-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.js
149 lines (136 loc) · 3.64 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
const path = require('path');
const url = require('url');
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const app = electron.app;
const Menu = electron.Menu;
let mainWindow = null;
const isSecondInstance = app.makeSingleInstance(
(commandLine, workingDirectory) => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.focus();
}
},
);
if (isSecondInstance) {
app.quit();
}
function initialize() {
app.on('ready', function() {
createWindow();
});
app.on('window-all-closed', function() {
app.quit();
});
app.on('activate', function() {
if (mainWindow === null) {
createWindow();
}
});
}
function createWindow() {
const windowOptions = {
title: app.getName(),
//resizable: true,
width: 1280,
height: 720,
minWidth: 1280,
minHeight: 720,
maxWidth: 1280,
webPreferences: {
webSecurity: false,
},
};
if (process.platform === 'linux') {
windowOptions.icon = path.join(__dirname, '/front/assets/app-icon.svg');
}
mainWindow = new BrowserWindow(windowOptions);
mainWindow.loadURL(
url.format({
protocol: 'file',
slashes: true,
pathname: path.join(__dirname, 'docs/index.html'),
}),
);
mainWindow.on('closed', function() {
mainWindow = null;
});
// Create the Application's main menu
const template = [
{
label: 'Electron',
submenu: [
{
label: 'Quit',
accelerator: 'Command+Q',
click: function() {
app.quit();
},
},
],
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:',
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:',
},
{
type: 'separator',
},
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:',
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:',
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:',
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:',
},
],
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() {
mainWindow.reload();
},
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() {
mainWindow.toggleDevTools();
},
},
],
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
initialize();