-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
265 lines (230 loc) · 6.14 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
const { autoUpdater } = require('electron-updater');
const { SSL_OP_EPHEMERAL_RSA } = require('constants');
const { app, BrowserWindow, ipcMain } = require('electron');
const {TitlebarRespect} = require('electron-titlebar-respect')
const glasstron = require('glasstron-clarity');
const electron = require('electron');
electron.app.commandLine.appendSwitch("enable-transparent-visuals");
TitlebarRespect({})
// is dev
var isDev = require('isdev')
// Notify
const { Notification } = require('electron')
// Start the libaries
require('./lib/rpc.js');
console.log("RPC lib init.");
// Prepare database
const Store = require('electron-store');
const config = new Store();
console.log("Software ready for start!");
require('./lib/core.js');
function die() {
console.log("Unregistering variables...");
config.set('newDiff', "unloaded")
config.set('oldDiff', "unloaded")
mainWindow.removeAllListeners('closed');
strm.removeAllListeners('closed');
strm.close()
app.quit()
}
function strmex() {
console.log("Unregistering variables...");
config.set('newDiff', "unloaded")
config.set('oldDiff', "unloaded")
app.removeAllListeners('window-all-closed');
mainWindow.removeAllListeners('closed');
mainWindow.close()
app.quit()
}
function neterr() {
const notification = {
title: 'StreamBop',
body: 'No valid network connection! Please reconnect!'
}
new Notification(notification).show()
}
// wait function
function wait(ms)
{
var d = new Date();
var d2 = null;
do { d2 = new Date(); }
while(d2-d < ms);
}
// Start the libaries
require('./lib/rpc.js');
console.log("RPC lib init.");
// Loading screen
/// create a global var, wich will keep a reference to out loadingScreen window
let loadingScreen;
const createLoadingScreen = () => {
loadingScreen = new BrowserWindow(
Object.assign({
width: 800,
height: 800,
alwaysOnTop: true,
frame: false,
fullscreen: false,
show: false
})
);
loadingScreen.setResizable(false);
loadingScreen.loadFile('./src/pages/splash.html');
loadingScreen.on('closed', () => (loadingScreen = null));
loadingScreen.hide();
loadingScreen.show()
setTimeout(() => {
console.log("Main WIN.REQ has been sent now.")
createWindow()
}, 2500);
};
console.log("Loading screen ready.");
// Start the main program
let mainWindow;
function createWindow() {
mainWindow = new glasstron.BrowserWindow({
width: 900,
height: 700,
show: false,
fullscreen: false,
frame: global.frame,
titleBarStyle: global.titleBarStyle,
modal: true,
blur: true,
blurType: global.blurType,
icon: 'snailfm.ico',
webPreferences: {
nodeIntegration: true,
devTools: isDev,
nativeWindowOpen: true,
backgroundThrottling: false,
contextIsolation: false
},
});
mainWindow.setResizable(false)
console.log("Window configured, starting")
mainWindow.setMenuBarVisibility(false)
mainWindow.loadFile('index.html')
mainWindow.on('maximize', () => mainWindow.unmaximize())
wait(6000)
console.log("Loaded sucess.")
loadingScreen.close()
mainWindow.on('closed', () => (
die()
));
// Don't tell me my code is messy, I know it is.
if(isDev) {
console.log("In Development!")
} else {
console.log("Not in Development!")
}
// This is the final part of the StreamBop boot-up.
var internetAvailable = require("internet-available");
// Set a timeout and a limit of attempts to check for connection
internetAvailable({
timeout: 2000,
retries: 3,
}).then(function(){
console.log("Internet available");
}).catch(function(){
console.log("No internet");
neterr()
mainWindow.loadFile('./src/pages/nonet.html');
});
mainWindow.show();
console.log("Ok! Window init, let's check for updates...")
autoUpdater.checkForUpdatesAndNotify();
console.log("Checking for updates... Waiting for a reply back...");
}
// After Preload
console.log("Main screen ready.");
// strm
/// create a global var, wich will keep a reference to out loadingScreen window
let strm;
const createNewstrm = () => {
strm = new BrowserWindow(
Object.assign({
width: 800,
setResizable: false,
isClosable: false,
minimizable: false,
height: 600,
alwaysOnTop: false,
frame: true,
fullscreen: false,
show: false,
frame: global.frame,
titleBarStyle: global.titleBarStyle,
trafficLightPosition: { x: 24, y: 25 },
webPreferences: {
nodeIntegration: true,
devTools: isDev,
nativeWindowOpen: true,
backgroundThrottling: false,
contextIsolation: false
},
})
);
strm.setResizable(false);
strm.loadFile('./src/pages/strm.html');
strm.isMovable(false)
strm.setMenuBarVisibility(false)
strm.on('closed', () => (strmex()));
};
app.on('ready', () => {
console.log("strm red");
config.set("on", false);
createNewstrm();
})
app.on('ready', () => {
createLoadingScreen();
console.log("Send check for updates signal...");
console.log("Alright, lets go!");
})
app.on('window-all-closed', function () {
die()
if (process.platform !== 'darwin') {
die()
app.quit();
}
});
ipcMain.on('app_version', (event) => {
event.sender.send('app_version', { version: app.getVersion() });
});
autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update_available');
});
autoUpdater.on('update-downloaded', () => {
mainWindow.webContents.send('update_downloaded');
});
ipcMain.on('relaunch', () => {
mainWindow.close()
});
ipcMain.on('restart_app', () => {
autoUpdater.quitAndInstall();
});
ipcMain.on('strm', () => {
strm.show()
});
ipcMain.on('strm.hide', () => {
strm.hide()
});
ipcMain.on('strm.start', () => {
console.log("StreamBop viewer activated")
config.set("on", true);
});
ipcMain.on('strm.stop', () => {
console.log("StreamBop viewer off")
config.set("on", false);
});
ipcMain.on('strm.setup', () => {
console.log("StreamBop viewer setup mode")
config.set("on", false);
config.set("setupan", true);
});
ipcMain.on('strm.reload', () => {
strm.reload();
});
ipcMain.on('minimize', () => {mainWindow.minimize()})
ipcMain.on('restore', () => {mainWindow.restore()})
ipcMain.on('close', () => {mainWindow.close()})