forked from microsoft/onnxjs-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.js
68 lines (57 loc) · 1.8 KB
/
electron.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
const {app, BrowserWindow, protocol} = require('electron');
const path = require('path');
const url = require('url');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null;
function createWindow () {
const WEB_FOLDER = 'dist';
const PROTOCOL = 'file';
protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {
// // Strip protocol
let url = request.url.substr(PROTOCOL.length + 1);
// Build complete path for node require function
url = path.join(__dirname, WEB_FOLDER, url);
// Replace backslashes by forward slashes (windows)
url = path.normalize(url);
callback({path: url});
});
// Create the browser window.
mainWindow = new BrowserWindow({show: false,
webPreferences: {webgl: true,
nodeIntegration: false}
});
mainWindow.maximize();
mainWindow.show();
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: 'index.html',
protocol: PROTOCOL + ':',
slashes: true
}));
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
app.on('ready', () => {
createWindow();
});
//create the application window if the window variable is null
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
//quit the app once closed
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
process.exit();
app.quit();
}
});