@@ -9,12 +9,23 @@ This can (should) be called in the app init process and only needs to be called
99LaunchedEffect (Unit ) {
1010 Cef .init (builder = {
1111 installDir = File (" jcef-bundle" )
12- })
12+ },{} )
1313}
1414```
15+
1516Then, run your app once and it will download the JCEF Bundle to the install directory.
1617After that, just restart your app and it will work properly.
1718
19+ ## Disposal
20+ When the app is closing, you need to dispose of the CEF Module.
21+ ``` kotlin
22+ DisposableEffect (Unit ) {
23+ onDispose {
24+ Cef .dispose()
25+ }
26+ }
27+ ```
28+
1829> ** Note**
1930> Make sure to exclude the ` installDir ` from upstreaming by adding it to the ` .gitignore ` .
2031> The downloaded files are platform-specific and therefore differ to each user.
@@ -24,21 +35,45 @@ Please use the following example as a reference.
2435fun main () = application {
2536 Window (onCloseRequest = ::exitApplication) {
2637 var restartRequired by remember { mutableStateOf(false ) }
38+ var downloading by remember { mutableStateOf(0F ) }
39+ var initialized by remember { mutableStateOf(false ) }
2740
2841 LaunchedEffect (Unit ) {
29- Cef .init (builder = {
30- installDir = File (" jcef-bundle" )
31- }, onError = {
32- it.printStackTrace()
33- }) {
34- restartRequired = true
42+ withContext(Dispatchers .IO ) {
43+ Cef .init (builder = {
44+ installDir = File (" jcef-bundle" )
45+ settings {
46+ cachePath = File (" cache" ).absolutePath
47+ }
48+ }, initProgress = {
49+ onDownloading {
50+ downloading = max(it, 0F )
51+ }
52+ onInitialized {
53+ initialized = true
54+ }
55+ }, onError = {
56+ it.printStackTrace()
57+ }, onRestartRequired = {
58+ restartRequired = true
59+ })
3560 }
3661 }
3762
3863 if (restartRequired) {
3964 Text (text = " Restart required." )
4065 } else {
41- MainWebView ()
66+ if (initialized) {
67+ MainWebView ()
68+ } else {
69+ Text (text = " Downloading $downloading %" )
70+ }
71+ }
72+
73+ DisposableEffect (Unit ) {
74+ onDispose {
75+ Cef .dispose()
76+ }
4277 }
4378 }
4479}
0 commit comments