Add zoom menu item roles
This commit is contained in:
parent
59ffe35781
commit
bcc372568f
4 changed files with 47 additions and 31 deletions
|
@ -72,6 +72,13 @@ const roles = {
|
|||
accelerator: 'Shift+CommandOrControl+Z',
|
||||
webContentsMethod: 'redo'
|
||||
},
|
||||
resetzoom: {
|
||||
label: 'Actual Size',
|
||||
accelerator: 'CommandOrControl+0',
|
||||
webContentsMethod: (webContents) => {
|
||||
webContents.setZoomLevel(0)
|
||||
}
|
||||
},
|
||||
selectall: {
|
||||
label: 'Select All',
|
||||
accelerator: 'CommandOrControl+A',
|
||||
|
@ -106,9 +113,34 @@ const roles = {
|
|||
},
|
||||
zoom: {
|
||||
label: 'Zoom'
|
||||
},
|
||||
zoomin: {
|
||||
label: 'Zoom In',
|
||||
accelerator: 'CommandOrControl+Plus',
|
||||
webContentsMethod: (webContents) => {
|
||||
webContents.getZoomLevel((zoomLevel) => {
|
||||
webContents.setZoomLevel(zoomLevel + 0.5)
|
||||
})
|
||||
}
|
||||
},
|
||||
zoomout: {
|
||||
label: 'Zoom Out',
|
||||
accelerator: 'CommandOrControl+-',
|
||||
webContentsMethod: (webContents) => {
|
||||
webContents.getZoomLevel((zoomLevel) => {
|
||||
webContents.setZoomLevel(zoomLevel - 0.5)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const canExecuteRole = (role) => {
|
||||
if (!roles.hasOwnProperty(role)) return false
|
||||
if (process.platform !== 'darwin') return true
|
||||
// macOS handles all roles natively except the ones listed below
|
||||
return ['zoomin', 'zoomout', 'resetzoom'].includes(role)
|
||||
}
|
||||
|
||||
exports.getDefaultLabel = (role) => {
|
||||
if (roles.hasOwnProperty(role)) {
|
||||
return roles[role].label
|
||||
|
@ -122,8 +154,7 @@ exports.getDefaultAccelerator = (role) => {
|
|||
}
|
||||
|
||||
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
||||
if (!roles.hasOwnProperty(role)) return false
|
||||
if (process.platform === 'darwin') return false
|
||||
if (!canExecuteRole(role)) return false
|
||||
|
||||
const {appMethod, webContentsMethod, windowMethod} = roles[role]
|
||||
|
||||
|
@ -142,7 +173,11 @@ exports.execute = (role, focusedWindow, focusedWebContents) => {
|
|||
}
|
||||
|
||||
if (webContentsMethod && focusedWebContents != null) {
|
||||
focusedWebContents[webContentsMethod]()
|
||||
if (typeof webContentsMethod === 'function') {
|
||||
webContentsMethod(focusedWebContents)
|
||||
} else {
|
||||
focusedWebContents[webContentsMethod]()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue