Skip to content

Commit

Permalink
feat: allow static generation from public subfolder in cache directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mlecoq committed May 25, 2022
1 parent fcd0bbe commit aab4662
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ open class StaticHtmlToPdfConverter(private var context: Context, private var pr
override fun run() {

val webView = WebView(context)
val assetLoader = WebViewAssetLoader.Builder().addPathHandler("/", WebViewAssetLoader.InternalStoragePathHandler(context, context.filesDir)).build()
val assetLoader: WebViewAssetLoader;
if(params.getPath().contains(context.cacheDir.path)){
assetLoader = WebViewAssetLoader.Builder().addPathHandler("/", WebViewAssetLoader.InternalStoragePathHandler(context, File(context.cacheDir, "public"))).build()
} else {
assetLoader = WebViewAssetLoader.Builder().addPathHandler("/", WebViewAssetLoader.InternalStoragePathHandler(context, context.filesDir)).build()
}


webView.webViewClient = object : WebViewClient() {
@RequiresApi(21)
Expand Down Expand Up @@ -134,7 +140,6 @@ open class StaticHtmlToPdfConverter(private var context: Context, private var pr
settings.textZoom = 100
settings.defaultTextEncodingName = "utf-8"
settings.javaScriptEnabled = true
webView.loadUrl("https://" + WebViewAssetLoader.DEFAULT_DOMAIN + params.getPath().replace(context.filesDir.path, "").replace("file://", ""))

webView.loadUrl("https://" + WebViewAssetLoader.DEFAULT_DOMAIN + params.getPath().replace(context.filesDir.path, "").replace(context.cacheDir.path + "/public", "").replace("file://", ""))
}
}

0 comments on commit aab4662

Please sign in to comment.