-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (82 loc) · 2.22 KB
/
index.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
const isDev = process.env.APP_ENV === "DEV";
const { app, BrowserWindow } = require("electron");
const { autoUpdater } = require("electron-updater");
const electronLocalshortcut = require("electron-localshortcut");
const path = require('path');
const url = require("url");
var log = require('electron-log');
log.transports.file.level = 'debug';
log.transports.console.level = 'debug';
autoUpdater.logger = log;
log.info("application version: " + app.getVersion() + "\n");
let win;
/**
* Create main electron window
*/
function createWindow() {
win = new BrowserWindow({
fullscreen: false,
autoHideMenuBar: true,
webPreferences: { webSecurity: false, experimentalFeatures: true },
icon: "./src/favicon.ico"
});
loadMain();
win.on("closed", () => {
win = null;
});
electronLocalshortcut.register(win, "F12", () => {
win.webContents.openDevTools();
});
electronLocalshortcut.register(win, "F5", () => {
loadMain();
});
/**
* Configure automatic updates
*/
if(!isDev) {
setInterval(() => {
log.info('check for updates...');
autoUpdater.checkForUpdates();
}, 200000); // check updates ever 20 min
log.info('check for updates...');
autoUpdater.checkForUpdates();
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
log.info('update downloaded! quit and install!');
autoUpdater.quitAndInstall();
});
autoUpdater.on('error', message => {
log.error('There was a problem updating the application');
log.error(message);
});
}
}
/**
* Load the main index.html window
*/
function loadMain() {
let indexUri = url.format({
pathname: path.join(__dirname, 'dist/uw/Unitinium-Workbench/dist/index.html'),
protocol: 'file:',
slashes: true
})
if (isDev) {
indexUri = url.format({
pathname: "localhost:5000",
protocol: "http:",
slashes: true
})
}
log.info("load uri: " + indexUri + "\n");
win.loadURL(indexUri);
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (win === null) {
createWindow();
}
});