This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
100 lines (85 loc) · 2.56 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
const electron = require('electron')
const { app, BrowserWindow, ipcMain, dialog, session } = electron;
const path = require('path');
const url = require('url');
let win, winSession;
const createWindow = () => {
const {width, height} = electron.screen.getPrimaryDisplay().size;
win = new BrowserWindow({width, height, resizable: false});
winSession = win.webContents.session
winSession.cookies.get({name: 'cookie'}, (error, cookies) => {
console.log(cookies)
if (cookies[0]) {
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
hash: '/',
slashes: true
}));
} else win.loadURL(url.format({
pathname: path.resolve(__dirname, 'login.html'),
protocol: 'file:',
slashes: true
}));
})
// if (process.env.NODE_ENV === 'development') win.loadURL('http://localhost:8080')
// win.webContents.openDevTools()
win.on('closed', () => {
win = null
});
}
ipcMain.on('login', () => {
win.loadURL(url.format({
pathname: path.join(__dirname, 'login.html'),
protocol: 'file:',
hash: '/',
slashes: true
}));
})
ipcMain.on('guest', (event, args) => {
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
hash: '/',
slashes: true
}));
console.log('Guest Logged In', args)
event.sender.send('guestLoggedIn', args)
})
ipcMain.on('authorized', (event, args) => {
console.log('before if state');
if (args) {
// console.log('user loggedin b4 loadURL', args);
win.webContents.on('dom-ready', () => {
// Send Message
console.log('inside did finishload');
event.sender.send('userLoggedIn', args);
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
hash: '/',
slashes: true
}));
winSession.cookies.set({url: 'https://myapp.com', name: 'cookie', value: 'cookie_value', domain: 'myapp.com', expirationDate: 999999999999}, (error) => console.log(error))
win.webContents.send('userLoggedIn', args);
}
})
ipcMain.on('logout', () => {
winSession.cookies.remove('https://myapp.com', 'cookie', (error) => console.log(error))
})
ipcMain.on('selectFileDirectory' , (event) => {
const dir = dialog.showOpenDialog(win, {
properties: ['openDirectory'],
})
event.sender.send('selectedDir', dir[0]);
})
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) createWindow()
})