-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (55 loc) · 1.64 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
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const nativeImage = electron.nativeImage
const Tray = electron.Tray
const Menu = electron.Menu
const system = electron.systemPreferences
const AutoLaunch = require('auto-launch')
var launch, trayMenu
exports.onApp = app => {
if (process.platform == 'darwin') {
app.dock.hide()
tray()
launch()
}
}
function tray() {
var image = nativeImage.createFromPath(__dirname + (system.isDarkMode() ? '/static/tray.png' : '/static/tray-black.png'))
image.setTemplateImage(true)
var tray = new Tray(image)
trayMenu = Menu.buildFromTemplate([
{
label: 'Open at Login',
type: 'checkbox',
checked: app.getLoginItemSettings().openAtLogin ? true : false,
click: launchToggle,
},
{ type: 'separator' },
{ label: 'Quit', role: 'quit' },
])
tray.on('click', () => {
if (app.getWindows().size === 0) {
app.createWindow()
} else {
app.getLastFocusedWindow().focus()
// app.getWindows().forEach(_win => {
// _win.show()
// })
}
})
tray.on('right-click', () => {
tray.popUpContextMenu(trayMenu)
})
tray.setToolTip('Hyper')
}
function launch() {
let appPath = app.getPath('exe').replace(/\.app\/Content.*/, '.app')
launch = new AutoLaunch({ name: 'Hyper', path: appPath, isHidden: false })
}
function launchToggle() {
launch.isEnabled().then(enabled => {
if (!enabled) launch.enable()
else launch.disable()
})
}