-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
94 lines (80 loc) · 1.98 KB
/
app.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
const { app, BrowserWindow, Menu, Tray } = require('electron')
const path = require('path')
const windowStateKeeper = require('electron-window-state')
const { DisableMinimize } = require('electron-disable-minimize')
const AutoLaunch = require('auto-launch')
let win, tray, mainWindowState
const createWindow = () => {
mainWindowState = windowStateKeeper()
win = new BrowserWindow({
maxWidth: 400,
minWidth: 150,
maxHeight: 155,
minHeight: 40,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
icon: path.join(__dirname, './src/img/clock.ico'),
frame: false,
transparent: true,
skipTaskbar: true,
minimizable: false,
fullscreenable: false,
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
})
mainWindowState.manage(win)
const handle = win.getNativeWindowHandle()
DisableMinimize(handle)
win.loadFile('./src/index.html')
win.on('closed', () => {
app.quit()
})
}
const createTray = () => {
const contextMenu = [
{
label: 'Show',
click: () => {
win.focus()
},
},
{
label: 'Quit',
click: () => {
win.close()
},
},
]
const menu = Menu.buildFromTemplate(contextMenu)
tray = new Tray(path.join(__dirname, './src/img/clock.ico'))
tray.setContextMenu(menu)
tray.setToolTip('Just Clock')
tray.on('click', () => {
win.focus()
})
}
app.whenReady().then(() => {
createWindow()
createTray()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('ready', () => {
let autoLaunch = new AutoLaunch({
name: 'Just Clock',
path: app.getPath('exe'),
})
autoLaunch.isEnabled().then((isEnabled) => {
if (!isEnabled) autoLaunch.enable()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})