-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
84 lines (73 loc) · 2.15 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
const { app, Menu, Tray, BrowserWindow, globalShortcut } = require('electron')
const isMacOS = (process.platform === "darwin")
let tray = null
function createWindow () {
const win = new BrowserWindow({
width: 900,
height: 600,
frame: isMacOS,
titleBarStyle: 'hidden',
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false
}
})
win.loadFile('index.html')
}
function manageShortcuts() {
const zoomInRegister = globalShortcut.register('CommandOrControl+=', () => {
let focusedWindow = BrowserWindow.getFocusedWindow()
if(focusedWindow)
{
let zoomLevel = focusedWindow.webContents.getZoomLevel()
if (zoomLevel < 2)
BrowserWindow.getFocusedWindow().webContents.setZoomLevel(zoomLevel + 0.1)
}
})
const zoomOutRegister = globalShortcut.register('CommandOrControl+-', () => {
let focusedWindow = BrowserWindow.getFocusedWindow()
if(focusedWindow)
{
let zoomLevel = focusedWindow.webContents.getZoomLevel()
if (zoomLevel > -0.5)
BrowserWindow.getFocusedWindow().webContents.setZoomLevel(zoomLevel - 0.1)
}
})
if (!zoomInRegister || !zoomOutRegister) {
console.log('registration failed')
}
globalShortcut.register('CommandOrControl+Shift+=',()=>{});
// for debuging purposes
// globalShortcut.register('CommandOrControl+W',()=>{});
}
function initTray() {
if (isMacOS) return; // building Tray breaks builds on MacOS
tray = new Tray('images/tray-icon.png')
const contextMenu = Menu.buildFromTemplate([
{label: "Show", type: "normal", click: () => {
BrowserWindow.getAllWindows().forEach((e) => e.show())
}},
{label: "Quit", type: "normal", role: "quit"}
])
tray.setToolTip("RAINO")
tray.setContextMenu(contextMenu)
tray.on('double-click', () => {
BrowserWindow.getAllWindows().forEach((e) => e.show())
})
}
app.whenReady().then(() => {
initTray()
createWindow()
manageShortcuts()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (!isMacOS) {
app.quit()
}
})