-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathexample.js
163 lines (150 loc) · 2.77 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
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
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import assert from 'node:assert';
import {app, BrowserWindow, Menu, dialog} from 'electron';
import {
openNewGitHubIssue,
openUrlMenuItem,
openSystemPreferences,
runJS,
platform,
} from '../distribution/shared/index.js';
import {
showAboutWindow,
aboutMenuItem,
debugInfo,
appMenu,
} from '../distribution/main/index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
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',
click() {
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 appMenuItems = appMenu([
{
label: 'Extra item',
enabled: false,
},
]);
const menu = Menu.buildFromTemplate([
appMenuItems,
{
label: 'Test',
submenu: items,
},
]);
Menu.setApplicationMenu(menu);
};
// eslint-disable-next-line unicorn/prefer-top-level-await -- whenReady is broken in top-level await.
(async () => {
await app.whenReady();
createMenu();
const mainWindow = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.cjs'),
},
});
await mainWindow.loadFile('index.html');
mainWindow.webContents.openDevTools('undocked');
assert.strictEqual(await runJS('2 + 2'), 4);
const platformTestCases = [
[
'basic',
{
linux: 1,
macos: 2,
default: 3,
},
2,
],
[
'function',
{
linux: 1,
macos: () => 2,
default: 3,
},
2,
],
[
'default',
{
linux: 1,
default: 3,
},
3,
],
[
'undefined',
{
linux: 1,
},
undefined,
],
];
setTimeout(() => {
for (const [name, input, expected] of platformTestCases) {
const actual = platform(input);
if (actual === expected) {
mainWindow.webContents.send(
'test-platform',
name,
actual,
expected,
true,
);
} else {
mainWindow.webContents.send(
'test-platform',
name,
actual,
expected,
false,
);
}
}
}, 1000);
})();