2017-11-05 02:49:23 +02:00
|
|
|
// This is the basic initialization for the Electron MAIN process
|
|
|
|
|
2017-11-03 20:01:24 +02:00
|
|
|
// Make it possible to require("/lib/...") without specifying full path
|
2017-11-04 13:26:49 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
2017-11-03 01:26:08 +02:00
|
|
|
|
2017-11-04 13:26:49 +02:00
|
|
|
const electronApp = require('electron').app;
|
2017-11-05 02:17:48 +02:00
|
|
|
const { ElectronAppWrapper } = require('./ElectronAppWrapper');
|
|
|
|
const { initBridge } = require('./bridge');
|
2017-11-14 12:53:18 +02:00
|
|
|
const { Logger } = require('lib/logger.js');
|
|
|
|
const { FsDriverNode } = require('lib/fs-driver-node.js');
|
2020-06-03 18:07:50 +02:00
|
|
|
const envFromArgs = require('lib/envFromArgs');
|
2017-11-03 01:26:08 +02:00
|
|
|
|
2017-11-04 13:26:49 +02:00
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
|
|
console.error('Unhandled promise rejection', p, 'reason:', reason);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
2018-04-23 21:50:29 +02:00
|
|
|
// Likewise, we want to know if a profile is specified early, in particular
|
|
|
|
// to save the window state data.
|
|
|
|
function profileFromArgs(args) {
|
|
|
|
if (!args) return null;
|
|
|
|
const profileIndex = args.indexOf('--profile');
|
|
|
|
if (profileIndex <= 0 || profileIndex >= args.length - 1) return null;
|
|
|
|
const profileValue = args[profileIndex + 1];
|
|
|
|
return profileValue ? profileValue : null;
|
|
|
|
}
|
|
|
|
|
2017-11-14 12:53:18 +02:00
|
|
|
Logger.fsDriver_ = new FsDriverNode();
|
|
|
|
|
2017-11-13 20:47:35 +02:00
|
|
|
const env = envFromArgs(process.argv);
|
2018-04-23 21:50:29 +02:00
|
|
|
const profilePath = profileFromArgs(process.argv);
|
2020-09-01 23:25:23 +02:00
|
|
|
const isDebugMode = !!process.argv && process.argv.indexOf('--debug') >= 0;
|
2017-11-13 20:47:35 +02:00
|
|
|
|
2020-09-01 23:25:23 +02:00
|
|
|
const wrapper = new ElectronAppWrapper(electronApp, env, profilePath, isDebugMode);
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
initBridge(wrapper);
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
wrapper.start().catch((error) => {
|
|
|
|
console.error('Electron App fatal error:');
|
2017-11-04 13:26:49 +02:00
|
|
|
console.error(error);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|