-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.js
111 lines (90 loc) · 3.03 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
104
105
106
107
108
109
110
111
const {app, BrowserWindow, ipcMain, dialog, session, cookies} = require('electron');
const {autoUpdater} = require("electron-updater");
const pug = require('pug');
const request = require('request');
let mainWindow, updateWindow;
let appPath = app.getAppPath();
async function createDiscordWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
preload: appPath + '/views/js/preload.js',
nodeIntegration: false,
contextIsolation: false
}
});
mainWindow.loadURL('https://doublecolossus.com/');
// mainWindow.loadURL('http://localhost/');
// mainWindow.removeMenu();
// mainWindow.webContents.openDevTools();
// mainWindow.maximize();
mainWindow.on('closed', function () {
mainWindow = null;
});
let cookies = session.defaultSession.cookies;
cookies.on('changed', function (event, cookie, cause, removed) {
if (!cookie.session || removed) {
return;
}
let url = `${(!cookie.httpOnly && cookie.secure) ? 'https' : 'http'}://${cookie.domain}${cookie.path}`;
cookies.set({
url: url,
name: cookie.name,
value: cookie.value,
domain: cookie.domain,
path: cookie.path,
secure: cookie.secure,
httpOnly: cookie.httpOnly,
expirationDate: Math.floor(new Date().getTime() / 1000) + 1209600
}, function (err) {
if (err) console.log(err);
});
});
}
async function createUpdateWindow() {
updateWindow = new BrowserWindow({
width: 500,
height: 200,
frame: false,
resizable: false,
webPreferences: {
nodeIntegration: true
}
});
let params = {
title: 'Launcher'
};
let html = pug.renderFile(appPath + '/views/update.pug', params);
updateWindow.loadURL('data:text/html,' + encodeURIComponent(html), {
baseURLForDataURL: `file://${appPath}/views/`
});
updateWindow.removeMenu();
updateWindow.on('closed', function () {
updateWindow = null;
});
}
app.on('ready', async () => {
await createUpdateWindow();
autoUpdater.checkForUpdates();
});
autoUpdater.on('checking-for-update', () => {
updateWindow.webContents.send('update', 'Checking for updates', '...');
});
autoUpdater.on('update-available', (info) => {
updateWindow.webContents.send('update', 'Update found', '...');
});
autoUpdater.on('update-not-available', async (info) => {
await createDiscordWindow();
updateWindow.close();
});
autoUpdater.on('error', (err) => {
updateWindow.webContents.send('update', 'Error when updating', JSON.stringify(err));
});
autoUpdater.on('download-progress', (progress) => {
let progressMsg = `Progress: ${progress.percent} (${progress.transferred} / ${progress.total})`;
updateWindow.webContents.send('update', 'Downloading', progressMsg);
});
autoUpdater.on('update-downloaded', (info) => {
autoUpdater.quitAndInstall();
});