-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
electron.js
164 lines (149 loc) · 3.37 KB
/
electron.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
const electron = require('electron');
const { app, BrowserWindow, Menu } = electron;
const path = require('path');
const url = require('url');
/* Electron logic */
//Checks if it is a mac user or not
const isMac = process.platform === 'darwin';
const createWindow = () => {
// Creates a new window
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: true },
});
// Loads the html into the Electron App
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, './dist/index.html'),
protocol: 'file',
slashes: true,
})
);
mainWindow.webContents.openDevTools();
// These are currently interfering with keyboard commands (e.g. paste)
// Build Menu
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
// Insert Menu
Menu.setApplicationMenu(mainMenu);
};
// Once Electron has finished initialization:
app.whenReady().then(createWindow);
// Quit when all windows are closed
app.on('window-all-closed', () => {
// don't apply this to Macs
if (!isMac) {
app.quit();
}
});
// On Mac, recreate app window when dock icon is clicked and no other windows are open
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
}
});
// Create a new window
const aboutNewWindow = () => {
aboutWindow = new BrowserWindow({
width: 300,
height: 300,
title: 'About',
});
aboutWindow.loadURL(
url.format({
pathname: path.join(__dirname, './client/Components/About.html'),
protocol: 'file',
slashes: true,
})
);
// Garbage Collection Handler
aboutWindow.on('close', () => {
aboutWindow = null;
});
};
// Create Menu Template
const mainMenuTemplate = [
{
label: '',
submenu: [
{
label: 'About',
click() {
aboutNewWindow();
},
},
{
label: 'Quit',
accelerator: isMac ? 'Command+Q' : 'Ctrl+Q',
click() {
app.quit(); // Closes the program/gooey
},
},
],
},
{
label: 'File',
submenu: [
{
label: 'Placeholder',
},
{
label: 'Placeholder',
},
{
label: 'Placeholder',
},
],
},
{
label: 'Edit',
submenu: [
{
label: 'Copy',
accelerator: isMac ? 'Command+C' : 'Ctrl+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: isMac ? 'Command+V' : 'Ctrl+V',
selector: 'paste:'
},
{
label: 'Cut',
accelerator: isMac ? 'Command+X' : 'Ctrl+X',
selector: 'cut:'
},
{
label: 'Select All',
accelerator: isMac ? 'Command+A' : 'Ctrl+A',
selector: 'selectAll:'
},
{
label: 'Undo',
accelerator: isMac ? 'Command+Z' : 'Ctrl+Z',
selector: 'undo:'
},
{
label: 'Redo',
accelerator: isMac ? 'Command+Shift+Z' : 'Ctrl+Shift+Z',
selector: 'redo:'
},
],
},
];
if (process.env.NODE_ENV !== 'production' && process.NODE_ENV !== 'test') {
mainMenuTemplate.push({
label: 'Developer Tools',
submenu: [
{
label: 'Toggle DevTools',
accelerator: isMac ? 'Command+I' : 'Ctrl+I',
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
},
},
{
role: 'reload',
},
],
});
}