-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
80 lines (72 loc) · 2 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
const {app, Tray, Menu, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
const {Database} = require('./data/Database')
const database = new Database({filePath: path.join(__dirname,'cred.json')})
const iconpath = path.join(__dirname, 'ninja.png')
let appIcon = null
let win = null
let loginWin = null
let mainWindow = null
app.on('ready', () => {
win = new BrowserWindow({show: false})
appIcon = new Tray(iconpath)
var contextMenu = Menu.buildFromTemplate([
{
label: 'Exit',
type: 'normal',
click: () => {
process.exit()
}
},
{
label: 'Login',
type: 'normal',
click: () => {
createLoginWindow()
}
}
])
appIcon.setContextMenu(contextMenu)
appIcon.on('click', () => {
mainWindow = new BrowserWindow({
show: true,
webPreferences: {
nodeIntegration: true
},
width: 400,
height: 500,
resizable: false,
autoHideMenuBar: true,
frame: false
})
mainWindow.loadFile(path.join(__dirname, 'index.html'))
const customMenu = Menu.buildFromTemplate([
{
label: 'Exit',
click: () => {
process.exit(0)
}
}
])
Menu.setApplicationMenu(customMenu)
})
})
app.allowRendererProcessReuse = true
function createLoginWindow() {
loginWin = new BrowserWindow({
show: true,
webPreferences: {
nodeIntegration: true
},
width: 500,
height: 200,
resizable: false,
frame: false
})
loginWin.loadFile(path.join(__dirname, 'login.html'))
}
ipcMain.on('save-cred', async (event, {uid, password}) => {
await database.saveCred({uid: uid, password: password})
loginWin.close()
event.sender.send('update-attendance', uid)
})