forked from Sustaingineeringubc/Monitoring-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainWindow.js
More file actions
88 lines (69 loc) · 2.1 KB
/
mainWindow.js
File metadata and controls
88 lines (69 loc) · 2.1 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
// Modules
const {BrowserWindow, ipcMain} = require('electron')
const datastore = require('./datastore.js')
const filewatch = require('./datasource/filewatch');
var loadingState = "Kicking off engines."
exports.win
ipcMain.on('loading-state', (e, msg) => {
e.sender.send('loading-state', loadingState)
})
// mainWindow createWindow fn
exports.createWindow = (mainWindow) => {
this.win = mainWindow
// Create full size app
//this.win.maximize();
// Devtools
//this.win.webContents.openDevTools()
this.win.loadURL(`file://${__dirname}/renderer/main.html`)
this.win.once('ready-to-show', async () => {
this.win.show()
loadingState = "Initializing Local Datastore.."
await datastore.initializeDataStore()
loadingState = "Local Datastore initialized.."
return true;
// updateLoadingState('Initializing datastore')
})
// Handle window closed
this.win.on('closed', () => {
this.win = null
})
return this.win;
}
var loadPage = exports.loadPage = (name) => {
if (name === 'monitor.html') {
this.win.loadURL('file://' + __dirname + '/renderer/monitor.html')
} else{
this.win.loadURL(`file://${__dirname}/renderer/${name}`)
}
}
ipcMain.on('is-new-user', async (e, msg) => {
try {
let isOldUser = await datastore.findUser(msg.email)
if (isOldUser) {
e.sender.send('is-new-user', {error:"User already exists"})
return
}
await datastore.newUser(msg.email, msg.password)
loadPage('login.html')
} catch(error) {
e.sender.send('is-new-user', false)
}
})
ipcMain.on('log-in', async (e, msg) => {
try {
let isLoggedIn = await datastore.loginUser(msg.email, msg.password, msg.isRemembered)
if (!isLoggedIn) {
e.sender.send('log-in', {error:"User already exists"})
return
}
//TODO:
let win = new BrowserWindow({width: 1000, height: 800, minWidth: 920, minHeight: 730})
win.loadURL(`file://${__dirname}/renderer/monitor.html`)
win.webContents.openDevTools()
this.win.close()
this.win = win
} catch(error) {
console.log('error', error)
e.sender.send('is-new-user', false)
}
})