forked from sindresorhus/electron-util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
96 lines (86 loc) · 1.78 KB
/
example.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
'use strict';
const path = require('path');
const assert = require('assert');
const {app, BrowserWindow, Menu, dialog} = require('electron');
const {
openNewGitHubIssue,
openUrlMenuItem,
showAboutWindow,
aboutMenuItem,
debugInfo,
appMenu,
openSystemPreferences,
runJS
} = require('.');
/// const enforceMacosAppLocation = require('./source/enforce-macos-app-location');
const createMenu = () => {
const items = [
{
label: 'openNewGitHubIssue() test',
click() {
openNewGitHubIssue({
user: 'sindresorhus',
repo: 'playground',
body: 'Test 🦄'
});
}
},
{
label: 'openSystemPreferences() test',
click() {
openSystemPreferences();
}
},
openUrlMenuItem({
label: 'openUrlMenuItem() test',
url: 'https://sindresorhus.com',
onClick() {
console.log('Executed before opening the URL');
}
}),
{
label: 'showAboutWindow() test',
click() {
showAboutWindow({
icon: path.join(__dirname, 'fixtures/Icon.png'),
copyright: 'Copyright © Sindre Sorhus',
text: 'Some more info.'
});
}
},
aboutMenuItem({
icon: path.join(__dirname, 'fixtures/Icon.png'),
copyright: 'Copyright © Sindre Sorhus',
text: 'Some more info.'
}),
{
label: 'debugInfo() test',
click() {
dialog.showErrorBox('', debugInfo());
}
}
];
const menu = Menu.buildFromTemplate([
appMenu([
{
label: 'Extra item',
enabled: false
}
]),
{
label: 'Test',
submenu: items
}
]);
Menu.setApplicationMenu(menu);
};
let mainWindow;
(async () => {
await app.whenReady();
/// enforceMacosAppLocation();
createMenu();
mainWindow = new BrowserWindow();
await mainWindow.loadURL('about:blank');
mainWindow.webContents.openDevTools('undocked');
assert.strictEqual(await runJS('2 + 2'), 4);
})();