-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
120 lines (93 loc) · 3.54 KB
/
app.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
const { app, BrowserWindow, Menu, Tray } = require('electron'),
{ autoUpdater } = require('electron-updater'),
path = require('path');
// require('electron-reload')(__dirname);
global.tray = null;
global.tray_context_menu = null;
global.__dirname = __dirname;
global.dirname = path.dirname(__dirname);
let win = null;
// --------------------------------------------------------------------------------------------------------------------------------------
// WINDOW INIT FUNCTION -----------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------------
function init() {
win = new BrowserWindow({
minWidth: 600,
width: 800,
minHeight: 800,
height: 800,
frame: false,
icon: path.join(__dirname, 'public/favicon.ico')
});
win.setTitle('MarlX-Client');
win.loadFile(path.join(__dirname, 'public/index.html'));
// win.webContents.openDevTools();
global.tray = new Tray(path.join(__dirname, 'public/favicon.ico'));
global.tray_context_menu = Menu.buildFromTemplate([
{ label: 'Quit', type: 'normal', role: 'quit' },
]);
global.tray.setToolTip('MarlX-Client');
global.tray.setContextMenu(global.tray_context_menu);
global.tray.on('click', () => {
win.center();
if (win.isVisible())
win.hide();
else
win.show();
});
win.on('closed', () => {
tray.destroy();
win = null;
});
// win.on('blur', () => {
// win.hide();
// });
}
// --------------------------------------------------------------------------------------------------------------------------------------
// APP EVENTS ---------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------------
var secInst = app.makeSingleInstance((cmdl, wd) => {
if (win) {
if (win.isMinimized())
win.restore();
win.focus();
}
});
if (secInst) {
app.quit();
return;
}
app.on('ready', init);
app.on('window-all-closed', () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on('activate', () => {
if (win === null)
init();
});
// --------------------------------------------------------------------------------------------------------------------------------------
// AUTO-UPDATER FUNCTIONS ---------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------------
function messageRenderer(chang, ...msg) {
if (win)
win.webContents.send(chan, ...msg);
}
autoUpdater.on('checking-for-update', () => {
messageRenderer('auto-updater', 'checking-for-updates');
});
autoUpdater.on('update-available', () => {
messageRenderer('update-available', 'auto-updater');
});
autoUpdater.on('update-not-available', () => {
messageRenderer('update-not-available', 'auto-updater');
});
autoUpdater.on('error', () => {
messageRenderer('error', 'auto-updater');
});
autoUpdater.on('download-progress', prog => {
});
autoUpdater.on('update-downloaded', () => {
messageRenderer('update-downloaded', 'auto-updater');
});