Skip to content

Commit 5e99727

Browse files
fix: sendLogToJavaScript (#2111)
* fix: error * fix: added try/catch * fix: added try/catch * fix: lamda issue
1 parent ae03b2b commit 5e99727

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

  • src/plugins/system/android/com/foxdebug/system

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
import android.os.Build;
116116

117117

118-
119118
public 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 = "";

0 commit comments

Comments
 (0)