From 68e73b658a6546d1f0e1060a41052bf58105639a Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 17 Dec 2019 17:06:55 +0000 Subject: [PATCH] Desktop: Fixed dev tool support --- ElectronClient/app/app.js | 45 ++++++++++++++++------ ElectronClient/app/bridge.js | 8 ++++ ElectronClient/app/gui/MainScreen.jsx | 3 +- ElectronClient/app/gui/NoteText.jsx | 13 ------- ElectronClient/app/gui/NoteTextViewer.jsx | 2 +- ElectronClient/app/gui/ShareNoteDialog.tsx | 2 +- ReactNativeClient/lib/BaseApplication.js | 2 +- ReactNativeClient/lib/models/Setting.js | 2 +- 8 files changed, 47 insertions(+), 30 deletions(-) diff --git a/ElectronClient/app/app.js b/ElectronClient/app/app.js index 5f74b9e7e..e27dd7276 100644 --- a/ElectronClient/app/app.js +++ b/ElectronClient/app/app.js @@ -49,7 +49,7 @@ const appDefaultState = Object.assign({}, defaultState, { windowContentSize: bridge().windowContentSize(), watchedNoteFiles: [], lastEditorScrollPercents: {}, - noteDevToolsVisible: false, + devToolsVisible: false, }); class Application extends BaseApplication { @@ -221,7 +221,12 @@ class Application extends BaseApplication { case 'NOTE_DEVTOOLS_TOGGLE': newState = Object.assign({}, state); - newState.noteDevToolsVisible = !newState.noteDevToolsVisible; + newState.devToolsVisible = !newState.devToolsVisible; + break; + + case 'NOTE_DEVTOOLS_SET': + newState = Object.assign({}, state); + newState.devToolsVisible = action.value; break; } @@ -233,6 +238,14 @@ class Application extends BaseApplication { return super.reducer(newState, action); } + toggleDevTools(visible) { + if (visible) { + bridge().openDevTools(); + } else { + bridge().closeDevTools(); + } + } + async generalMiddleware(store, next, action) { if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') { setLocale(Setting.value('locale')); @@ -274,12 +287,12 @@ class Application extends BaseApplication { } if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0) { - this.updateMenuItemStates(); + this.updateMenuItemStates(newState); } - if (action.type === 'NOTE_DEVTOOLS_TOGGLE') { - const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools'); - menuItem.checked = newState.noteDevToolsVisible; + if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) { + this.toggleDevTools(newState.devToolsVisible); + this.updateMenuItemStates(newState); } return result; @@ -1105,11 +1118,13 @@ class Application extends BaseApplication { this.lastMenuScreen_ = screen; } - async updateMenuItemStates() { + async updateMenuItemStates(state = null) { if (!this.lastMenuScreen_) return; - if (!this.store()) return; + if (!this.store() && !state) return; - const selectedNoteIds = this.store().getState().selectedNoteIds; + if (!state) state = this.store().getState(); + + const selectedNoteIds = state.selectedNoteIds; const note = selectedNoteIds.length === 1 ? await Note.load(selectedNoteIds[0]) : null; for (const itemId of ['copy', 'paste', 'cut', 'selectAll', 'bold', 'italic', 'link', 'code', 'insertDateTime', 'commandStartExternalEditing', 'setTags', 'showLocalSearch']) { @@ -1117,6 +1132,9 @@ class Application extends BaseApplication { if (!menuItem) continue; menuItem.enabled = !!note && note.markup_language === Note.MARKUP_LANGUAGE_MARKDOWN; } + + const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools'); + menuItem.checked = state.devToolsVisible; } updateTray() { @@ -1187,8 +1205,8 @@ class Application extends BaseApplication { reg.setShowErrorMessageBoxHandler((message) => { bridge().showErrorMessageBox(message); }); - if (Setting.value('openDevTools')) { - bridge().window().webContents.openDevTools(); + if (Setting.value('flagOpenDevTools')) { + bridge().openDevTools(); } PluginManager.instance().dispatch_ = this.dispatch.bind(this); @@ -1244,6 +1262,11 @@ class Application extends BaseApplication { templates: templates, }); + this.store().dispatch({ + type: 'NOTE_DEVTOOLS_SET', + value: Setting.value('flagOpenDevTools'), + }); + // Note: Auto-update currently doesn't work in Linux: it downloads the update // but then doesn't install it on exit. if (shim.isWindows() || shim.isMac()) { diff --git a/ElectronClient/app/bridge.js b/ElectronClient/app/bridge.js index 54c9cdd89..90b862449 100644 --- a/ElectronClient/app/bridge.js +++ b/ElectronClient/app/bridge.js @@ -43,6 +43,14 @@ class Bridge { return this.window().setSize(width, height); } + openDevTools() { + return this.window().webContents.openDevTools(); + } + + closeDevTools() { + return this.window().webContents.closeDevTools(); + } + showSaveDialog(options) { const {dialog} = require('electron'); if (!options) options = {}; diff --git a/ElectronClient/app/gui/MainScreen.jsx b/ElectronClient/app/gui/MainScreen.jsx index 627422074..667997a7c 100644 --- a/ElectronClient/app/gui/MainScreen.jsx +++ b/ElectronClient/app/gui/MainScreen.jsx @@ -605,7 +605,7 @@ class MainScreenComponent extends React.Component { - + {pluginDialog} @@ -629,7 +629,6 @@ const mapStateToProps = state => { noteListWidth: state.settings['style.noteList.width'], selectedNoteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null, plugins: state.plugins, - noteDevToolsVisible: state.noteDevToolsVisible, templates: state.templates, }; }; diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 28ecae299..5968f8c26 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -455,19 +455,6 @@ class NoteTextComponent extends React.Component { } componentDidUpdate() { - // if (Setting.value('env') === 'dev' && this.webviewRef()) { - // this.webviewRef().openDevTools(); - // return; - // } - - if (this.webviewRef() && this.props.noteDevToolsVisible !== this.webviewRef().isDevToolsOpened()) { - if (this.props.noteDevToolsVisible) { - this.webviewRef().openDevTools(); - } else { - this.webviewRef().closeDevTools(); - } - } - const currentNoteId = this.state.note ? this.state.note.id : null; if (this.lastComponentUpdateNoteId_ !== currentNoteId && this.editor_) { this.editor_.editor.getSession().setMode(new CustomMdMode()); diff --git a/ElectronClient/app/gui/NoteTextViewer.jsx b/ElectronClient/app/gui/NoteTextViewer.jsx index ce37a9fcb..84e2984de 100644 --- a/ElectronClient/app/gui/NoteTextViewer.jsx +++ b/ElectronClient/app/gui/NoteTextViewer.jsx @@ -160,7 +160,7 @@ class NoteTextViewerComponent extends React.Component { // ---------------------------------------------------------------- render() { - const viewerStyle = Object.assign({}, this.props.viewerStyle, { borderTop: 'none' }); + const viewerStyle = Object.assign({}, this.props.viewerStyle, { borderTop: 'none', borderRight: 'none', borderBottom: 'none' }); return ; } } diff --git a/ElectronClient/app/gui/ShareNoteDialog.tsx b/ElectronClient/app/gui/ShareNoteDialog.tsx index d950d50e7..9b652d698 100644 --- a/ElectronClient/app/gui/ShareNoteDialog.tsx +++ b/ElectronClient/app/gui/ShareNoteDialog.tsx @@ -210,8 +210,8 @@ export default function ShareNoteDialog(props:ShareNoteDialogProps) {
{_('Share Notes')}
{renderNoteList(notes)} - {encryptionWarningMessage}
{statusMessage(sharesState)}
+ {encryptionWarningMessage} diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index e59682fc6..371ae41ce 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -132,7 +132,7 @@ class BaseApplication { } if (arg == '--open-dev-tools') { - Setting.setConstant('openDevTools', true); + Setting.setConstant('flagOpenDevTools', true); argv.splice(0, 1); continue; } diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index 20ec3411e..d2a8efd2d 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -1028,7 +1028,7 @@ Setting.constants_ = { profileDir: '', templateDir: '', tempDir: '', - openDevTools: false, + flagOpenDevTools: false, syncVersion: 1, };