forked from 3174N/stonecutter-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
210 lines (204 loc) · 8.1 KB
/
main.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
const { app, BrowserWindow, Menu, ipcMain } = require('electron');
const url = require('url');
const path = require('path');
// ! Does not work, document is undefined
//// const { foo } = require('./src/scripts/index.js');
const ipc = require('electron').ipcMain;
const { PerformanceObserver, performance } = require('perf_hooks');
const isMac = process.platform === 'darwin'; // Checks if running on macOS
let win;
function createWindow() {
/*
This part of the function handles the menu items
in the menubar at the top of the window.
macOS' guidelines are different from Windows',
so the menu will change depending on OS.
(Linux behaves like Windows)
*/
var menu = Menu.buildFromTemplate([
...(isMac
? [
{
label: app.name,
submenu: [
{ label: 'About Stonecutter', role: 'about' },
{ type: 'separator' },
{
label: 'Preferences...',
accelerator: 'CmdOrCtrl+,',
}, // TODO: Add preferences (new window?)
{ role: 'services' },
{ type: 'separator' },
{ label: 'Hide Stonecutter', role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ label: 'Quit Stonecutter', role: 'quit' },
],
},
]
: []),
...(isMac
? [
{
label: 'File',
submenu: [
{ label: 'New', accelerator: 'CmdOrCtrl+N' },
{
label: 'New Window',
accelerator: 'CmdOrCtrl+Shift+N',
},
{ type: 'separator' },
{
label: 'Open...',
click() {
win.webContents.send('open-file');
},
accelerator: 'CmdOrCtrl+O',
},
{
label: 'Open Folder...',
click() {
win.webContents.send('open-folder');
},
accelerator: 'CmdOrCtrl+Shift+O',
},
// ? { label: 'Open Recent' },
{ type: 'separator' },
{ label: 'Close Tab', accelerator: 'CmdOrCtrl+W' },
{
label: 'Close Window',
role: 'close',
accelerator: 'CmdOrCtrl+Shift+W',
},
{ type: 'separator' },
{
label: 'Save',
click() {
win.webContents.send('save');
},
accelerator: 'CmdOrCtrl+S',
},
{
label: 'Save As...',
click() {
win.webContents.send('save-as');
},
accelerator: 'CmdOrCtrl+Shift+S',
},
],
},
]
: [
{
label: 'File',
submenu: [
{ label: 'New File', accelerator: 'CmdOrCtrl+N' },
{
label: 'New Instance',
accelerator: 'CmdOrCtrl+Shift+N',
},
{ type: 'separator' },
{
label: 'Open File...',
click() {
win.webContents.send('open-file');
},
accelerator: 'CmdOrCtrl+O',
},
{
label: 'Open Folder...',
click() {
win.webContents.send('open-folder');
},
accelerator: 'CmdOrCtrl+Shift+O',
},
// ? { label: 'Open Recent' },
{ type: 'separator' },
{
label: 'Save',
click() {
win.webContents.send('save');
},
accelerator: 'CmdOrCtrl+S',
},
{
label: 'Save As...',
click() {
win.webContents.send('save-as');
},
accelerator: 'CmdOrCtrl+Shift+S',
},
{ type: 'separator' },
{
label: 'Preferences...',
accelerator: 'CmdOrCtrl+,',
}, // TODO: Add preferences (new window?) (if not new window then remove ellipsis)
{ type: 'separator' },
{ label: 'Close Tab', accelerator: 'CmdOrCtrl+W' },
{
label: 'Close Instance',
role: 'close',
accelerator: 'CmdOrCtrl+Shift+W',
},
{ type: 'separator' },
{ role: 'quit' },
],
},
]),
{
label: 'Edit',
submenu: [
{ label: 'Undo', role: 'undo' },
{ label: 'Redo', role: 'redo' },
{ type: 'separator' },
{ label: 'Cut', role: 'cut' },
{ label: 'Copy', role: 'copy' },
{ label: 'Paste', role: 'paste' },
],
},
{
label: 'View',
submenu: [
{ label: 'Actual Size', role: 'resetZoom' },
{
label: 'Zoom In',
role: 'zoomIn',
accelerator: 'CmdOrCtrl+=',
},
{ label: 'Zoom Out', role: 'zoomOut' },
{ type: 'separator' },
{ label: 'Toggle Fullscreen', role: 'togglefullscreen' },
{ label: 'Toggle Dev Tools', role: 'toggleDevTools' },
],
},
]);
Menu.setApplicationMenu(menu);
/*
This section contains window info,
such as size, icon and permissions
to interact with the code.
*/
win = new BrowserWindow({
width: 800,
height: 600,
icon: path.join(__dirname, 'src/styles/media/icon.ico'), // Icon path relative to root
webPreferences: {
nodeIntegration: true, // Enables use of node modules
enableRemoteModule: true, // Enables showing system dialogs
},
});
// Loads index.html
win.loadURL(
url.format({
pathname: path.join(__dirname, 'src/index.html'),
protocol: 'file:',
slashes: true,
}),
);
}
console.log('Launching Stonecutter...');
var t0 = performance.now();
app.on('ready', createWindow);
var t1 = performance.now();
console.log('Stonecutter successfully launched (' + (t1 - t0) + 'ms)'); // Prints difference between times, i.e. time to launch