1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-09 08:45:55 +02:00
joplin/packages/app-desktop/main.js
Laurent Cozic f371bb8e59 Revert "Merge branch 'desktop-protocol' of https://github.com/roman-r-m/joplin into dev"
This reverts commit 7c85889c1f, reversing
changes made to ab134807ea.

Reason: Messed up and accidentally merged a pull request.
2021-09-03 15:03:17 +01:00

47 lines
1.7 KiB
JavaScript

// This is the basic initialization for the Electron MAIN process
const electronApp = require('electron').app;
const ElectronAppWrapper = require('./ElectronAppWrapper').default;
const { initBridge } = require('./bridge');
const Logger = require('@joplin/lib/Logger').default;
const FsDriverNode = require('@joplin/lib/fs-driver-node').default;
const envFromArgs = require('@joplin/lib/envFromArgs');
const packageInfo = require('./packageInfo.js');
// Electron takes the application name from package.json `name` and
// displays this in the tray icon toolip and message box titles, however in
// our case it's a string like "@joplin/app-desktop". It's also supposed to
// check the productName key but is not doing it, so here set the
// application name to the right string.
electronApp.name = packageInfo.name;
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled promise rejection', p, 'reason:', reason);
process.exit(1);
});
// 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;
}
Logger.fsDriver_ = new FsDriverNode();
const env = envFromArgs(process.argv);
const profilePath = profileFromArgs(process.argv);
const isDebugMode = !!process.argv && process.argv.indexOf('--debug') >= 0;
const wrapper = new ElectronAppWrapper(electronApp, env, profilePath, isDebugMode);
initBridge(wrapper);
wrapper.start().catch((error) => {
console.error('Electron App fatal error:');
console.error(error);
});