From eeaff3c1dbd4b07e2d78b2e4a62f0596933901cf Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 2 Oct 2026 20:05:23 +0600 Subject: [PATCH] refactor(main): simplify main function and remove unused WebKit GPU compositing logic --- .../core/webview/PlatformWebviewScreen.kt | 1 - .../kotlin/dev/krtirtho/spotube/main.kt | 45 +------------------ gradle/libs.versions.toml | 2 +- 3 files changed, 2 insertions(+), 46 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/dev/krtirtho/spotube/core/webview/PlatformWebviewScreen.kt b/composeApp/src/commonMain/kotlin/dev/krtirtho/spotube/core/webview/PlatformWebviewScreen.kt index 93ecbd47..8751e1ec 100644 --- a/composeApp/src/commonMain/kotlin/dev/krtirtho/spotube/core/webview/PlatformWebviewScreen.kt +++ b/composeApp/src/commonMain/kotlin/dev/krtirtho/spotube/core/webview/PlatformWebviewScreen.kt @@ -215,7 +215,6 @@ fun PlatformWebViewScreen(webViewController: WebViewController) { webViewJsBridge = webViewBridge, onCreated = { webView -> navigator.evaluateJavaScript(bridgeBootstrapScript) - }, ) } diff --git a/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/main.kt b/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/main.kt index 171f215b..2a203feb 100644 --- a/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/main.kt +++ b/composeApp/src/jvmMain/kotlin/dev/krtirtho/spotube/main.kt @@ -58,52 +58,9 @@ private object KoinServicesProvider : KoinComponent { val settingsProvider: SettingsProvider get() = get() } -private interface LibC : Library { - fun setenv(name: String, value: String, overwrite: Int): Int - - companion object { - val INSTANCE: LibC = Native.load("c", LibC::class.java) - } -} - -/** - * WebKitGTK is only used on Linux (Windows = WebView2, macOS = WKWebView). - * The webview is created *after* the window is already mapped and the Tao - * render/swap loop is running. WebKitGTK's accelerated-compositing path then - * initialises its own GL context in-process, racing Tao's swap thread on the - * same Mesa display, which deterministically segfaults `libgallium` on the - * next Compose flush. Disabling WebKit's hardware-accelerated compositing - * (and its DMABUF renderer) removes that GL context entirely — login pages - * render fine in software. Must run before libwebkit2gtk is loaded. - */ -private fun disableWebKitGpuCompositing() { - if (!System.getProperty("os.name").lowercase().contains("linux")) return - LibC.INSTANCE.setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "1", 1) - LibC.INSTANCE.setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "1", 1) -} - -/** - * Routes `spotube://` deep links into [ExternalUriHandler]. - * macOS delivers them through the open-URI handler; on Linux/Windows they arrive - * as command line arguments (scheme registration is handled by the distribution - * packaging, e.g. the `.desktop` file's `Exec %u`). - */ -private fun handleStartupDeepLinks(args: Array) { - runCatching { - if (java.awt.Desktop.isDesktopSupported()) { - java.awt.Desktop.getDesktop().setOpenURIHandler { event -> - ExternalUriHandler.onNewUri(event.uri.toString()) - } - } - } - args.firstOrNull { it.startsWith("spotube:", ignoreCase = true) } - ?.let(ExternalUriHandler::onNewUri) -} @OptIn(ExperimentalComposeUiApi::class) -fun main(args: Array) { - disableWebKitGpuCompositing() - handleStartupDeepLinks(args) +fun main() { FileKit.init(appId = "dev.krtirtho.spotube") initKoin() NewPipeDownloader.init(KoinPathsProvider.paths) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1505c23..8f1e5295 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -61,7 +61,7 @@ kotlinStdlib = "2.4.10" runner = "1.7.0" core = "1.7.0" filekit = "0.14.2" -compose-webview = "1.0.3" +compose-webview = "0.1.0-SNAPSHOT" composeNativeTray = "2.1.6" koin = "4.2.2" multiplatform-nav3-ui = "1.1.1"