-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
111 lines (98 loc) · 2.41 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict'
const menubar = require('menubar')
const electron = require('electron')
const AutoLaunch = require('auto-launch')
const ipcMain = require('electron').ipcMain
const storage = require('electron-json-storage')
const Menu = electron.Menu
const BrowserWindow = electron.BrowserWindow
const mb = menubar({icon: '' + __dirname + '/IconTemplate.png'})
mb.setOption('preload-window', true)
mb.setOption('height', 600)
mb.setOption('width', 400)
let aboutWindow
let appLauncher = new AutoLaunch({
name: 'canvasbar'
})
const contextMenu = Menu.buildFromTemplate([
{
label: 'About Canvasbar',
click: () => {
openAbout()
}
},
{
label: 'Launch on Login',
type: 'checkbox',
checked: false,
click: (item) => {
appLauncher.isEnabled().then((enabled) => {
if (enabled) {
return appLauncher.disable().then(() => {
item.checked = false
})
} else {
return appLauncher.enable().then(() => {
item.checked = true
})
}
})
}
},
{
label: 'Show devtools',
click: () => {
mb.window.openDevTools()
}
},
{
label: 'Quit Canvasbar',
click: () => {
mb.app.quit()
}
}
])
appLauncher.isEnabled().then((enabled) => {
contextMenu.items[1].checked = enabled
})
const openAbout = () => {
aboutWindow = new BrowserWindow({width: 400, height: 320})
aboutWindow.loadURL('file://' + __dirname + '/about.html')
aboutWindow.on('closed', () => {
aboutWindow = null
})
}
mb.on('ready', () => {
mb.tray.on('right-click', () => {
mb.tray.popUpContextMenu(contextMenu)
})
})
mb.on('after-create-window', () => {
storage.has('schoolUrl', (error, hasKey) => {
if (hasKey) {
storage.get('schoolUrl', (error, data) => {
mb.window.loadURL('file://' + __dirname + '/index.html#' + data)
})
} else {
mb.window.loadURL('file://' + __dirname + '/index.html#')
}
})
// mb.window.openDevTools()
})
mb.on('show', () => {
storage.has('schoolUrl', (error, hasKey) => {
if (hasKey) {
storage.get('schoolUrl', (error, data) => {
mb.window.loadURL('file://' + __dirname + '/index.html#' + data)
})
} else {
mb.window.loadURL('file://' + __dirname + '/index.html#')
}
})
})
ipcMain.on('schoolUrl', (e, data) => {
storage.set('schoolUrl', data)
})
ipcMain.on('log', (e, data) => {
// console.log(data)
})