-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
379 lines (328 loc) · 8.7 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
const electron = require('electron');
const url = require('url');
const path = require('path');
const {
app,
BrowserWindow,
dialog,
Menu,
Tray,
ipcMain
} = electron;
let mainWindow;
let aboutWindow;
let whatWindow;
let splashWindow;
let ExWindow;
app.on('ready', function () {
//Tray
tray = new Tray('views/assets/icons/app/icon.ico')
const contextMenu = Menu.buildFromTemplate([
{
label: 'Display',
click: () => {
mainWindow.show()
}
},
{
label: 'About Bizplus Enterprise 2019',
},
{
label: 'Exit',
click: () => {
mainWindow.destroy()
app.quit()
}
}
])
tray.setToolTip('Bizplus Enterprise 2019')
tray.setContextMenu(contextMenu)
//Create new window
mainWindow = new BrowserWindow({
width: 1080,
height: 768,
minWidth: 1080,
minHeight: 768,
center: true,
show: false, // don't show until splash screen finishes
title: 'Bizplus Enterprise 2019',
icon: path.join(__dirname, 'views/assets/icons/app/icon.ico'),
webPreferences: {
nodeIntegration: true
}
});
// mainWindow.webContents.openDevTools();//Create splash window
splashWindow = new BrowserWindow({
width: 590,
height: 300,
minWidth: 590,
minHeight: 300,
transparent: true,
frame: false,
maximizable: false,
center: true,
alwaysOnTop: true,
icon: path.join(__dirname, 'views/assets/icons/app/icon.ico')
});
//Load Splash HTML File
splashWindow.loadURL(url.format({
pathname: path.join(__dirname, 'splashWindow.html'),
protocol: 'file:',
slashes: true
}));
//Load Main HTML File
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
// if main window is ready to show, then destroy the splash window and show up the main window
mainWindow.once('ready-to-show', function () {
splashWindow.destroy();
mainWindow.show();
mainWindow.maximize();
});
//Garbage collection
mainWindow.on('closed', function () {
mainWindow = null
});
//Initialize Alert Message on App Quiting
mainWindow.on('close', (event) => {
event.preventDefault()
let options = {}
options.type = "question"
options.buttons = ["&Yes", "&Cancel"]
options.defaultId = 2
options.title = "Quit"
options.message = "Do you really want to quit?"
options.detail = "Any process not saved will be lost. Click Yes if you wish to proceed"
//options.icon = "/path/image.png"
options.cancelId = 2
options.noLink = true
options.normalizeAccessKeys = true
dialog.showMessageBox(mainWindow, options, (res, checked) => {
if (res === 0) {
mainWindow.destroy();
app.quit();
} else if (res === 1) {} else if (res === 2) {}
})
});
//Build menu from template
const mainMenu = Menu.buildFromTemplate(menuBar);
//Insert menu
Menu.setApplicationMenu(mainMenu);
});
//Handle AboutWindow
function createAboutWindow() {
//Create about window
aboutWindow = new BrowserWindow({
width: 500,
height: 400,
minWidth: 500,
minHeight: 400,
title: 'About',
minimizable: false,
maximizable: false,
center: true,
icon: path.join(__dirname, 'views/assets/icons/app/icon.ico')
});
//Load HTML File
aboutWindow.loadURL(url.format({
pathname: path.join(__dirname, 'aboutWindow.html'),
protocol: 'file:',
slashes: true
}));
//Garbage collection
aboutWindow.on('closed', function () {
aboutWindow = null;
});
aboutWindow.setMenu(null);
}
//Handle createWhatWindow
function createWhatWindow() {
//Create what's new window
whatWindow = new BrowserWindow({
width: 600,
height: 540,
minWidth: 600,
minHeight: 540,
title: "What's New",
minimizable: false,
maximizable: false,
center: true,
icon: path.join(__dirname, 'views/assets/icons/app/icon.ico')
});
//Load HTML File
whatWindow.loadURL(url.format({
pathname: path.join(__dirname, 'whatWindow.html'),
protocol: 'file:',
slashes: true
}));
//Garbage collection
whatWindow.on('closed', function () {
whatWindow = null;
});
whatWindow.setMenu(null);
}
//Handle createExWindow
function createExWindow() {
//Create expire window
ExWindow = new BrowserWindow({
width: 630,
height: 540,
minWidth: 630,
minHeight: 540,
maxWidth: 630,
maxHeight: 540,
title: 'Licence Expired',
minimizable: false,
maximizable: false,
center: true,
alwaysOnTop: true,
icon: path.join(__dirname, 'views/assets/icons/app/icon.ico')
});
//Load HTML File
ExWindow.loadURL(url.format({
pathname: path.join(__dirname, 'exWindow.html'),
protocol: 'file:',
slashes: true
}));
//Garbage collection
ExWindow.on('closed', function () {
aboutWindow = null;
});
ExWindow.setMenu(null);
}
// Menu bar
const menuBar = [{
//File
label: ' F̲ile',
submenu: [
{
label: 'B̲ack Up Company',
}
, {
label: 'C̲reate Copy...',
}
, {
type: 'separator'
}
, {
label: 'U̲tilities',
}
, {
label: 'Sync',
}
, {
type: 'separator'
},
{
label: 'Q̲uit Bizplus',
accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q',
click() {
app.quit();
}
}
, ]
},
//View
{
label: 'V̲iew',
submenu: [
{
label: 'Keyboard Shortcuts',
accelerator: process.platform == 'darwin' ? 'Command+K' : 'Ctrl+K',
},
{
type: 'separator'
},
{
role: 'togglefullscreen'
}
, {
role: 'reload'
},
]
}
, //Tools
{
label: 'Add-ons',
submenu: [
{
label: 'Expense Calculator'
},
{
label: 'Sales Calculator'
},
{
label: 'Point of Sale (POS)'
}
, ]
},
//Help
{
role: 'help',
submenu: [{
label: 'B̲izplus Help',
accelerator: process.platform == 'darwin' ? 'F1' : 'F1',
},
{
label: 'Visit O̲nline Help',
click() {
require('electron').shell.openExternal('https://electronjs.org')
}
},
{
type: 'separator'
},
{
label: "✓ W̲hat's New",
click() {
createWhatWindow();
}
},
{
type: 'separator'
},
{
label: 'B̲izplus Learning Tutorials',
click() {
require('electron').shell.openExternal('https://electronjs.org')
}
},
{
label: 'F̲ind A Local Bizplus Expert',
click() {
require('electron').shell.openExternal('https://electronjs.org')
}
},
{
type: 'separator'
},
{
label: 'U̲pdate Bizplus...',
click() {
createExWindow();
}
},
{
type: 'separator'
},
{
label: 'About B̲izplus Enterprise 2019',
click() {
createAboutWindow();
}
},
{
type: 'separator'
}
, {
label: 'Bizplus H̲omepage',
click() {
require('electron').shell.openExternal('https://electronjs.org')
}
},
]
}
];