forked from browserhtml/browserhtml
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
79 lines (67 loc) · 1.96 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
const electron = require('electron');
const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
const path = require('path');
var mainWindow = null;
// Quit when all windows are closed.
const onQuit = function() {
app.quit()
};
const encodeArgsAsQueryString =
args =>
args.reduce
( ({flag, query}, arg) =>
( /^--\w+$/.test(arg) // If new flag swap flag.
? { flag: arg.substr(2)
, query:
( query === ""
? `${arg.substr(2)}`
: `${query}&${arg.substr(2)}`
)
}
: flag == null // If there is no flag then skip.
? { flag
, query
}
: { flag
, query:
( ( query.endsWith(`&${flag}`) || query === flag )
? `${query}=${encodeURIComponent(arg)}`
: `${query}&${flag}=${encodeURIComponent(arg)}`
)
}
)
, { flag: null
, query: ""
}
)
.query
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
var onReady = function() {
// Create the browser window.
mainWindow = new BrowserWindow
( { width: 1024
, height: 740
, frame: false
, webPreferences:
{ nodeIntegration: true
, preload: path.resolve(path.join('.'), 'electron-preload.js')
}
}
);
// and load the index.html of the app.
mainWindow.loadURL
(`file://${path.resolve(module.filename, '../dist/index.html')}?${encodeArgsAsQueryString(process.argv.slice(2))}`);
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// 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('window-all-closed', onQuit);
app.on('ready', onReady);