2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-11 15:51:06 +00:00

add mainWindow and options objects to createMenu args and refactor

This commit is contained in:
Gary Moon 2016-02-24 09:45:22 -05:00
parent 546bad7035
commit ce76d0be7f
2 changed files with 23 additions and 23 deletions

View File

@ -54,7 +54,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
mainWindow.webContents.send('change-zoom', currentZoom); 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); initContextMenu(mainWindow);
if (options.userAgent) { if (options.userAgent) {

View File

@ -4,13 +4,12 @@ import {Menu, shell, clipboard, dialog} from 'electron';
* *
* @param {string} nativefierVersion * @param {string} nativefierVersion
* @param {function} onQuit should be from app.quit * @param {function} onQuit should be from app.quit
* @param {function} onGoBack
* @param {electron} onGoForward
* @param {function} onZoomIn * @param {function} onZoomIn
* @param {function} onZoomOut * @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()) { if (Menu.getApplicationMenu()) {
return; return;
} }
@ -46,7 +45,7 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
label: 'Copy Current URL', label: 'Copy Current URL',
accelerator: 'CmdOrCtrl+C', accelerator: 'CmdOrCtrl+C',
click: () => { click: () => {
const currentURL = getUrl(); const currentURL = mainWindow.webContents.getURL();
clipboard.writeText(currentURL); clipboard.writeText(currentURL);
} }
}, },
@ -69,14 +68,14 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
label: 'Back', label: 'Back',
accelerator: 'CmdOrCtrl+[', accelerator: 'CmdOrCtrl+[',
click: () => { click: () => {
onGoBack(); mainWindow.webContents.goBack();
} }
}, },
{ {
label: 'Forward', label: 'Forward',
accelerator: 'CmdOrCtrl+]', accelerator: 'CmdOrCtrl+]',
click: () => { click: () => {
onGoForward(); mainWindow.webContents.goForward();
} }
}, },
{ {
@ -131,22 +130,23 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
}, },
{ {
label: 'Clear App Data', label: 'Clear App Data',
click: (item, focusedWindow) => { click: () => {
if (focusedWindow) { dialog.showMessageBox(mainWindow, {
dialog.showMessageBox(focusedWindow, { type: 'warning',
type: 'warning', buttons: ['Yes', 'Cancel'],
buttons: ['Yes', 'Cancel'], defaultId: 1,
defaultId: 1, title: 'Clear cache confirmation',
title: 'Clear cache confirmation', message: 'This will clear all data (cookies, local storage etc) from this app. Are you sure you wish to proceed?'
message: 'This will clear all data (cookies, local storage etc) from this app. Are you sure you wish to proceed?' }, response => {
}, response => { if (response === 0) {
if (response === 0) { mainWindow.webContents.session.clearStorageData({},
focusedWindow.webContents.session.clearStorageData({}, () => {
() => { mainWindow.webContents.session.clearCache(() => {
focusedWindow.webContents.session.clearCache(() => { mainWindow.loadURL(options.targetUrl);
focusedWindow.reload();
});
}); });
});
}
});
} }
}, },
{ {