From ce76d0be7f4cbc5b0b040bdff4598b8e61314dd0 Mon Sep 17 00:00:00 2001 From: Gary Moon Date: Wed, 24 Feb 2016 09:45:22 -0500 Subject: [PATCH] add mainWindow and options objects to createMenu args and refactor --- app/src/components/mainWindow/mainWindow.js | 2 +- app/src/components/menu/menu.js | 44 ++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/components/mainWindow/mainWindow.js b/app/src/components/mainWindow/mainWindow.js index 5119118..3345d68 100644 --- a/app/src/components/mainWindow/mainWindow.js +++ b/app/src/components/mainWindow/mainWindow.js @@ -54,7 +54,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) { mainWindow.webContents.send('change-zoom', currentZoom); }; - createMenu(options.nativefierVersion, onAppQuit, mainWindow.webContents.goBack, mainWindow.webContents.goForward, onZoomIn, onZoomOut, mainWindow.webContents.getURL); + createMenu(options.nativefierVersion, onAppQuit, onZoomIn, onZoomOut, mainWindow, options); initContextMenu(mainWindow); if (options.userAgent) { diff --git a/app/src/components/menu/menu.js b/app/src/components/menu/menu.js index 9c69ac6..81b8c3e 100644 --- a/app/src/components/menu/menu.js +++ b/app/src/components/menu/menu.js @@ -4,13 +4,12 @@ import {Menu, shell, clipboard, dialog} from 'electron'; * * @param {string} nativefierVersion * @param {function} onQuit should be from app.quit - * @param {function} onGoBack - * @param {electron} onGoForward * @param {function} onZoomIn * @param {function} onZoomOut - * @param {function} getUrl + * @param {{}}} mainWindow + * @param {{}}} options */ -function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn, onZoomOut, getUrl) { +function createMenu(nativefierVersion, onQuit, onZoomIn, onZoomOut, mainWindow, options) { if (Menu.getApplicationMenu()) { return; } @@ -46,7 +45,7 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn, label: 'Copy Current URL', accelerator: 'CmdOrCtrl+C', click: () => { - const currentURL = getUrl(); + const currentURL = mainWindow.webContents.getURL(); clipboard.writeText(currentURL); } }, @@ -69,14 +68,14 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn, label: 'Back', accelerator: 'CmdOrCtrl+[', click: () => { - onGoBack(); + mainWindow.webContents.goBack(); } }, { label: 'Forward', accelerator: 'CmdOrCtrl+]', click: () => { - onGoForward(); + mainWindow.webContents.goForward(); } }, { @@ -131,22 +130,23 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn, }, { label: 'Clear App Data', - click: (item, focusedWindow) => { - if (focusedWindow) { - dialog.showMessageBox(focusedWindow, { - type: 'warning', - buttons: ['Yes', 'Cancel'], - defaultId: 1, - title: 'Clear cache confirmation', - message: 'This will clear all data (cookies, local storage etc) from this app. Are you sure you wish to proceed?' - }, response => { - if (response === 0) { - focusedWindow.webContents.session.clearStorageData({}, - () => { - focusedWindow.webContents.session.clearCache(() => { - focusedWindow.reload(); - }); + click: () => { + dialog.showMessageBox(mainWindow, { + type: 'warning', + buttons: ['Yes', 'Cancel'], + defaultId: 1, + title: 'Clear cache confirmation', + message: 'This will clear all data (cookies, local storage etc) from this app. Are you sure you wish to proceed?' + }, response => { + if (response === 0) { + mainWindow.webContents.session.clearStorageData({}, + () => { + mainWindow.webContents.session.clearCache(() => { + mainWindow.loadURL(options.targetUrl); }); + }); + } + }); } }, {