Merge pull request #8570 from electron/force-refresh-menu-role

Add forcereload menu item role
This commit is contained in:
Kevin Sawicki 2017-02-03 09:44:57 -08:00 committed by GitHub
commit cf694ef32b
4 changed files with 22 additions and 2 deletions

View file

@ -86,6 +86,9 @@ app.once('ready', () => {
{ {
role: 'reload' role: 'reload'
}, },
{
role: 'forcereload'
},
{ {
role: 'toggledevtools' role: 'toggledevtools'
}, },

View file

@ -57,6 +57,7 @@ The `role` property can have following values:
* `close` - Close current window * `close` - Close current window
* `quit`- Quit the application * `quit`- Quit the application
* `reload` - Reload the current window * `reload` - Reload the current window
* `forcereload` - Reload the current window ignoring the cache.
* `toggledevtools` - Toggle developer tools in the current window * `toggledevtools` - Toggle developer tools in the current window
* `togglefullscreen`- Toggle full screen mode on the current window * `togglefullscreen`- Toggle full screen mode on the current window
* `resetzoom` - Reset the focused page's zoom level to the original size * `resetzoom` - Reset the focused page's zoom level to the original size

View file

@ -139,6 +139,9 @@ const template = [
{ {
role: 'reload' role: 'reload'
}, },
{
role: 'forcereload'
},
{ {
role: 'toggledevtools' role: 'toggledevtools'
}, },

View file

@ -25,6 +25,14 @@ const roles = {
label: 'Delete', label: 'Delete',
webContentsMethod: 'delete' webContentsMethod: 'delete'
}, },
forcereload: {
label: 'Force Reload',
accelerator: 'Shift+CmdOrCtrl+R',
nonNativeMacOSRole: true,
windowMethod: (window) => {
window.webContents.reloadIgnoringCache()
}
},
front: { front: {
label: 'Bring All to Front' label: 'Bring All to Front'
}, },
@ -75,11 +83,13 @@ const roles = {
reload: { reload: {
label: 'Reload', label: 'Reload',
accelerator: 'CmdOrCtrl+R', accelerator: 'CmdOrCtrl+R',
nonNativeMacOSRole: true,
windowMethod: 'reload' windowMethod: 'reload'
}, },
resetzoom: { resetzoom: {
label: 'Actual Size', label: 'Actual Size',
accelerator: 'CommandOrControl+0', accelerator: 'CommandOrControl+0',
nonNativeMacOSRole: true,
webContentsMethod: (webContents) => { webContentsMethod: (webContents) => {
webContents.setZoomLevel(0) webContents.setZoomLevel(0)
} }
@ -101,6 +111,7 @@ const roles = {
toggledevtools: { toggledevtools: {
label: 'Toggle Developer Tools', label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
nonNativeMacOSRole: true,
windowMethod: 'toggleDevTools' windowMethod: 'toggleDevTools'
}, },
togglefullscreen: { togglefullscreen: {
@ -127,6 +138,7 @@ const roles = {
zoomin: { zoomin: {
label: 'Zoom In', label: 'Zoom In',
accelerator: 'CommandOrControl+Plus', accelerator: 'CommandOrControl+Plus',
nonNativeMacOSRole: true,
webContentsMethod: (webContents) => { webContentsMethod: (webContents) => {
webContents.getZoomLevel((zoomLevel) => { webContents.getZoomLevel((zoomLevel) => {
webContents.setZoomLevel(zoomLevel + 0.5) webContents.setZoomLevel(zoomLevel + 0.5)
@ -136,6 +148,7 @@ const roles = {
zoomout: { zoomout: {
label: 'Zoom Out', label: 'Zoom Out',
accelerator: 'CommandOrControl+-', accelerator: 'CommandOrControl+-',
nonNativeMacOSRole: true,
webContentsMethod: (webContents) => { webContentsMethod: (webContents) => {
webContents.getZoomLevel((zoomLevel) => { webContents.getZoomLevel((zoomLevel) => {
webContents.setZoomLevel(zoomLevel - 0.5) webContents.setZoomLevel(zoomLevel - 0.5)
@ -147,8 +160,8 @@ const roles = {
const canExecuteRole = (role) => { const canExecuteRole = (role) => {
if (!roles.hasOwnProperty(role)) return false if (!roles.hasOwnProperty(role)) return false
if (process.platform !== 'darwin') return true if (process.platform !== 'darwin') return true
// macOS handles all roles natively except the ones listed below // macOS handles all roles natively except for a few
return ['reload', 'resetzoom', 'toggledevtools', 'zoomin', 'zoomout'].includes(role) return roles[role].nonNativeMacOSRole
} }
exports.getDefaultLabel = (role) => { exports.getDefaultLabel = (role) => {