Skip to content

Commit

Permalink
move "forceClose" flag to context
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Feb 22, 2018
1 parent 8430d7e commit cb3e5d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ let uiContext: UIContext;

export function initApp(ctx: Context) {
if (app.makeSingleInstance(activateBrowserWindow)) {
app.quit();
ctx.forceClose = true;
// 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();
}

app.on("ready", async () => {
Expand Down
7 changes: 3 additions & 4 deletions src/electron/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export async function initBrowserWindow(ctx: Context): Promise<BrowserWindow> {
show: false,
};
const browserWindow = new BrowserWindow(browserWindowConstructorOptions);
const appBeforeQuitEventHandler = () => forceClose = true;
let forceClose = false;
const appBeforeQuitEventHandler = () => ctx.forceClose = true;

app.on("before-quit", appBeforeQuitEventHandler);

Expand All @@ -36,7 +35,7 @@ export async function initBrowserWindow(ctx: Context): Promise<BrowserWindow> {
});
browserWindow.on("closed", () => {
browserWindow.destroy();

delete ctx.forceClose;
app.removeListener("before-quit", appBeforeQuitEventHandler);

// On macOS it is common for applications and their menu bar to stay active until the user quits explicitly with Cmd + Q
Expand All @@ -45,7 +44,7 @@ export async function initBrowserWindow(ctx: Context): Promise<BrowserWindow> {
}
});
browserWindow.on("close", (event) => {
if (!ctx.configInstance().closeToTray || forceClose) {
if (!ctx.configInstance().closeToTray || ctx.forceClose) {
// allow window closing
return true;
}
Expand Down

0 comments on commit cb3e5d6

Please sign in to comment.