changeset 2983:81611e54ff1d

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.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 27 Mar 2023 04:34:29 +0000
parents e6fb2558e29e
children ebb94fc2b19f
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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?)
--- 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);