File tree Expand file tree Collapse file tree
src/plugins/system/android/com/foxdebug/system Expand file tree Collapse file tree Original file line number Diff line number Diff line change 115115import android .os .Build ;
116116
117117
118-
119118public class System extends CordovaPlugin {
120119 private static final String TAG = "SystemPlugin" ;
121120
@@ -633,19 +632,21 @@ public void run() {
633632
634633 private void sendLogToJavaScript (String level , String message ) {
635634 final String js =
636- "window.log(" + JSONObject .quote (level ) + ", " + JSONObject .quote (message ) + ");" ;
637- cordova
638- .getActivity ()
639- .runOnUiThread (
640- new Runnable () {
641- @ Override
642- public void run () {
643- webView .evaluateJavascript (js , null );
644- }
645- }
646- );
647- }
635+ "if (typeof window.log === 'function')" +
636+ " window.log(" + JSONObject .quote (level ) + ", " + JSONObject .quote (message ) + ");" +
637+ "else" +
638+ " console.log(" + JSONObject .quote (level ) + ", " + JSONObject .quote (message ) + ");" ;
648639
640+ cordova .getActivity ().runOnUiThread (() -> {
641+ try {
642+ ((android .webkit .WebView ) webView .getEngine ().getView ())
643+ .evaluateJavascript (js , null );
644+ } catch (Exception e ) {
645+ Log .e (TAG , "Failed to send log to JavaScript: " + e .getMessage ());
646+ }
647+ });
648+ }
649+
649650 // Helper method to determine MIME type using Android's built-in MimeTypeMap
650651 private String getMimeTypeFromExtension (String fileName ) {
651652 String extension = "" ;
You can’t perform that action at this time.
0 commit comments