This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhubMain.js
190 lines (175 loc) · 5.19 KB
/
hubMain.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
const electron = require('electron');
const {
app,
BrowserWindow,
Menu,
MenuItem,
ipcMain,
webContents,
globalShortcut,
Tray,
nativeImage,
shell
} = electron;
const remote = require('@electron/remote/main').initialize()
const url = require('url');
const path = require('path');
//const isDev = require('electron-is-dev');
const isDev = true;
const {
autoUpdater
} = require("electron-updater");
const fs = require('fs');
// only here to initiate globals
let hubWindow;
let trayIcon;
const menu = new Menu();
// the image globals
let imageTray = nativeImage.createFromPath('./SvgIcons/TrayIcon.png');
let imageIcon = nativeImage.createFromPath('./SvgIcons/AppIcon.png');
//just the startup script, nothing besides that should go in here.
app.on('ready', openHub);
function openHub() {
//make the tray icon
trayIcon = new Tray(imageTray.resize({
width: 16,
height: 16
}));
trayIcon.setContextMenu(contextMenu);
trayIcon.addListener("click", function () {
hubWindow.show();
})
hubWindow = new BrowserWindow({
width: 778,
minWidth: 778,
icon: imageIcon.resize({
width: 32,
height: 32
}),
show: false,
movable: true,
frame: false,
closable: true,
backgroundColor: '#FFF',
worldSafeExecuteJavaScript: false,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
enableRemoteModule: true,
experimentalFeatures: true
}
});
hubWindow.loadURL(url.format({
pathname: path.join(__dirname, 'hubWindow.html'),
protocol: 'file:',
slashes: true
}));
hubWindow.on('close', function (event) {
app.quit();
//event.preventDefault();
//hubWindow.hide();
});
hubWindow.on("ready-to-show", function () {
hubWindow.setMenu(menu)
//openLoginWindow();
hubWindow.show();
});
//The part of the app that checks if in devlopment or not
if (!isDev) {
//check to see if settings exist
var filePath = './settings.json';
if (!fs.existsSync(filePath)) {
//make that file
var settings = {};
fs.writeFile(filePath, JSON.stringify(settings, null, 1), (err) => {
if (err) throw err;
});
}
//running production
autoUpdater.autoDownload = false;
var updaterSystem = setInterval(() => {
autoUpdater.checkForUpdates();
}, 60000);
//changes the status text in the update button
autoUpdater.on("checking-for-update", () => {
hubWindow.webContents.send('update_status_changed', "searching for updates");
});
autoUpdater.on("update-not-available", () => {
hubWindow.webContents.send('update_status_changed', "no updates found");
});
autoUpdater.on("update-available", () => {
hubWindow.webContents.send('update_status_changed', "update found, click to download");
});
autoUpdater.on('download-progress', (progressObj) => {
clearInterval(updaterSystem);
hubWindow.webContents.send('update_status_changed', "update found, downloading " + progressObj.percent.toFixed(1) + "%");
});
//changes text and changes function of button
autoUpdater.on("update-downloaded", () => {
hubWindow.webContents.send('update_status_changed', "update downloaded, click to install");
});
//response that does install update
ipcMain.on('quit-and-install', (event, arg) => {
event.reply('quit-and-install-reply', "installing update now ...")
autoUpdater.quitAndInstall();
});
//response that does install update
ipcMain.on('download-update', (event, arg) => {
autoUpdater.downloadUpdate(); //downloads the update
});
} else {
//shortcuts only in dev mode
globalShortcut.register('f2', function () {
hubWindow.toggleDevTools();
});
}
}
//menu for the tray
var contextMenu = Menu.buildFromTemplate([{
icon: imageIcon.resize({
width: 16,
height: 16
}),
label: 'LiquidPixel Hub ' + app.getVersion(),
enabled: false
},
{
type: 'separator'
},
{
label: 'Check for Updates...',
click: function () {
autoUpdater.checkForUpdates();
}
},
{
label: 'Email the Programmer',
click: function () {
shell.openExternal("mailto:[email protected]?subject=LPC_HELPDESK&body=");
}
},
{
label: 'Getting started',
click: function () {
shell.openExternal("https://www.youtube.com/watch?v=X7A7kmjybwA")
}
},
{
type: 'separator'
},
{
label: 'Restart',
click: function () {
hubWindow.destroy();
app.relaunch();
}
},
{
label: 'Quit LpcHub',
click: function () {
//app.isQuiting = true;
hubWindow.destroy();
app.quit();
}
},
]);