-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (62 loc) · 1.88 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
// Requires and consts
const electron = require("electron");
const app = electron.app;
const {ipcMain} = electron.app;
const {Menu} = require("electron");
const BrowserWindow = electron.BrowserWindow;
const path = require("path");
const url = require("url");
const fs = require("fs");
let mainWindow;
require("./js/join-leave.js");
const uxinstall = require("./js/ux-install.js");
// create main app window
function spawnAppWindow(item) {
mainWindow = new BrowserWindow({width: 1200, height: 800});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, item+".html"),
protocol: "file:",
slashes: true
}));
mainWindow.openDevTools();
uxinstall.define(mainWindow);
console.log("Opening "+item);
// on close event
mainWindow.on("closed", function () {
mainWindow = null;
});
}
// handle app events
app.on("ready", () => {
// delete menus
Menu.setApplicationMenu(null);
// check if app config is set
var configpath = app.getPath("appData")+"/project-sharon-client/management.json";
console.log("Loading config "+configpath+"...");
fs.access(configpath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
// If the file exists, open main app
if(err === null){
spawnAppWindow("index");
} else {
spawnAppWindow("onboarding");
}
});
// events to occur when Electron is ready
});
app.on("all-windows-closed", () => {
// events to occur when all the app windows have closed
});
app.on("activate", () => {
// events to occur when application is launched when closed
if(mainWindow === null) {
spawnAppWindow();
}
});
app.on("will-quit", (e) => {
// prevent app from exiting so it stays running in background
console.log("Still running in the background.");
e.preventDefault();
});
app.on("quit", (e) => {
// on app exit
});