diff --git a/src/electron-main/index.ts b/src/electron-main/index.ts index 2be2e8e71..526bb74fa 100644 --- a/src/electron-main/index.ts +++ b/src/electron-main/index.ts @@ -17,21 +17,31 @@ electronUnhandled({logger: logger.error}); // needed for desktop notifications properly working on Win 10, details https://www.electron.build/configuration/nsis app.setAppUserModelId(`com.github.vladimiry.${APP_NAME}`); +const secondInstanceExecutedCallbacks = (() => { + const callbacks: Array<() => Promise> = []; + if (app.makeSingleInstance(async () => { + for (const callback of callbacks) { + await callback(); + } + })) { + // calling app.exit() instead of app.quit() in order to prevent "Error: Cannot find module ..." error happening + // https://github.com/electron/electron/issues/8862 + app.exit(); + } + return callbacks; +})(); + // possible rejection will be caught and logged by above initialized "electron-unhandled" // tslint:disable-next-line:no-floating-promises initContext().then(initApp); export function initApp(ctx: Context) { app.on("ready", async () => { - if (app.makeSingleInstance(async () => endpoints.activateBrowserWindow().toPromise())) { - // calling app.exit() instead of app.quit() in order to prevent "Error: Cannot find module ..." error happening - // https://github.com/electron/electron/issues/8862 - app.exit(); - } - const endpoints = await initApi(ctx); const {checkForUpdatesAndNotify} = await endpoints.readConfig().toPromise(); + secondInstanceExecutedCallbacks.push(() => endpoints.activateBrowserWindow().toPromise()); + initWebContentContextMenu(ctx); const uiContext = ctx.uiContext = {