This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmenus.js
379 lines (346 loc) · 9.6 KB
/
menus.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import { APPIUM_SESSION_EXTENSION } from "../app/main/helpers";
let menuTemplates = {mac: {}, other: {}};
function languageMenu ({config, i18n}) {
return config.languages.map((languageCode) => ({
label: i18n.t(languageCode),
type: 'radio',
checked: i18n.language === languageCode,
click: () => i18n.changeLanguage(languageCode)
}));
}
function getShowAppInfoClickAction ({dialog, i18n, app}) {
return () => {
dialog.showMessageBox({
title: i18n.t('appiumDesktop'),
message: i18n.t('showAppInfo', {
appVersion: app.getVersion(),
electronVersion: process.versions.electron,
nodejsVersion: process.versions.node
}),
});
};
}
function macMenuAppium ({dialog, i18n, app, checkNewUpdates, extraMenus}) {
const menu = {
label: 'Appium',
submenu: [{
label: i18n.t('About Appium'),
click: getShowAppInfoClickAction({dialog, i18n, app})
}, {
label: i18n.t('Check for updates'),
click () {
checkNewUpdates(true);
}
}, {
type: 'separator'
}, {
label: i18n.t('Hide Appium'),
accelerator: 'Command+H',
selector: 'hide:'
}, {
label: i18n.t('Hide Others'),
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
}, {
label: i18n.t('Show All'),
selector: 'unhideAllApplications:'
}, {
type: 'separator'
}, {
label: i18n.t('Quit'),
accelerator: 'Command+Q',
click () {
app.quit();
}
}]
};
for (const extraMenu of extraMenus) {
menu.submenu.splice(extraMenu.index, 0, extraMenu.menu);
}
return menu;
}
function macMenuEdit ({i18n}) {
return {
label: i18n.t('Edit'),
submenu: [{
label: i18n.t('Undo'),
accelerator: 'Command+Z',
selector: 'undo:'
}, {
label: i18n.t('Redo'),
accelerator: 'Shift+Command+Z',
selector: 'redo:'
}, {
type: 'separator'
}, {
label: i18n.t('Cut'),
accelerator: 'Command+X',
selector: 'cut:'
}, {
label: i18n.t('Copy'),
accelerator: 'Command+C',
selector: 'copy:'
}, {
label: i18n.t('Paste'),
accelerator: 'Command+V',
selector: 'paste:'
}, {
label: i18n.t('Select All'),
accelerator: 'Command+A',
selector: 'selectAll:'
}]
};
}
function macMenuView ({i18n, mainWindow, config}) {
const submenu = (process.env.NODE_ENV === 'development') ? [{
label: i18n.t('Reload'),
accelerator: 'Command+R',
click () {
mainWindow.webContents.reload();
}
}, {
label: i18n.t('Toggle Developer Tools'),
accelerator: 'Alt+Command+I',
click () {
mainWindow.toggleDevTools();
}
}] : [];
submenu.push({
label: i18n.t('Toggle Full Screen'),
accelerator: 'Ctrl+Command+F',
click () {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
});
submenu.push({
label: i18n.t('Languages'),
submenu: languageMenu({config, i18n}),
});
return {
label: i18n.t('View'),
submenu,
};
}
function macMenuWindow ({i18n}) {
return {
label: i18n.t('Window'),
submenu: [{
label: i18n.t('Minimize'),
accelerator: 'Command+M',
selector: 'performMiniaturize:'
}, {
label: i18n.t('Close'),
accelerator: 'Command+W',
selector: 'performClose:'
}, {
type: 'separator'
}, {
label: i18n.t('Bring All to Front'),
selector: 'arrangeInFront:'
}]
};
}
function macMenuHelp ({i18n, shell}) {
return {
label: i18n.t('Help'),
submenu: [{
label: i18n.t('Learn More'),
click () {
shell.openExternal('http://appium.io');
}
}, {
label: i18n.t('Documentation'),
click () {
shell.openExternal('https://appium.io/documentation.html');
}
}, {
label: i18n.t('Search Issues'),
click () {
shell.openExternal('https://github.com/appium/appium-desktop/issues');
}
}, {
label: i18n.t('Add Or Improve Translations'),
click () {
shell.openExternal('https://crowdin.com/project/appium-desktop');
}
}]
};
}
menuTemplates.mac = ({dialog, i18n, app, checkNewUpdates, extraMenus, extraFileMenus, mainWindow, config, shell, shouldShowFileMenu}) => [
macMenuAppium({dialog, i18n, app, checkNewUpdates, extraMenus}),
...(shouldShowFileMenu ? [macMenuFile({i18n, mainWindow, dialog, shouldShowFileMenu, extraFileMenus})]: []),
macMenuEdit({i18n}),
macMenuView({i18n, mainWindow, config}),
macMenuWindow({i18n}),
macMenuHelp({i18n, shell}),
];
async function openFileCallback (mainWindow, dialog) {
const { canceled, filePaths } = await dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{name: 'Appium Session Files', extensions: [APPIUM_SESSION_EXTENSION]}
],
})
if (!canceled) {
const filePath = filePaths[0];
mainWindow.webContents.send('open-file', filePath);
}
};
async function saveAsCallback (mainWindow, dialog, i18n) {
const { canceled, filePath } = await dialog.showSaveDialog({
title: i18n.t('saveAs'),
filters: [{ name: 'Appium', extensions: [APPIUM_SESSION_EXTENSION] }],
});
if (!canceled) {
mainWindow.webContents.send('save-file', filePath);
}
}
function macMenuFile ({i18n, mainWindow, dialog, extraFileMenus}) {
let fileSubmenu = [{
label: i18n.t('Open'),
accelerator: 'Command+O',
click: () => openFileCallback(mainWindow, dialog),
}, {
label: i18n.t('Save'),
accelerator: 'Command+S',
click: () => mainWindow.webContents.send('save-file'),
}, {
label: i18n.t('saveAs'),
accelerator: 'Command+Shift+S',
click: () => saveAsCallback(mainWindow, dialog, i18n),
}];
for (const extraMenu of extraFileMenus) {
fileSubmenu.splice(extraMenu.index, 0, extraMenu.menu);
}
return {
label: '&'+i18n.t('File'),
submenu: fileSubmenu,
};
}
function otherMenuFile ({i18n, dialog, app, mainWindow, checkNewUpdates, extraFileMenus, shouldShowFileMenu}) {
const fileSavingOperations = [{
label: i18n.t('Open'),
accelerator: 'Ctrl+O',
click: () => openFileCallback(mainWindow, dialog),
}, {
label: i18n.t('Save'),
accelerator: 'Ctrl+S',
click: () => mainWindow.webContents.send('save-file'),
}, {
label: i18n.t('saveAs'),
accelerator: 'Ctrl+Shift+S',
click: () => saveAsCallback(mainWindow, dialog, i18n),
}];
let fileSubmenu = [
...(shouldShowFileMenu ? fileSavingOperations : []),
{
label: '&'+i18n.t('About Appium'),
click: getShowAppInfoClickAction({dialog, i18n, app}),
}, {
type: 'separator'
}, {
label: '&'+i18n.t('Close'),
accelerator: 'Ctrl+W',
click () {
mainWindow.close();
}
}
];
if (shouldShowFileMenu) {
for (const extraMenu of extraFileMenus) {
fileSubmenu.splice(extraMenu.index, 0, extraMenu.menu);
}
}
// If it's Windows, add a 'Check for Updates' menu option
if (process.platform === 'win32') {
fileSubmenu.splice(1, 0, {
label: '&'+i18n.t('Check for updates'),
click () {
checkNewUpdates(true);
}
});
}
return {
label: '&'+i18n.t('File'),
submenu: fileSubmenu,
};
}
function otherMenuView ({i18n, mainWindow, config}) {
const submenu = [];
submenu.push({
label: i18n.t('Toggle &Full Screen'),
accelerator: 'F11',
click () {
mainWindow.setFullScreen(!mainWindow.isFullScreen());
}
});
submenu.push({
label: i18n.t('Languages'),
submenu: languageMenu({config, i18n}),
});
if (process.env.NODE_ENV === 'development') {
submenu.push({
label: '&'+i18n.t('Reload'),
accelerator: 'Ctrl+R',
click () {
mainWindow.webContents.reload();
}
});
submenu.push({
label: i18n.t('Toggle &Developer Tools'),
accelerator: 'Alt+Ctrl+I',
click () {
mainWindow.toggleDevTools();
}
});
}
return {
label: '&'+i18n.t('View'),
submenu,
};
}
function otherMenuHelp ({i18n, shell}) {
return {
label: i18n.t('Help'),
submenu: [{
label: i18n.t('Learn More'),
click () {
shell.openExternal('http://appium.io');
}
}, {
label: i18n.t('Documentation'),
click () {
shell.openExternal('https://appium.io/documentation.html');
}
}, {
label: i18n.t('Search Issues'),
click () {
shell.openExternal('https://github.com/appium/appium-desktop/issues');
}
}, {
label: i18n.t('Add Or Improve Translations'),
click () {
shell.openExternal('https://crowdin.com/project/appium-desktop');
}
}]
};
}
menuTemplates.other = ({mainWindow, i18n, dialog, app, checkNewUpdates, config, shell, shouldShowFileMenu, extraFileMenus}) => [
otherMenuFile({i18n, dialog, app, mainWindow, checkNewUpdates, shouldShowFileMenu, extraFileMenus}),
otherMenuView({i18n, mainWindow, config}),
otherMenuHelp({i18n, shell})
];
export function rebuildMenus ({mainWindow, config, Menu, dialog, i18n, app, checkNewUpdates, extraMacMenus, extraFileMenus, extraMacFileMenus, shell, shouldShowFileMenu}) {
if (!mainWindow) {
return;
}
if (config.platform === 'darwin') {
const template = menuTemplates.mac({dialog, i18n, app, checkNewUpdates, extraMenus: extraMacMenus, extraFileMenus: extraMacFileMenus, mainWindow, config, shell, shouldShowFileMenu});
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
} else {
const template = menuTemplates.other({mainWindow, i18n, dialog, app, extraFileMenus, checkNewUpdates, config, shell, shouldShowFileMenu});
const menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu);
}
}