-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
76 lines (61 loc) · 1.82 KB
/
renderer.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
const { ipcRenderer, remote } = require('electron')
// Keep the window hidden instead of fully closing. Full close is performed by menu or tray.
window.onbeforeunload = (e) => {
let windowVisible = ipcRenderer.sendSync('window-visible')
if (windowVisible) {
e.returnValue = false
}
else {
e.returnValue = true
}
ipcRenderer.send('close-main-window')
}
let webview = document.querySelector('#contentFrame')
showConfig = () => {
let config = remote.getGlobal('getConfig')()
document.querySelector('#config').innerHTML = JSON.stringify(config)
}
hideLogin = () => {
document.querySelector('#login').style.display = 'none'
}
showLogin = () => {
document.querySelector('#login').style.display = 'block'
}
showSettings = () => {
webview.executeJavaScript("window.showSettings()")
}
login = () => {
// if (remote.getGlobal('login')(
// document.querySelector('#server').value,
// document.querySelector('#username').value,
// document.querySelector('#password').value
// )) {
hideLogin()
// }
}
logout = () => {
showLogin()
}
checkAuthenticated = () => {
if (remote.getGlobal('isAuthenticated')()) {
hideLogin()
}
else {
showLogin()
}
}
// Listeners for button clicks
// document.querySelector('.selectDir').addEventListener('click', function () {
// ipcRenderer.send('select-dir')
// showConfig()
// })
// document.querySelector('.saveConfig').addEventListener('click', function () {
// ipcRenderer.send('save-config')
// hideSettings()
// })
// document.querySelector('.loadConfig').addEventListener('click', showConfig)
document.querySelector('.login').addEventListener('click', login)
// document.querySelector('#settingsButton').addEventListener('click', showSettings)
// ipcRenderer.on('show-settings', showSettings)
ipcRenderer.on('logout', logout)
checkAuthenticated()