This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (83 loc) · 3.18 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
const {app, BrowserWindow, Tray, process, Menu, globalShortcut, shell} = require('electron');
let mainWindow, tray;
app.on('ready', () => {
const screen = require('electron').screen;
mainWindow = new BrowserWindow({
height: 480,
width: 275,
frame: false,
resizable: false,
transparent: true
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Hide window in taskbar
mainWindow.setSkipTaskbar(true);
mainWindow.setAlwaysOnTop(true);
globalShortcut.register('CommandOrControl+`', () => {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
var display = screen.getPrimaryDisplay();
// Position at top-right
mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);
mainWindow.setAlwaysOnTop(true);
}
});
tray = new Tray(__dirname + '/tray.png');
tray.setToolTip('Twitch overlay activated. Press Ctrl + ` to show.');
const trayContextMenu = Menu.buildFromTemplate([
{label: `TwitchOverlay v${app.getVersion()}`, enabled: false},
{type: "separator"},
{label: "Website", click: () => {shell.openExternal('https://overlay.twitchbot.io')}},
{label: "Source code", click: () => {shell.openExternal('https://github.com/devakira/twitchoverlay')}},
{type: "separator"},
{label: "Toggle Chat", click: () => {
mainWindow.webContents.executeJavaScript(`renderer.toggleChat()`);
}},
{label: "Settings", click: () => {mainWindow.loadURL('file://' + __dirname + '/settings.html');}},
{type: "separator"},
{label: "Quit Application", role: "quit"}
]);
tray.setContextMenu(trayContextMenu);
const trayBounds = tray.getBounds();
var display = screen.getPrimaryDisplay();
// Position at top-right
mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);
tray.on('click', () => {
mainWindow.show();
var display = screen.getPrimaryDisplay();
// Position at top-right
mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);
mainWindow.setAlwaysOnTop(true);
});
mainWindow.on('blur', () => {
mainWindow.setAlwaysOnTop(true);
});
mainWindow.on('closed', () => {
app.quit();
});
mainWindow.on('resize', () => {
var display = screen.getPrimaryDisplay();
// Position at top-right
mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);
mainWindow.setAlwaysOnTop(true);
});
mainWindow.on('enter-html-full-screen', () => {
mainWindow.setPosition(0, 0);
});
mainWindow.on('leave-html-full-screen', () => {
var display = screen.getPrimaryDisplay();
// Position at top-right
mainWindow.setPosition(display.bounds.width - mainWindow.getSize()[0], 0);
});
mainWindow.webContents.on('new-window', function(event, url){
event.preventDefault();
shell.openExternal(url);
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});