-
Notifications
You must be signed in to change notification settings - Fork 29
/
menu.js
189 lines (180 loc) · 3.89 KB
/
menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const { app, BrowserWindow, Menu, shell, dialog } = require('electron')
const path = require('path')
const os = require('os')
const config = require('./config')
const { platform, arch, versions } = process
/**
* Creates an issue body text.
* @return {String}
*/
function getIssueBody() {
const text = '[Replace this with your issue, but leave the table below]'
const table = [
'<table>',
`<tr><td>${app.getName()}</td><td>${app.getVersion()}</td></tr>`,
`<tr><td>Electron</td><td>${versions.electron}</td></tr>`,
`<tr><td>${platform} (${arch})</td><td>${os.release()}</td></tr>`,
'</table>',
].join('')
return `${text} \n *** \n ### System information \n ${table}`
}
/**
* Send an asynchronous message to renderer process.
* @param {String} event
* @return {undefined}
*/
function sendToWebContent(event) {
const window = BrowserWindow.getAllWindows()[0]
if (platform === 'darwin') {
window.restore()
}
window.webContents.send(event)
}
const template = []
const menu = {
[app.getName()]: {
label: app.getName(),
submenu: [
{ role: 'about' },
{ label: `Version ${app.getVersion()}`, enabled: false },
{ type: 'separator' },
{
label: 'Preferences...',
accelerator: 'Cmd+,',
click() {
sendToWebContent('show-preferences')
},
},
{ type: 'separator' },
{
label: 'Log Out',
click() {
sendToWebContent('log-out')
},
},
{ type: 'separator' },
{
role: 'services',
submenu: [],
},
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ type: 'separator' },
{ role: 'quit' },
],
},
file: {
label: 'File',
submenu: [
{
label: 'Create new document',
accelerator: 'Cmd+N',
click() {
sendToWebContent('new-document')
},
},
{
label: 'Create meeting document',
click() {
sendToWebContent('meeting-document')
},
},
{ type: 'separator' },
{
label: 'Create new folder',
accelerator: 'Cmd+T',
click() {
sendToWebContent('new-folder')
},
},
{ type: 'separator' },
{
label: 'Download document',
accelerator: 'Cmd+D',
click() {
sendToWebContent('download-document')
},
},
],
},
edit: {
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectall' },
],
},
view: {
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
],
},
window: {
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'close' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
{ role: 'front' },
],
},
help: {
role: 'help',
submenu: [
{
label: `Visit ${app.getName()} website`,
click() {
shell.openExternal(config.get('repository'))
},
},
{
label: 'Report an issue',
click() {
const body = encodeURIComponent(getIssueBody())
shell.openExternal(`${config.get('repository')}/issues/new?body=${body}`)
},
},
],
},
about: {
role: 'about',
click() {
dialog.showMessageBox({
title: `About ${app.getName()}`,
message: `${app.getName()} ${app.getVersion()}`,
detail: 'Created by Moritz Kröger',
icon: path.join(__dirname, 'static/dropbox-osx.png'),
buttons: [],
})
},
},
}
if (platform === 'darwin') {
template.push(menu[app.getName()])
} else {
menu.view.submenu.push({ type: 'separator' }, { role: 'quit' })
// If not on macOS, add the about menu item to help.
menu.help.submenu.unshift(menu.about, { type: 'separator' })
}
template.push(menu.file)
template.push(menu.edit)
template.push(menu.view)
template.push(menu.window)
template.push(menu.help)
module.exports = Menu.buildFromTemplate(template)