-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (43 loc) · 1.58 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
const {app} = require('electron');
const path = require('path');
const isDev = require('electron-is-dev');
const {createWindow} = require('./config_tool.js');
const service = require('./service.js');
if(isDev) {
require('electron-reload')(__dirname, {electron: path.join(__dirname, 'node_modules', '.bin', 'electron')});
}
process.on('uncaughtException', (error) => {
console.error(error.message);
console.trace(error);
process.exit(-1);
});
require('yargs')
.usage('$0 [cmd]')
.command('$0', 'run the config program', () => {}, fix0(run_config))
.command('service', 'run the background service of the switcher', () => {}, fix0(run_service))
.command('install', 'install the background service to the system', () => {}, fix0(run_installer))
.command('uninstall', 'remove the background service from the system', () => {}, fix0(run_uninstaller))
.help()
.strict()
.parse(isDev ? process.argv.slice(2) : process.argv.slice(1));
function fix0(func) {
return function(argv) {
argv.$0 = isDev ? argv.$0 : argv.$0.split(' ')[0];
return func(argv);
};
}
function run_config(argv) {
app.on('ready', createWindow.bind(null, argv));
app.on('window-all-closed', function() {
app.quit();
});
}
function run_service(argv) {
app.on('ready', service.startService.bind(null, argv));
}
function run_installer(argv) {
app.on('ready', service.installService.bind(null, argv));
}
function run_uninstaller(argv) {
app.on('ready', service.removeService.bind(null, argv));
}