-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
103 lines (89 loc) · 2.66 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
This file is the main thread for electron
*/
const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
const url = require('url')
const config = require('./src/app/app.config.json')
const fs = require('fs')
/**
* mainApplicationWindow is the parent of the application
* splashWindow is the child of the above
*/
let mainApplicationWindow
let splashWindow
//initiates the windows
function createWindow () {
// Create the browser window.
mainApplicationWindow = new BrowserWindow({
width: config.mainApplication.width,
height: config.mainApplication.height,
fullscreenable: config.mainApplication.isFullscreenable,
title: config.name,
show: false
})
splashWindow = new BrowserWindow({
parent: mainApplicationWindow,
width: config.splash.width,
height: config.splash.height,
frame: config.splash.isBorder,
modal: true,
show: true
})
// and load the index.html of the app.
mainApplicationWindow.loadURL(url.format({
pathname: path.join(__dirname, 'public/index.html'),
protocol: 'file:',
slashes: true
}))
splashWindow.loadURL(url.format({
pathname: path.join(__dirname, 'public/splash.html'),
protocol: 'file:',
slashes: true
}))
// Emitted when the window is closed.
mainApplicationWindow.on('closed', () => {
mainApplicationWindow = null
})
splashWindow.on('closed', () => {
splashWindow = null
})
mainApplicationWindow.once('ready-to-show', () => {
let credentialLocation = url.format({
pathname: path.join(app.getPath('userData'), config.credentials.location),
protocol: 'file',
slashes: true
})
if (fs.existsSync(credentialLocation)) {
//then load the credentials
let credentials = fs.readFileSync(credentialLocation)
splashWindow.webContents.on('did-finish-load', () => {
console.log('sending the data')
splashWindow.webContents.send('credentials', credentials)
})
console.log('we have credentials')
}
else {
console.log('We don\'t have credentials')
splashWindow.webContents.on('did-finish-load', () => {
splashWindow.webContents.send('credentials', '')
})
}
})
}
app.on('ready', createWindow)
ipcMain.on('credentials', (event, arg) => {
//persist the credentials
console.log(arg) // prints "ping"
})
// Quit when all windows are closed.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainApplicationWindow === null) {
createWindow()
}
})