-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (113 loc) · 3.64 KB
/
index.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
const { app, BrowserWindow, ipcMain, globalShortcut } = require('electron');
const { write, read } = require('./src/settings.js');
const pathjs = require('path');
const { readFromFile, manualLookup, refreshPlayers } = require('./src/readPlayers.js');
const { paths } = require('./data.json');
const windowStateKeeper = require('electron-window-state');
const { autoUpdater } = require('electron-updater');
try {
require('electron-reloader')(module);
} catch {}
app.on('ready', () => {
autoUpdater.checkForUpdatesAndNotify();
// Load the previous state with fallback to defaults
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 500
});
// init the window and set it to load from index.html
const win = new BrowserWindow({
show: false,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 800,
minHeight: 400,
frame: false,
transparent: true,
resizable: true,
show: false,
// backgroundColor: '#00ffffff',
webPreferences: {
nodeIntegration: true,
preload: pathjs.join(__dirname, 'src/preload.js')
}
});
// this will let electron window state manage the window for us
mainWindowState.manage(win);
win.loadFile('index.html');
win.removeMenu();
win.once('ready-to-show', () => {
win.show();
});
// shortcuts - f5 to refresh page and ctrl+shift+i to show dev tools
globalShortcut.register('f5', () => {
win.reload();
});
globalShortcut.register('CommandOrControl+Shift+I', () => {
win.webContents.openDevTools();
});
const clientSelect = (client) => {
write('path', `${app.getPath('home').replace(/\\/g, '\/') + paths[`${client}-${process.platform}`] }/logs/latest.log`);
write('client', client);
};
if(!read('client')) {
clientSelect('lunar');
}
if(!read('autowho')) {
write('autowho', true);
}
if(!read('mode')) {
write('mode', 'overall');
}
if(!read('theme-darkmode')) {
write('theme-darkmode', false);
}
if(!read('statColor')) {
write('statColor', false);
}
win.webContents.once('dom-ready', () => {
win.webContents.send('initSettings', {
path: read('path'),
client: read('client'),
autowho: read('autowho'),
mode: read('mode'),
darkmode: read('theme-darkmode'),
statColor: read('statColor')
});
// start reading from the file immediately
readFromFile(read('path'), win, read('key'));
});
// listen for settings changes
ipcMain.on('updateSettings', (e, data) => {
switch(data.type) {
case 'client':
clientSelect(data.client);
win.webContents.send('noticeText', 'Please restart the overlay!');
break;
case 'autowho':
write('autowho', data.autowho);
break;
case 'modeSelect':
write('mode', data.modeSelect.mode);
refreshPlayers(data.modeSelect.players, win, read('key'));
break;
case 'darkmode':
write('theme-darkmode', data.darkmode);
break;
case 'statColor':
write('statColor', data.statColor);
break;
}
});
ipcMain.on('manualLookup', (e, data) => {
manualLookup(data, win, read('key'));
});
ipcMain.on('exit', (e, data) => {
win.close();
});
});
app.on('window-all-closed', () => {
app.quit();
});