-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
83 lines (72 loc) · 1.99 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
const { app, BrowserWindow, ipcMain, globalShortcut } = require('electron')
require('electron-reload')(__dirname);
const speedTest = require('./speedtest');
let dspeed = 0;
// ==== Global IPC Handlers ==== //
ipcMain.on('console-log', (event, arg) => {
console.log(arg);
});
// ==== Functions to create the windows ==== //
function openDownUpFrame() {
const downUpFrame = new BrowserWindow({
width: 210,
height: 104,
frame: false,
transparent: true,
x: 1710,
y: 2,
skipTaskbar: false,
// resizable: false,
webPreferences: {
nodeIntegration: true
},
});
downUpFrame.loadFile('downUpFrame/downUpFrame.html');
console.log('download speed: ', dspeed);
return downUpFrame;
}
function openTrafficUI() {
const bandwidthAnalyzer = new BrowserWindow({
height: 200,
width: 210,
x: 1710,
y: 106,
frame: false,
// transparent: true,
webPreferences: {
nodeIntegration: true
}
})
// bandwidthAnalyzer.setMenu(null);
bandwidthAnalyzer.loadFile('trafficUI/trafficUI.html');
return bandwidthAnalyzer;
}
app.whenReady().then(() => {
//Create Windows
const downUpFrame = openDownUpFrame();
const trafficUI = openTrafficUI();
//Enable Devtools
globalShortcut.register("CmdOrCtrl+F12", () => {
trafficUI.isFocused() && trafficUI.webContents.toggleDevTools();
downUpFrame.isFocused() && downUpFrame.webContents.toggleDevTools();
});
//Listener for Userinput regarding max speed values arg: [type: download/upload, value: number]
ipcMain.on('max-change', (event, arg) => {
console.log(arg);
downUpFrame.webContents.send('max-change', arg);
})
ipcMain.on('speed-test', async(event, arg) => {
dspeed = await speedTest.testDownloadSpeed();
downUpFrame.webContents.send('speed-test', dspeed);
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})