-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (44 loc) · 1.55 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
// Basic init
const electron = require('electron')
const path = require('path')
const Backend = require('./lib/Backend')
const R = require('ramda')
const fs = require('fs')
const {app, BrowserWindow, dialog} = electron
let config;
try {
config = fs.readFileSync('./config.js');
} catch (err) {
dialog.showErrorBox("Can not load configuration", "config.js can not be found in current working directory. You can always make one, by copy config.js.example, and rename it to config.js");
process.exit(1);
}
const Config = eval(config.toString());
// Let electron reloads by itself when webpack watches changes in ./app/
if (/electron/.test(process.execPath)) {
require('electron-reload')(path.resolve(__dirname, "app"))
}
const backend = new Backend(Config);
global.backend = backend;
// To avoid being garbage collected
let mainWindow
app.on('ready', () => {
// BrowserWindow.addDevToolsExtension(path.resolve(__dirname, "vue-devtools.crx"));
let mainWindow = new BrowserWindow({
width: 1000,
height: 600,
minWidth: 600
})
mainWindow.loadURL(`file://${__dirname}/app/index.html`)
mainWindow.on("close", () => {
process.exit(0);
})
setInterval(() => {
const getProgress = worker => worker.getProgress();
const getAllProgress = R.mapObjIndexed(getProgress);
mainWindow.webContents.send("backend-update-link", {
downloadPool: getAllProgress(backend.downloadPool),
needRefresh: backend.needRefresh
});
backend.flushState();
}, 500);
})