Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
99 lines (82 loc) · 2.19 KB
/
Copy pathmain.js
File metadata and controls
99 lines (82 loc) · 2.19 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
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
const {app, BrowserWindow, autoUpdater, ipcMain, Tray, nativeImage, globalShortcut, remote, clipboard, systemPreferences, Menu} = require('electron');
const path = require('path');
require('electron-debug')();
let tray = undefined
let window = undefined
let iconSize = {
width: 15,
height: 15
}
// Don't show the app in the doc
//app.dock.hide()
app.on('ready', () => {
createTray()
createWindow()
Menu.setApplicationMenu(menu)
})
const createTray = () => {
const iconPath = systemPreferences.isDarkMode() ? path.join(__dirname, 'light.png') : path.join(__dirname, 'dark.png');
let trayIcon = nativeImage.createFromPath(iconPath);
trayIcon = trayIcon.resize(iconSize);
tray = new Tray(trayIcon)
tray.on('click', function (event) {
toggleWindow()
});
tray.setIgnoreDoubleClickEvents(true)
}
const getWindowPosition = () => {
const windowBounds = window.getBounds();
const trayBounds = tray.getBounds();
const x = Math.round(trayBounds.x + (trayBounds.width / 2) - (windowBounds.width / 2));
const y = Math.round(trayBounds.y + trayBounds.height);
return {x: x, y: y};
}
const createWindow = () => {
window = new BrowserWindow({
width: 184,
height: 184,
show: false,
frame: false,
fullscreenable: false,
resizable: false,
transparent: true,
webPreferences: {
backgroundThrottling: false
},
})
window.loadURL(`file://${path.join(__dirname, 'index.html')}`)
// Hide the window when it loses focus
window.on('blur', () => {
if (!window.webContents.isDevToolsOpened()) {
window.hide()
}
})
}
const createTemplateMenu = [
{
label: app.getName(),
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'quit' }
]
}
]
const menu = Menu.buildFromTemplate(createTemplateMenu)
const toggleWindow = () => {
window.isVisible() ? window.hide() : showWindow();
}
const showWindow = () => {
const position = getWindowPosition();
window.setPosition(position.x, position.y, false);
window.show();
}
//app.dock.hide();
ipcMain.on('show-window', () => {
showWindow()
})
ipcMain.on('close-main-window', function () {
app.quit();
});