mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
fix: on Linux/Win, hide OSX specific menu items and change 'Shell' to 'File' (#736)
Based on this document: https://github.com/electron/electron/blob/master/docs/api/menu.md#user-content-notes-on-os-x-application-menu
This commit is contained in:
parent
a27f5556fd
commit
6959667589
1 changed files with 299 additions and 265 deletions
564
app/menu.js
564
app/menu.js
|
|
@ -8,260 +8,284 @@ const appName = app.getName();
|
||||||
// https://github.com/sindresorhus/anatine/blob/master/menu.js
|
// https://github.com/sindresorhus/anatine/blob/master/menu.js
|
||||||
|
|
||||||
module.exports = function createMenu({createWindow, updatePlugins}) {
|
module.exports = function createMenu({createWindow, updatePlugins}) {
|
||||||
return [
|
const osxApplicationMenu = {
|
||||||
{
|
// This menu label is overrided by OSX to be the appName
|
||||||
label: 'Application',
|
// The label is set to appName here so it matches actual behavior
|
||||||
submenu: [
|
label: appName,
|
||||||
{
|
submenu: [
|
||||||
role: 'about'
|
{
|
||||||
},
|
role: 'about'
|
||||||
{
|
},
|
||||||
type: 'separator'
|
{
|
||||||
},
|
type: 'separator'
|
||||||
{
|
},
|
||||||
label: 'Preferences...',
|
{
|
||||||
accelerator: 'Cmd+,',
|
label: 'Preferences...',
|
||||||
click(item, focusedWindow) {
|
accelerator: 'Cmd+,',
|
||||||
if (focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
focusedWindow.rpc.emit('preferences');
|
if (focusedWindow) {
|
||||||
} else {
|
focusedWindow.rpc.emit('preferences');
|
||||||
createWindow(win => win.rpc.emit('preferences'));
|
} else {
|
||||||
}
|
createWindow(win => win.rpc.emit('preferences'));
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'services',
|
|
||||||
submenu: []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'hide'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'hideothers'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'unhide'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'quit'
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
type: 'separator'
|
||||||
label: 'Shell',
|
},
|
||||||
submenu: [
|
{
|
||||||
{
|
role: 'services',
|
||||||
label: 'New Window',
|
submenu: []
|
||||||
accelerator: 'CmdOrCtrl+N',
|
},
|
||||||
click() {
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'hide'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'hideothers'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'unhide'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'quit'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const shellOrFileMenu = {
|
||||||
|
label: process.platform === 'darwin' ? 'Shell' : 'File',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'New Window',
|
||||||
|
accelerator: 'CmdOrCtrl+N',
|
||||||
|
click() {
|
||||||
|
createWindow();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'New Tab',
|
||||||
|
accelerator: 'CmdOrCtrl+T',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('session add req');
|
||||||
|
} else {
|
||||||
createWindow();
|
createWindow();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'New Tab',
|
|
||||||
accelerator: 'CmdOrCtrl+T',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('session add req');
|
|
||||||
} else {
|
|
||||||
createWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Close',
|
|
||||||
accelerator: 'CmdOrCtrl+W',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('session close req');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Close Terminal Window',
|
|
||||||
role: 'close',
|
|
||||||
accelerator: 'CmdOrCtrl+Shift+W'
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
type: 'separator'
|
||||||
label: 'Edit',
|
},
|
||||||
submenu: [
|
{
|
||||||
{
|
label: 'Close',
|
||||||
role: 'undo'
|
accelerator: 'CmdOrCtrl+W',
|
||||||
},
|
click(item, focusedWindow) {
|
||||||
{
|
if (focusedWindow) {
|
||||||
role: 'redo'
|
focusedWindow.rpc.emit('session close req');
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'cut'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'copy'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'paste'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'selectall'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Clear',
|
|
||||||
accelerator: 'CmdOrCtrl+K',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('session clear req');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
label: process.platform === 'darwin' ? 'Close Terminal Window' : 'Quit',
|
||||||
label: 'View',
|
role: 'close',
|
||||||
submenu: [
|
accelerator: 'CmdOrCtrl+Shift+W'
|
||||||
{
|
}
|
||||||
label: 'Reload',
|
]
|
||||||
accelerator: 'CmdOrCtrl+R',
|
};
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
const editMenu = {
|
||||||
focusedWindow.rpc.emit('reload');
|
label: 'Edit',
|
||||||
}
|
submenu: [
|
||||||
}
|
{
|
||||||
},
|
role: 'undo'
|
||||||
{
|
},
|
||||||
label: 'Full Reload',
|
{
|
||||||
accelerator: 'CmdOrCtrl+Shift+R',
|
role: 'redo'
|
||||||
click(item, focusedWindow) {
|
},
|
||||||
if (focusedWindow) {
|
{
|
||||||
focusedWindow.reload();
|
type: 'separator'
|
||||||
}
|
},
|
||||||
}
|
{
|
||||||
},
|
role: 'cut'
|
||||||
{
|
},
|
||||||
label: 'Toggle Developer Tools',
|
{
|
||||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
role: 'copy'
|
||||||
click(item, focusedWindow) {
|
},
|
||||||
if (focusedWindow) {
|
{
|
||||||
focusedWindow.webContents.toggleDevTools();
|
role: 'paste'
|
||||||
}
|
},
|
||||||
}
|
{
|
||||||
},
|
role: 'selectall'
|
||||||
{
|
},
|
||||||
type: 'separator'
|
{
|
||||||
},
|
type: 'separator'
|
||||||
{
|
},
|
||||||
label: 'Reset Zoom Level',
|
{
|
||||||
accelerator: 'CmdOrCtrl+0',
|
label: 'Clear',
|
||||||
click(item, focusedWindow) {
|
accelerator: 'CmdOrCtrl+K',
|
||||||
if (focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
focusedWindow.rpc.emit('reset fontSize req');
|
if (focusedWindow) {
|
||||||
}
|
focusedWindow.rpc.emit('session clear req');
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Zoom In',
|
|
||||||
accelerator: 'CmdOrCtrl+plus',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('increase fontSize req');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Zoom Out',
|
|
||||||
accelerator: 'CmdOrCtrl+-',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('decrease fontSize req');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
},
|
]
|
||||||
{
|
};
|
||||||
label: 'Plugins',
|
|
||||||
submenu: [
|
if (process.platform !== 'darwin') {
|
||||||
{
|
editMenu.submenu.push(
|
||||||
label: 'Update All Now',
|
{type: 'separator'},
|
||||||
accelerator: 'CmdOrCtrl+Shift+U',
|
{
|
||||||
click() {
|
label: 'Preferences...',
|
||||||
updatePlugins();
|
accelerator: 'Cmd+,',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('preferences');
|
||||||
|
} else {
|
||||||
|
createWindow(win => win.rpc.emit('preferences'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
},
|
);
|
||||||
{
|
}
|
||||||
role: 'window',
|
|
||||||
submenu: [
|
const viewMenu = {
|
||||||
{
|
label: 'View',
|
||||||
role: 'minimize'
|
submenu: [
|
||||||
},
|
{
|
||||||
{
|
label: 'Reload',
|
||||||
role: 'zoom'
|
accelerator: 'CmdOrCtrl+R',
|
||||||
},
|
click(item, focusedWindow) {
|
||||||
{
|
if (focusedWindow) {
|
||||||
type: 'separator'
|
focusedWindow.rpc.emit('reload');
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Show Previous Tab',
|
|
||||||
accelerator: 'CmdOrCtrl+Option+Left',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('move left req');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Show Next Tab',
|
|
||||||
accelerator: 'CmdOrCtrl+Option+Right',
|
|
||||||
click(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.rpc.emit('move right req');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'separator'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'front'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: 'togglefullscreen'
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
},
|
{
|
||||||
{
|
label: 'Full Reload',
|
||||||
role: 'help',
|
accelerator: 'CmdOrCtrl+Shift+R',
|
||||||
submenu: [
|
click(item, focusedWindow) {
|
||||||
{
|
if (focusedWindow) {
|
||||||
label: `${appName} Website`,
|
focusedWindow.reload();
|
||||||
click() {
|
|
||||||
shell.openExternal('https://hyperterm.now.sh');
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
{
|
},
|
||||||
label: 'Report an Issue...',
|
{
|
||||||
click() {
|
label: 'Toggle Developer Tools',
|
||||||
const body = `
|
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.webContents.toggleDevTools();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Reset Zoom Level',
|
||||||
|
accelerator: 'CmdOrCtrl+0',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('reset fontSize req');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Zoom In',
|
||||||
|
accelerator: 'CmdOrCtrl+plus',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('increase fontSize req');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Zoom Out',
|
||||||
|
accelerator: 'CmdOrCtrl+-',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('decrease fontSize req');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const pluginsMenu = {
|
||||||
|
label: 'Plugins',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Update All Now',
|
||||||
|
accelerator: 'CmdOrCtrl+Shift+U',
|
||||||
|
click() {
|
||||||
|
updatePlugins();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const windowMenu = {
|
||||||
|
role: 'window',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
role: 'minimize'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'zoom'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Show Previous Tab',
|
||||||
|
accelerator: 'CmdOrCtrl+Option+Left',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('move left req');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Show Next Tab',
|
||||||
|
accelerator: 'CmdOrCtrl+Option+Right',
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
focusedWindow.rpc.emit('move right req');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'front'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'togglefullscreen'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const helpMenu = {
|
||||||
|
role: 'help',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: `${appName} Website`,
|
||||||
|
click() {
|
||||||
|
shell.openExternal('https://hyperterm.now.sh');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Report an Issue...',
|
||||||
|
click() {
|
||||||
|
const body = `
|
||||||
<!-- Please succinctly describe your issue and steps to reproduce it. -->
|
<!-- Please succinctly describe your issue and steps to reproduce it. -->
|
||||||
|
|
||||||
-
|
-
|
||||||
|
|
@ -270,29 +294,39 @@ ${app.getName()} ${app.getVersion()}
|
||||||
Electron ${process.versions.electron}
|
Electron ${process.versions.electron}
|
||||||
${process.platform} ${process.arch} ${os.release()}`;
|
${process.platform} ${process.arch} ${os.release()}`;
|
||||||
|
|
||||||
shell.openExternal(`https://github.com/zeit/hyperterm/issues/new?body=${encodeURIComponent(body)}`);
|
shell.openExternal(`https://github.com/zeit/hyperterm/issues/new?body=${encodeURIComponent(body)}`);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
...(
|
]
|
||||||
process.platform === 'darwin' ?
|
};
|
||||||
[] :
|
|
||||||
[
|
if (process.platform !== 'darwin') {
|
||||||
{type: 'separator'},
|
helpMenu.submenu.push(
|
||||||
{
|
{type: 'separator'},
|
||||||
role: 'about',
|
{
|
||||||
click() {
|
role: 'about',
|
||||||
dialog.showMessageBox({
|
click() {
|
||||||
title: `About ${appName}`,
|
dialog.showMessageBox({
|
||||||
message: `${appName} ${app.getVersion()}`,
|
title: `About ${appName}`,
|
||||||
detail: 'Created by Guillermo Rauch',
|
message: `${appName} ${app.getVersion()}`,
|
||||||
icon: path.join(__dirname, 'static/icon.png'),
|
detail: 'Created by Guillermo Rauch',
|
||||||
buttons: []
|
icon: path.join(__dirname, 'static/icon.png'),
|
||||||
});
|
buttons: []
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
)
|
);
|
||||||
]
|
}
|
||||||
}
|
|
||||||
];
|
const menu = [].concat(
|
||||||
|
process.platform === 'darwin' ? osxApplicationMenu : [],
|
||||||
|
shellOrFileMenu,
|
||||||
|
editMenu,
|
||||||
|
viewMenu,
|
||||||
|
pluginsMenu,
|
||||||
|
windowMenu,
|
||||||
|
helpMenu
|
||||||
|
);
|
||||||
|
|
||||||
|
return menu;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue