mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-23 02:28:55 +00:00
add mainWindow and options objects to createMenu args and refactor
This commit is contained in:
parent
546bad7035
commit
ce76d0be7f
@ -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) {
|
||||
|
@ -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,9 +130,8 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
|
||||
},
|
||||
{
|
||||
label: 'Clear App Data',
|
||||
click: (item, focusedWindow) => {
|
||||
if (focusedWindow) {
|
||||
dialog.showMessageBox(focusedWindow, {
|
||||
click: () => {
|
||||
dialog.showMessageBox(mainWindow, {
|
||||
type: 'warning',
|
||||
buttons: ['Yes', 'Cancel'],
|
||||
defaultId: 1,
|
||||
@ -141,13 +139,15 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
|
||||
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({},
|
||||
mainWindow.webContents.session.clearStorageData({},
|
||||
() => {
|
||||
focusedWindow.webContents.session.clearCache(() => {
|
||||
focusedWindow.reload();
|
||||
mainWindow.webContents.session.clearCache(() => {
|
||||
mainWindow.loadURL(options.targetUrl);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Window Developer Tools',
|
||||
|
Loading…
Reference in New Issue
Block a user