Skip to content

Conversation

sdsantos
Copy link
Contributor

@sdsantos sdsantos commented Apr 9, 2025

I'm trying to use JavaFX for the WebView but I could get it to run.

I was following an old version of https://github.com/KevinnZou/compose-webview-multiplatform/tree/1.2.0 as inspiration.

It said the toolkit was missing. It seems Jetbrains JRE and most others no longer have JavaFX bundled, so I installed the Android Studio plugin for it: https://plugins.jetbrains.com/plugin/14250-javafx-runtime-for-plugins

Still the app failed to run.

I then try to follow the configurations mentioned here: https://openjfx.io/openjfx-docs/#gradle But I still get issues:

Apr 09, 2025 3:54:31 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @1b4dba64'
Exception in thread "main" java.lang.IllegalStateException: Method setCurrentState must be called on the main thread
	at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.jvm.kt:297)
	at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.jvm.kt:101)
	at androidx.compose.ui.scene.ComposeContainer.updateLifecycleState(ComposeContainer.desktop.kt:471)
	at androidx.compose.ui.scene.ComposeContainer.onWindowFocusChanged(ComposeContainer.desktop.kt:230)
	at androidx.compose.ui.scene.ComposeContainer.setWindow(ComposeContainer.desktop.kt:322)

@sdsantos sdsantos marked this pull request as ready for review April 14, 2025 15:09
@sdsantos sdsantos changed the title JavaFX webview PoC Desktop webview support with JavaFX Apr 15, 2025
Copy link
Member

@aanorbel aanorbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐳

JFXPanel().apply {
Platform.setImplicitExit(false) // Otherwise, webView will not show the second time
Platform.runLater {
println("webview: factory runLater")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println("webview: factory runLater")

}
// Hack to send HTTP headers by taking advantage of userAgent
webView.engine.userAgent = "ooni$headers"
println("webview: Loading: ${event.url}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println("webview: Loading: ${event.url}")

factory = {
controller.state = OoniWebViewController.State.Initializing

println("webview: factory")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println("webview: factory")

},
modifier = modifier,
update = { jfxPanel ->
println("webview: update")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println("webview: update")

update = { jfxPanel ->
println("webview: update")
Platform.runLater {
println("webview: update runLater")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println("webview: update runLater")

@sdsantos sdsantos merged commit 044ef8a into main Apr 28, 2025
4 of 5 checks passed
@sdsantos sdsantos deleted the javafx branch April 28, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants