@@ -9,11 +9,13 @@ import javax.swing.JPanel
99import javax.swing.SwingUtilities
1010import javax.swing.Timer
1111import kotlin.concurrent.thread
12+ import kotlin.properties.Delegates
1213
1314
1415class WryWebViewPanel (
1516 initialUrl : String ,
1617 customUserAgent : String? = null ,
18+ private val bridgeLogger : (String ) -> Unit = { System .err.println(it) }
1719) : JPanel() {
1820 private val host = SkikoInterop .createHost()
1921 private var webviewId: ULong? = null
@@ -568,7 +570,7 @@ class WryWebViewPanel(
568570
569571 private fun log (message : String ) {
570572 if (LOG_ENABLED ) {
571- System .err. println (" [WryWebViewPanel] $message " )
573+ bridgeLogger (" [WryWebViewPanel] $message " )
572574 }
573575 }
574576
@@ -665,12 +667,12 @@ class WryWebViewPanel(
665667 private data class ParentHandle (val handle : ULong , val isWindow : Boolean )
666668 private data class Bounds (val x : Int , val y : Int , val width : Int , val height : Int )
667669
668- private companion object {
670+ companion object {
669671 private val OS_NAME = System .getProperty(" os.name" )?.lowercase().orEmpty()
670672 private val IS_LINUX = OS_NAME .contains(" linux" )
671673 private val IS_MAC = OS_NAME .contains(" mac" )
672674 private val IS_WINDOWS = OS_NAME .contains(" windows" )
673- private val LOG_ENABLED = run {
675+ var LOG_ENABLED = run {
674676 val raw = System .getProperty(" composewebview.wry.log" ) ? : System .getenv(" WRYWEBVIEW_LOG" )
675677 when {
676678 raw == null -> false
@@ -681,19 +683,24 @@ class WryWebViewPanel(
681683 else -> false
682684 }
683685 }
686+
687+ var NATIVE_LOGGER : (String ) -> Unit = { System .err.println (it) }
688+
689+ init {
690+ setNativeLogger(
691+ object : NativeLogger {
692+ override fun handleLog (data : String ) {
693+ if (LOG_ENABLED ) {
694+ NATIVE_LOGGER (data)
695+ }
696+ }
697+ }
698+ )
699+ }
684700 }
685701}
686702
687703private object NativeBindings {
688- init {
689- setNativeLogger(
690- object : NativeLogger {
691- override fun handleLog (data : String ) {
692- println (data)
693- }
694- }
695- )
696- }
697704
698705 fun createWebview (parentHandle : ULong , width : Int , height : Int , url : String , handler : NavigationHandler ): ULong {
699706 return io.github.kdroidfilter.webview.wry.createWebview(parentHandle, width, height, url, handler)
0 commit comments