Skip to content

Commit ecc0d6a

Browse files
committed
Add a standard set of basic menu options
1 parent a062626 commit ecc0d6a

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { spawn, ChildProcess } from 'child_process';
22
import * as os from 'os';
33
import * as path from 'path';
4-
import { app, BrowserWindow, shell } from 'electron';
4+
import { app, BrowserWindow, shell, Menu } from 'electron';
55

66
import * as registerContextMenu from 'electron-context-menu';
77
registerContextMenu({
88
showSaveImageAs: true
99
});
1010

11+
import { menu } from './menu';
12+
1113
const packageJson = require('../package.json');
1214

1315
const isWindows = os.platform() === 'win32';
@@ -54,6 +56,10 @@ const createWindow = () => {
5456
});
5557
};
5658

59+
app.on('ready', () => {
60+
Menu.setApplicationMenu(menu);
61+
});
62+
5763
app.on('window-all-closed', () => {
5864
// On OS X it is common for applications and their menu bar
5965
// to stay active until the user quits explicitly with Cmd + Q

src/menu.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { app, Menu } from 'electron';
2+
3+
const template = [
4+
{
5+
label: '&File',
6+
submenu: [
7+
{ role: 'quit' }
8+
]
9+
},
10+
{
11+
label: '&Edit',
12+
submenu: [
13+
{ role: 'undo' },
14+
{ role: 'redo' },
15+
{ type: 'separator' },
16+
{ role: 'cut' },
17+
{ role: 'copy' },
18+
{ role: 'paste' },
19+
{ role: 'pasteandmatchstyle' },
20+
{ role: 'delete' },
21+
{ role: 'selectall' }
22+
]
23+
},
24+
{
25+
label: '&View',
26+
submenu: [
27+
{ role: 'resetzoom' },
28+
{ role: 'zoomin' },
29+
{ role: 'zoomout' },
30+
{ type: 'separator' },
31+
{ role: 'togglefullscreen' },
32+
{ type: 'separator' },
33+
{ role: 'reload' },
34+
{ role: 'forcereload' },
35+
{ role: 'toggledevtools' },
36+
]
37+
},
38+
{
39+
label: '&Window',
40+
role: 'window',
41+
submenu: [
42+
{ role: 'minimize' },
43+
{ role: 'close' }
44+
]
45+
},
46+
{
47+
label: '&Help',
48+
role: 'help',
49+
submenu: [
50+
{
51+
label: 'Learn More',
52+
click () { require('electron').shell.openExternal('https://httptoolkit.tech') }
53+
}
54+
]
55+
}
56+
]
57+
58+
if (process.platform === 'darwin') {
59+
template.unshift({
60+
label: app.getName(),
61+
submenu: [
62+
{ role: 'about' },
63+
{ type: 'separator' },
64+
{ role: 'services' },
65+
{ type: 'separator' },
66+
{ role: 'hide' },
67+
{ role: 'hideothers' },
68+
{ role: 'unhide' },
69+
{ type: 'separator' },
70+
{ role: 'quit' }
71+
]
72+
})
73+
74+
// Edit menu
75+
template[1].submenu.push(
76+
{ type: 'separator' },
77+
{
78+
label: 'Speech',
79+
submenu: [
80+
{ role: 'startspeaking' },
81+
{ role: 'stopspeaking' }
82+
]
83+
}
84+
)
85+
86+
// Window menu
87+
template[3].submenu = [
88+
{ role: 'close' },
89+
{ role: 'minimize' },
90+
{ role: 'zoom' },
91+
{ type: 'separator' },
92+
{ role: 'front' }
93+
]
94+
}
95+
96+
export const menu = Menu.buildFromTemplate(template)

0 commit comments

Comments
 (0)