-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
120 lines (104 loc) · 2.57 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
const { menubar } = require("menubar");
var { ipcMain } = require("electron");
const util = require("util");
const { exec } = require("child_process");
const execProm = util.promisify(exec);
const Store = require("electron-store");
const AutoLaunch = require("auto-launch");
let path = require("path");
let { rootPath } = require("electron-root-path");
const root = rootPath;
let store = new Store();
require("update-electron-app")();
var coolm1Launcher = new AutoLaunch({
name: "coolm1",
path: "/Applications/coolm1.app",
isHidden: true,
});
const mb = menubar({
browserWindow: {
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
},
width: 600,
height: 300,
resizable: false,
preloadWindow: true,
show: false,
},
});
ipcMain.on("autostart", (event, arg) => {
if (arg) {
coolm1Launcher.enable();
} else {
coolm1Launcher.disable();
}
});
let showtemp = false;
ipcMain.on("showtemp", (event, arg) => {
if (arg) {
showtemp = true;
} else {
showtemp = false;
}
});
ipcMain.handle("getStoreValue", (event, key) => {
return store.get(key);
});
ipcMain.handle("hasStoreValue", (event, key) => {
return store.has(key);
});
mb.on("show", () => {
mb.window.webContents.send("visibility", true);
});
mb.on("after-hide", () => {
mb.window.webContents.send("visibility", false);
mb.app.dock.hide();
});
let firstShow = true;
mb.on("ready", () => {
const { execPath } = require("./app/binaries");
//show for a bit so we load sensors
mb.showWindow();
showtemp = store.get("showtemp");
ipcMain.on("settemp", (event, args) => {
if (firstShow) {
mb.hideWindow();
firstShow = false;
}
if (showtemp) mb.tray.setTitle(args);
else mb.tray.setTitle("");
});
ipcMain.on("index", (event, arg) => {
switch (arg) {
case "getNames":
run_shell_command(execPath + " n").then((res) => {
mb.window.webContents.send("names", res.stdout);
});
break;
case "getValues":
run_shell_command(execPath + " v").then((res) => {
mb.window.webContents.send("values", res.stdout);
});
break;
case "showalltoggle":
if (mb.window.getSize()[1] == 800) mb.window.setSize(600, 300);
else mb.window.setSize(600, 800);
break;
case "close":
mb.app.exit(0);
break;
}
});
});
async function run_shell_command(command) {
let result;
try {
result = await execProm(command);
} catch (ex) {
result = ex;
}
if (Error[Symbol.hasInstance](result)) return;
return result;
}