This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
119 lines (100 loc) · 2.61 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
const {
app,
BrowserWindow,
globalShortcut,
clipboard,
ipcMain,
Notification,
} = require("electron");
const axios = require("axios");
const { autoUpdater } = require("electron-updater");
const fs = require("fs");
const isDev = require("electron-is-dev");
var config_valid = true;
async function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 650,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
autoHideMenuBar: true,
});
autoUpdater.on("checking-for-update", () => {
new Notification({
title: "Update Check",
body: "Checking for updates...",
}).show();
});
autoUpdater.on("update-available", (info) => {
new Notification({
title: "Update Check",
body: "Update available: " + info.version,
}).show();
app.setBadgeCount(1);
});
autoUpdater.on("update-not-available", () => {
new Notification({
title: "Update Check",
body: "No Update available",
}).show();
});
autoUpdater.on("download-progress", (data) => {
win.setProgressBar(data.percent / 100.0);
});
autoUpdater.on("update-downloaded", (data) => {
new Notification({
title: "Update Check",
body: "Installing Update",
}).show();
autoUpdater.quitAndInstall();
});
autoUpdater.on("error", (error) => {
new Notification({
title: "Update Check",
body: "ERR: " + error,
}).show();
});
// ##### CONFIG CHECK #####
const configExists = fs.existsSync(
`C:\\users\\${require("os").userInfo().username}\\.ics-placetel-config.json`
);
// ##### END CONFIG CHECK #####
if (!configExists) {
win.loadFile("error.html");
config_valid = false;
return;
}
const config = require(`C:\\users\\${
require("os").userInfo().username
}\\.ics-placetel-config.json`);
if (!config.shortcut_key) {
win.loadFile("error.html");
config_valid = false;
}
if (
config.placetel_data.api_token === "" ||
config.placetel_data.si_id === ""
) {
win.loadFile("error.html");
config_valid = false;
}
if (config_valid) win.loadFile("index.html");
return { win, config };
}
app.whenReady().then(async () => {
const window = await createWindow();
app.setAppUserModelId("ICS Placetel Application");
if (config_valid) {
if (window.config.shortcut_key) {
globalShortcut.register(window.config.shortcut_key, () => {
window.win.webContents.send("dialkey");
});
if (!isDev) autoUpdater.checkForUpdates();
}
}
});
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
});