Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
68 lines (57 loc) · 1.4 KB
/
Copy pathmain.js
File metadata and controls
68 lines (57 loc) · 1.4 KB
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
const { app, BrowserWindow, Tray, Menu, screen, ipcMain, nativeImage } = require('electron');
const path = require('path');
const myServer = require('./server.js');
let win;
let tray;
app.on('ready', () => {
const { width } = screen.getPrimaryDisplay().workAreaSize;
win = new BrowserWindow({
width: 320,
height: 150,
x: width - 340,
y: 20,
frame: false,
alwaysOnTop: true,
transparent: true,
resizable: false,
skipTaskbar: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
win.loadFile('index.html');
win.setAlwaysOnTop(true, 'screen-saver');
myServer.startServer(win);
ipcMain.on('control', (event, data) => {
myServer.addElectronCommand(data);
});
const iconPath = path.join(__dirname, 'icon.ico');
const trayIcon = nativeImage.createFromPath(iconPath);
tray = new Tray(trayIcon);
const contextMenu = Menu.buildFromTemplate([
{
label: 'Toggle',
click: () => {
if (win.isVisible()) win.hide();
else win.show();
}
},
{
label: 'Settings',
click: () => {
win.webContents.send('toggle-settings');
}
},
{
label: 'Close',
click: () => app.quit()
}
]);
tray.setToolTip('YouTube Overlay');
tray.setContextMenu(contextMenu);
tray.on('click', () => {
if (win.isVisible()) win.hide();
else win.show();
});
});