Merge pull request #6166 from electron/fullscreen-role
Add togglefullscreen menu item role
This commit is contained in:
commit
85c163e58a
4 changed files with 13 additions and 11 deletions
|
@ -39,6 +39,7 @@ Role kRolesMap[] = {
|
||||||
{ @selector(performClose:), "close" },
|
{ @selector(performClose:), "close" },
|
||||||
{ @selector(performZoom:), "zoom" },
|
{ @selector(performZoom:), "zoom" },
|
||||||
{ @selector(terminate:), "quit" },
|
{ @selector(terminate:), "quit" },
|
||||||
|
{ @selector(toggleFullScreen:), "togglefullscreen" },
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -107,18 +107,12 @@ app.once('ready', () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Toggle Full Screen',
|
||||||
accelerator: (() => {
|
role: 'togglefullscreen',
|
||||||
return (process.platform === 'darwin') ? 'Ctrl+Command+F' : 'F11'
|
accelerator: process.platform === 'darwin' ? 'Ctrl+Command+F' : 'F11'
|
||||||
})(),
|
|
||||||
click (item, focusedWindow) {
|
|
||||||
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Toggle Developer Tools',
|
||||||
accelerator: (() => {
|
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||||
return (process.platform === 'darwin') ? 'Alt+Command+I' : 'Ctrl+Shift+I'
|
|
||||||
})(),
|
|
||||||
click (item, focusedWindow) {
|
click (item, focusedWindow) {
|
||||||
if (focusedWindow) focusedWindow.toggleDevTools()
|
if (focusedWindow) focusedWindow.toggleDevTools()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ The `role` property can have following values:
|
||||||
* `minimize` - Minimize current window
|
* `minimize` - Minimize current window
|
||||||
* `close` - Close current window
|
* `close` - Close current window
|
||||||
* `quit`- Quit the application
|
* `quit`- Quit the application
|
||||||
|
* `togglefullscreen`- Toggle full screen mode on the current window
|
||||||
|
|
||||||
On macOS `role` can also have following additional values:
|
On macOS `role` can also have following additional values:
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,17 @@ const rolesMap = {
|
||||||
minimize: 'minimize',
|
minimize: 'minimize',
|
||||||
close: 'close',
|
close: 'close',
|
||||||
delete: 'delete',
|
delete: 'delete',
|
||||||
quit: 'quit'
|
quit: 'quit',
|
||||||
|
togglefullscreen: 'toggleFullScreen'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps methods that should be called directly on the BrowserWindow instance
|
// Maps methods that should be called directly on the BrowserWindow instance
|
||||||
const methodInBrowserWindow = {
|
const methodInBrowserWindow = {
|
||||||
minimize: true,
|
minimize: true,
|
||||||
close: true
|
close: true,
|
||||||
|
toggleFullScreen: function (window) {
|
||||||
|
window.setFullScreen(!window.isFullScreen())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const methodInApp = {
|
const methodInApp = {
|
||||||
|
@ -78,6 +82,8 @@ const MenuItem = (function () {
|
||||||
const methodName = rolesMap[this.role]
|
const methodName = rolesMap[this.role]
|
||||||
if (methodInApp[methodName]) {
|
if (methodInApp[methodName]) {
|
||||||
return app[methodName]()
|
return app[methodName]()
|
||||||
|
} else if (typeof methodInBrowserWindow[methodName] === 'function') {
|
||||||
|
return methodInBrowserWindow[methodName](focusedWindow)
|
||||||
} else if (methodInBrowserWindow[methodName]) {
|
} else if (methodInBrowserWindow[methodName]) {
|
||||||
return focusedWindow[methodName]()
|
return focusedWindow[methodName]()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue