1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Android: Allow debugging plugins (#10156)

This commit is contained in:
Henry Heino 2024-03-20 03:52:58 -07:00 committed by GitHub
parent 9c3e751ebc
commit 7d068cfb87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 34 additions and 3 deletions

View File

@ -3,7 +3,7 @@
import * as React from 'react'; import * as React from 'react';
import { import {
forwardRef, Ref, useCallback, useEffect, useImperativeHandle, useRef, useState, forwardRef, Ref, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState,
} from 'react'; } from 'react';
import { WebView, WebViewMessageEvent } from 'react-native-webview'; import { WebView, WebViewMessageEvent } from 'react-native-webview';
import { WebViewErrorEvent, WebViewEvent, WebViewSource } from 'react-native-webview/lib/WebViewTypes'; import { WebViewErrorEvent, WebViewEvent, WebViewSource } from 'react-native-webview/lib/WebViewTypes';
@ -50,6 +50,7 @@ interface Props {
mixedContentMode?: 'never' | 'always'; mixedContentMode?: 'never' | 'always';
allowFileAccessFromJs?: boolean; allowFileAccessFromJs?: boolean;
hasPluginScripts?: boolean;
// Initial javascript. Must evaluate to true. // Initial javascript. Must evaluate to true.
injectedJavaScript: string; injectedJavaScript: string;
@ -142,6 +143,10 @@ const ExtendedWebView = (props: Props, ref: Ref<WebViewControl>) => {
logger.error('Error', event.nativeEvent.description); logger.error('Error', event.nativeEvent.description);
}, []); }, []);
const allowWebviewDebugging = useMemo(() => {
return Setting.value('env') === 'dev' || (!!props.hasPluginScripts && Setting.value('plugins.enableWebviewDebugging'));
}, [props.hasPluginScripts]);
// - `setSupportMultipleWindows` must be `true` for security reasons: // - `setSupportMultipleWindows` must be `true` for security reasons:
// https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0 // https://github.com/react-native-webview/react-native-webview/releases/tag/v11.0.0
@ -172,7 +177,7 @@ const ExtendedWebView = (props: Props, ref: Ref<WebViewControl>) => {
mixedContentMode={props.mixedContentMode} mixedContentMode={props.mixedContentMode}
allowFileAccess={true} allowFileAccess={true}
allowFileAccessFromFileURLs={props.allowFileAccessFromJs} allowFileAccessFromFileURLs={props.allowFileAccessFromJs}
webviewDebuggingEnabled={Setting.value('env') === 'dev'} webviewDebuggingEnabled={allowWebviewDebugging}
injectedJavaScript={props.injectedJavaScript} injectedJavaScript={props.injectedJavaScript}
onMessage={props.onMessage} onMessage={props.onMessage}
onError={props.onError ?? onError} onError={props.onError ?? onError}

View File

@ -517,6 +517,7 @@ function NoteEditor(props: Props, ref: any) {
ref={webviewRef} ref={webviewRef}
html={html} html={html}
injectedJavaScript={injectedJavaScript} injectedJavaScript={injectedJavaScript}
hasPluginScripts={codeMirrorPlugins.length > 0}
onMessage={onMessage} onMessage={onMessage}
onLoadEnd={onLoadEnd} onLoadEnd={onLoadEnd}
onError={onError} onError={onError}

View File

@ -107,13 +107,13 @@ const PluginRunnerWebViewComponent: React.FC<Props> = props => {
} }
`; `;
return ( return (
<> <>
<ExtendedWebView <ExtendedWebView
webviewInstanceId='PluginRunner' webviewInstanceId='PluginRunner'
html={html} html={html}
injectedJavaScript={injectedJs} injectedJavaScript={injectedJs}
hasPluginScripts={true}
onMessage={pluginRunner.onWebviewMessage} onMessage={pluginRunner.onWebviewMessage}
onLoadEnd={onLoadEnd} onLoadEnd={onLoadEnd}
onLoadStart={onLoadStart} onLoadStart={onLoadStart}

View File

@ -103,6 +103,7 @@ const PluginUserWebView = (props: Props) => {
baseUrl={plugin.baseDir} baseUrl={plugin.baseDir}
webviewInstanceId='joplin__PluginDialogWebView' webviewInstanceId='joplin__PluginDialogWebView'
html={html} html={html}
hasPluginScripts={true}
injectedJavaScript={injectedJs} injectedJavaScript={injectedJs}
onMessage={messenger.onWebViewMessage} onMessage={messenger.onWebViewMessage}
onLoadEnd={onWebViewLoaded} onLoadEnd={onWebViewLoaded}

View File

@ -1179,6 +1179,24 @@ class Setting extends BaseModel {
autoSave: true, autoSave: true,
}, },
'plugins.enableWebviewDebugging': {
value: false,
type: SettingItemType.Bool,
section: 'plugins',
public: true,
appTypes: [AppType.Mobile],
show: (_settings) => {
// Hide on iOS due to App Store guidelines. See
// https://github.com/laurent22/joplin/pull/10086 for details.
return shim.mobilePlatform() !== 'ios';
},
needRestart: true,
advanced: true,
label: () => _('Plugin WebView debugging'),
description: () => _('Allows debugging mobile plugins. See %s for details.', 'https://https://joplinapp.org/help/api/references/mobile_plugin_debugging/'),
},
'plugins.devPluginPaths': { 'plugins.devPluginPaths': {
value: '', value: '',
type: SettingItemType.String, type: SettingItemType.String,

View File

@ -0,0 +1,6 @@
# Debugging mobile plugins
On Android, it's possible to debug mobile plugins with the Chrome development tools. To do this,
1. Enable plugin WebView debugging. To do this, go to "Configuration" > "Plugins" > "Advanced settings" and enable "Plugin webview debugging".
2. Restart Joplin.
3. Follow the [Chrome devtools instructions for debugging Android devices](https://developer.chrome.com/docs/devtools/remote-debugging/).