# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1679891669 0 # Node ID 81611e54ff1d5ba8d6c04a85fbbff13c35517cb3 # Parent e6fb2558e29e79b48d6fec5717c4c9e714a5de56 Android: Fix DW_SIGNAL_HTML_MESSAGE, there were 3 problems in the last commit. Passed HTML_CHANGE instead of HTML_MESSAGE in a copy and paste problem. The injected javascript code needed the first parameter quoted. The interface callback seems to be run on a thread that was not initialized. Presumably the web content has its own thread so need to initialize the environment. diff -r e6fb2558e29e -r 81611e54ff1d android/DWindows.kt --- a/android/DWindows.kt Mon Mar 27 00:40:17 2023 +0000 +++ b/android/DWindows.kt Mon Mar 27 04:34:29 2023 +0000 @@ -1543,7 +1543,7 @@ override fun onPageFinished(view: WebView, url: String) { // Inject the functions on the page on complete - HTMLAdds.forEach { e -> view.loadUrl("javascript:function $e(body) { DWindows.postMessage($e, body) }") } + HTMLAdds.forEach { e -> view.loadUrl("javascript:function $e(body) { DWindows.postMessage('$e', body) }") } // Handle the DW_HTML_CHANGE_COMPLETE event eventHandlerHTMLChanged(view, DWEvent.HTML_CHANGED, url, 4) @@ -1556,8 +1556,8 @@ /* Show a toast from the web page */ @JavascriptInterface fun postMessage(name: String?, body: String?) { - // Handle the DW_HTML_CHANGE_COMPLETE event - eventHandlerHTMLMessage(view, DWEvent.HTML_CHANGED, name, body) + // Handle the DW_HTML_MESSAGE event + eventHandlerHTMLMessage(view, DWEvent.HTML_MESSAGE, name, body) } external fun eventHandlerHTMLMessage(obj1: View, message: Int, hmltName: String?, htmlBody: String?) diff -r e6fb2558e29e -r 81611e54ff1d android/dw.cpp --- a/android/dw.cpp Mon Mar 27 00:40:17 2023 +0000 +++ b/android/dw.cpp Mon Mar 27 04:34:29 2023 +0000 @@ -272,7 +272,7 @@ { _DW_EVENT_HTML_RESULT, DW_SIGNAL_HTML_RESULT }, { _DW_EVENT_HTML_CHANGED, DW_SIGNAL_HTML_CHANGED }, { _DW_EVENT_HTML_MESSAGE, DW_SIGNAL_HTML_MESSAGE }, - { 0, "" } + { 0, "" } }; #define _DW_EVENT_PARAM_SIZE 10 @@ -592,8 +592,7 @@ params[9] = (void *)handler; /* We have to handle draw events in the main thread... - * If it isn't a draw event, either queue the event - * or launch a new thread to handle it. + * If it isn't a draw event, queue the event. */ if(DW_POINTER_TO_INT(params[8]) != _DW_EVENT_EXPOSE) { @@ -691,6 +690,9 @@ nullptr, nullptr, nullptr, nullptr, nullptr, DW_INT_TO_POINTER(message), nullptr }; + // This seems callback seems to run on an uninitialized thread... + pthread_setspecific(_dw_env_key, env); + _dw_event_handler(obj1, params); if(name) env->ReleaseStringUTFChars(htmlName, name);