Skip to content

Latest commit

 

History

History
116 lines (93 loc) · 3.64 KB

README.desktop.md

File metadata and controls

116 lines (93 loc) · 3.64 KB

Desktop Setup

Starting from version 1.3.0, we switched from JavaFX to the Java CEF Browser for better performance and user experience.

Starting from version 1.7.0, we switched from Java CEF Browser to KCEF for more features and better performance.

If you are using a version before 1.7.0, please refer to the old documentation.

After importing the library, some configurations need to be done before running the desktop app.

Initialization

Take a look at the KCEF Compose documentation here: DatL4g/KCEF

Please use the following example as a reference.

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        var restartRequired by remember { mutableStateOf(false) }
        var downloading by remember { mutableStateOf(0F) }
        var initialized by remember { mutableStateOf(false) }

        LaunchedEffect(Unit) {
            withContext(Dispatchers.IO) {
                KCEF.init(builder = {
                    installDir(File("kcef-bundle"))
                    progress {
                        onDownloading {
                            downloading = max(it, 0F)
                        }
                        onInitialized {
                            initialized = true
                        }
                    }
                    settings {
                        cachePath = File("cache").absolutePath
                    }
                }, onError = {
                    it.printStackTrace()
                }, onRestartRequired = {
                    restartRequired = true
                })
            }
        }

        if (restartRequired) {
            Text(text = "Restart required.")
        } else {
            if (initialized) {
                MainWebView()
            } else {
                Text(text = "Downloading $downloading%")
            }
        }

        DisposableEffect(Unit) {
            onDispose {
                KCEF.disposeBlocking()
            }
        }
    }
}

Flags

Make sure to include platform-required Flags to your compose configuration: DatL4g/KCEF

compose.desktop {
  application {
    // all your other configuration, etc

    jvmArgs("--add-opens", "java.desktop/sun.awt=ALL-UNNAMED")
    jvmArgs("--add-opens", "java.desktop/java.awt.peer=ALL-UNNAMED") // recommended but not necessary

    if (System.getProperty("os.name").contains("Mac")) {
      jvmArgs("--add-opens", "java.desktop/sun.lwawt=ALL-UNNAMED")
      jvmArgs("--add-opens", "java.desktop/sun.lwawt.macosx=ALL-UNNAMED")
    }
  }
}

ProGuard

Make sure to add ProGuard rules in order for KCEF to work in required build types: DatL4g/KCEF

Simply add a ProGuard configuration file to your target platform, for example compose-desktop.pro and add the following lines:

-keep class org.cef.** { *; }
-keep class kotlinx.coroutines.swing.SwingDispatcherFactory

Then make sure to use this config by adding the following lines to your build.gradle.kts:

compose.desktop {
  application {
    // all your other configuration, etc

    buildTypes.release.proguard {
      configurationFiles.from("compose-desktop.pro")
    }
  }
}

Dependencies

This library requires Jogamp's Maven to be added to your project's repositories.

repositories {
    maven("https://jogamp.org/deployment/maven")
}