diff --git a/src/main/menu/actions/edit.js b/src/main/menu/actions/edit.js index 9bfb30aa..15e2d0f2 100644 --- a/src/main/menu/actions/edit.js +++ b/src/main/menu/actions/edit.js @@ -22,7 +22,9 @@ ipcMain.on('mt::ask-for-image-auto-path', (e, { pathname, src, id }) => { }) export const edit = (win, type) => { - win.webContents.send('AGANI::edit', { type }) + if (win && win.webContents) { + win.webContents.send('AGANI::edit', { type }) + } } export const screenshot = (win, type) => { @@ -30,5 +32,7 @@ export const screenshot = (win, type) => { } export const lineEnding = (win, lineEnding) => { - win.webContents.send('AGANI::set-line-ending', { lineEnding, ignoreSaveStatus: false }) + if (win && win.webContents) { + win.webContents.send('AGANI::set-line-ending', { lineEnding, ignoreSaveStatus: false }) + } } diff --git a/src/main/menu/actions/file.js b/src/main/menu/actions/file.js index 695d49c4..4eba8183 100644 --- a/src/main/menu/actions/file.js +++ b/src/main/menu/actions/file.js @@ -420,7 +420,9 @@ ipcMain.on('AGANI::format-link-click', (e, { data, dirname }) => { // --- menu ------------------------------------- export const exportFile = (win, type) => { - win.webContents.send('mt::show-export-dialog', type) + if (win && win.webContents) { + win.webContents.send('mt::show-export-dialog', type) + } } export const importFile = async win => { @@ -444,6 +446,9 @@ export const importFile = async win => { } export const print = win => { + if (!win) { + return + } // See GH#749, Electron#16085 and Electron#17523. dialog.showMessageBox(win, { type: 'info', @@ -492,7 +497,9 @@ export const openFileOrFolder = (win, pathname) => { } export const newBlankTab = win => { - win.webContents.send('mt::new-untitled-tab') + if (win && win.webContents) { + win.webContents.send('mt::new-untitled-tab') + } } export const newEditorWindow = () => { @@ -500,15 +507,21 @@ export const newEditorWindow = () => { } export const closeTab = win => { - win.webContents.send('AGANI::close-tab') + if (win && win.webContents) { + win.webContents.send('AGANI::close-tab') + } } export const save = win => { - win.webContents.send('AGANI::ask-file-save') + if (win && win.webContents) { + win.webContents.send('AGANI::ask-file-save') + } } export const saveAs = win => { - win.webContents.send('AGANI::ask-file-save-as') + if (win && win.webContents) { + win.webContents.send('AGANI::ask-file-save-as') + } } export const autoSave = (menuItem, browserWindow) => { @@ -517,11 +530,15 @@ export const autoSave = (menuItem, browserWindow) => { } export const moveTo = win => { - win.webContents.send('AGANI::ask-file-move-to') + if (win && win.webContents) { + win.webContents.send('AGANI::ask-file-move-to') + } } export const rename = win => { - win.webContents.send('AGANI::ask-file-rename') + if (win && win.webContents) { + win.webContents.send('AGANI::ask-file-rename') + } } export const clearRecentlyUsed = () => { diff --git a/src/main/menu/actions/format.js b/src/main/menu/actions/format.js index c3948853..8eb53e13 100644 --- a/src/main/menu/actions/format.js +++ b/src/main/menu/actions/format.js @@ -9,12 +9,9 @@ const MENU_ID_FORMAT_MAP = { } export const format = (win, type) => { - // Fix #961 - // TODO: This is not the best solution for fix #961, but we don't know how to reproduce this issue. - if (!win) { - return + if (win && win.webContents) { + win.webContents.send('AGANI::format', { type }) } - win.webContents.send('AGANI::format', { type }) } // --- IPC events ------------------------------------------------------------- diff --git a/src/main/menu/actions/help.js b/src/main/menu/actions/help.js index 47b83dbc..ec6f6a8f 100644 --- a/src/main/menu/actions/help.js +++ b/src/main/menu/actions/help.js @@ -1,7 +1,11 @@ export const showAboutDialog = win => { - win.webContents.send('AGANI::about-dialog') + if (win && win.webContents) { + win.webContents.send('AGANI::about-dialog') + } } export const showTweetDialog = (win, type) => { - win.webContents.send('AGANI::tweet', type) + if (win && win.webContents) { + win.webContents.send('AGANI::tweet', type) + } } diff --git a/src/main/menu/actions/paragraph.js b/src/main/menu/actions/paragraph.js index 1968ad26..df51537e 100644 --- a/src/main/menu/actions/paragraph.js +++ b/src/main/menu/actions/paragraph.js @@ -27,7 +27,9 @@ const MENU_ID_MAP = { } export const paragraph = (win, type) => { - win.webContents.send('AGANI::paragraph', { type }) + if (win && win.webContents) { + win.webContents.send('AGANI::paragraph', { type }) + } } // --- IPC events ------------------------------------------------------------- diff --git a/src/main/menu/actions/view.js b/src/main/menu/actions/view.js index 294e4930..65353c5e 100644 --- a/src/main/menu/actions/view.js +++ b/src/main/menu/actions/view.js @@ -4,6 +4,9 @@ const typewriterModeMenuItemId = 'typewriterModeMenuItem' const focusModeMenuItemId = 'focusModeMenuItem' export const typeMode = (win, type, item) => { + if (!win) { + return + } const { checked } = item win.webContents.send('AGANI::view', { type, checked }) @@ -16,7 +19,9 @@ export const typeMode = (win, type, item) => { } export const layout = (item, win, type) => { - win.webContents.send('AGANI::listen-for-view-layout', { [type]: item.checked }) + if (win && win.webContents) { + win.webContents.send('AGANI::listen-for-view-layout', { [type]: item.checked }) + } } export const showTabBar = win => {