Skip to content

Commit e715100

Browse files
committed
Fix ktlint styling issues
1 parent 481b025 commit e715100

5 files changed

Lines changed: 40 additions & 41 deletions

File tree

webview/src/androidMain/kotlin/com/multiplatform/webview/util/InternalStoragePathHandler.kt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,38 @@ import androidx.webkit.WebViewAssetLoader
66
import java.io.File
77
import java.io.FileInputStream
88

9-
class InternalStoragePathHandler() : WebViewAssetLoader.PathHandler {
9+
class InternalStoragePathHandler : WebViewAssetLoader.PathHandler {
1010
override fun handle(path: String): WebResourceResponse? {
1111
Log.d("InternalStorageHandler", "Intercepted: $path")
1212
val file = File(path.removePrefix("/"))
1313
if (!file.exists() || !file.isFile) return null
1414

15-
val mimeType = when {
16-
path.endsWith(".html") -> "text/html"
17-
path.endsWith(".js") -> "application/javascript"
18-
path.endsWith(".css") -> "text/css"
19-
path.endsWith(".json") -> "application/json"
20-
path.endsWith(".png") -> "image/png"
21-
path.endsWith(".jpg") || path.endsWith(".jpeg") -> "image/jpeg"
22-
path.endsWith(".svg") -> "image/svg+xml"
23-
path.endsWith(".webp") -> "image/webp"
24-
path.endsWith(".ico") -> "image/x-icon"
25-
path.endsWith(".woff") -> "font/woff"
26-
path.endsWith(".woff2") -> "font/woff2"
27-
path.endsWith(".ttf") -> "font/ttf"
28-
path.endsWith(".mp4") -> "video/mp4"
29-
path.endsWith(".webm") -> "video/webm"
30-
path.endsWith(".ogg") -> "video/ogg"
31-
path.endsWith(".mp3") -> "audio/mpeg"
32-
path.endsWith(".wav") -> "audio/wav"
33-
path.endsWith(".wasm") -> "application/wasm"
34-
path.endsWith(".pdf") -> "application/pdf"
35-
path.endsWith(".zip") -> "application/zip"
36-
path.endsWith(".csv") -> "text/csv"
37-
else -> "application/octet-stream"
38-
}
15+
val mimeType =
16+
when {
17+
path.endsWith(".html") -> "text/html"
18+
path.endsWith(".js") -> "application/javascript"
19+
path.endsWith(".css") -> "text/css"
20+
path.endsWith(".json") -> "application/json"
21+
path.endsWith(".png") -> "image/png"
22+
path.endsWith(".jpg") || path.endsWith(".jpeg") -> "image/jpeg"
23+
path.endsWith(".svg") -> "image/svg+xml"
24+
path.endsWith(".webp") -> "image/webp"
25+
path.endsWith(".ico") -> "image/x-icon"
26+
path.endsWith(".woff") -> "font/woff"
27+
path.endsWith(".woff2") -> "font/woff2"
28+
path.endsWith(".ttf") -> "font/ttf"
29+
path.endsWith(".mp4") -> "video/mp4"
30+
path.endsWith(".webm") -> "video/webm"
31+
path.endsWith(".ogg") -> "video/ogg"
32+
path.endsWith(".mp3") -> "audio/mpeg"
33+
path.endsWith(".wav") -> "audio/wav"
34+
path.endsWith(".wasm") -> "application/wasm"
35+
path.endsWith(".pdf") -> "application/pdf"
36+
path.endsWith(".zip") -> "application/zip"
37+
path.endsWith(".csv") -> "text/csv"
38+
else -> "application/octet-stream"
39+
}
3940

4041
return WebResourceResponse(mimeType, "utf-8", FileInputStream(file))
4142
}
42-
}
43+
}

webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ fun AccompanistWebView(
212212
mediaPlaybackRequiresUserGesture = it.mediaPlaybackRequiresUserGesture
213213

214214
if (it.enableSandbox) {
215-
client.assetLoader = WebViewAssetLoader.Builder()
216-
.addPathHandler(
217-
it.sandboxSubdomain,
218-
InternalStoragePathHandler()
219-
)
220-
.build()
215+
client.assetLoader =
216+
WebViewAssetLoader
217+
.Builder()
218+
.addPathHandler(
219+
it.sandboxSubdomain,
220+
InternalStoragePathHandler(),
221+
).build()
221222
}
222223
}
223224
}
@@ -288,6 +289,7 @@ open class AccompanistWebViewClient : WebViewClient() {
288289
state.pageTitle = null
289290
state.lastLoadedUrl = url
290291
val supportZoom = if (state.webSettings.supportZoom) "yes" else "no"
292+
291293
// set scale level
292294
@Suppress("ktlint:standard:max-line-length")
293295
val script =
@@ -297,7 +299,7 @@ open class AccompanistWebViewClient : WebViewClient() {
297299

298300
override fun shouldInterceptRequest(
299301
view: WebView?,
300-
request: WebResourceRequest?
302+
request: WebResourceRequest?,
301303
): WebResourceResponse? {
302304
val url = request?.url
303305
KLogger.d { "Intercepting request for URL: $url" }

webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ sealed class PlatformWebSettings {
207207
* for them as well
208208
*/
209209
var enableSandbox: Boolean = false,
210-
211210
/**
212211
* The virtual subdomain prefix to be used with WebViewAssetLoader for local file access.
213212
*
@@ -219,7 +218,7 @@ sealed class PlatformWebSettings {
219218
* the WebViewAssetLoader will map it to the correct local file or asset if configured properly.
220219
* This URL should be used instead of file:// URLs to ensure secure and modern WebView behavior.
221220
*/
222-
var sandboxSubdomain: String = "/app/"
221+
var sandboxSubdomain: String = "/app/",
223222
) : PlatformWebSettings() {
224223
object LayerType {
225224
const val NONE = 0

webview/src/commonMain/kotlin/com/multiplatform/webview/web/WebViewNavigator.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ class WebViewNavigator(
221221

222222
fun loadHtmlFile(
223223
fileName: String,
224-
readType: WebViewFileReadType = WebViewFileReadType.ASSET_RESOURCES
224+
readType: WebViewFileReadType = WebViewFileReadType.ASSET_RESOURCES,
225225
) {
226226
coroutineScope.launch {
227227
navigationEvents.emit(
228228
NavigationEvent.LoadHtmlFile(
229229
fileName,
230-
readType
230+
readType,
231231
),
232232
)
233233
}
@@ -310,5 +310,4 @@ class WebViewNavigator(
310310
fun rememberWebViewNavigator(
311311
coroutineScope: CoroutineScope = rememberCoroutineScope(),
312312
requestInterceptor: RequestInterceptor? = null,
313-
): WebViewNavigator =
314-
remember(coroutineScope) { WebViewNavigator(coroutineScope, requestInterceptor) }
313+
): WebViewNavigator = remember(coroutineScope) { WebViewNavigator(coroutineScope, requestInterceptor) }

webview/src/desktopMain/kotlin/com/multiplatform/webview/web/WebEngineExt.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import org.cef.handler.CefDisplayHandler
1111
import org.cef.handler.CefLoadHandler
1212
import org.cef.handler.CefRequestHandlerAdapter
1313
import org.cef.network.CefRequest
14-
import kotlin.math.abs
15-
import kotlin.math.ln
1614

1715
/**
1816
* Created By Kevin Zou On 2023/9/12

0 commit comments

Comments
 (0)