Rename and prune
This commit is contained in:
parent
d1d9cd9518
commit
8045bd1e5a
3 changed files with 19 additions and 17 deletions
|
@ -36,24 +36,26 @@ export const rendererURL = "next://app";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We want to hide our window instead of closing it when the user presses the
|
* We want to hide our window instead of closing it when the user presses the
|
||||||
* cross button on the window (this is because there is 1. a perceptible initial
|
* cross button on the window.
|
||||||
* window creation time for our app, and 2. because the long running processes
|
*
|
||||||
* like export and watch folders are tied to the lifetime of the window and
|
* > This is because there is 1. a perceptible initial window creation time for
|
||||||
* otherwise won't run in the background.
|
* > our app, and 2. because the long running processes like export and watch
|
||||||
|
* > folders are tied to the lifetime of the window and otherwise won't run in
|
||||||
|
* > the background.
|
||||||
*
|
*
|
||||||
* Intercepting the window close event and using that to instead hide it is
|
* Intercepting the window close event and using that to instead hide it is
|
||||||
* easy, however that prevents the actual app quit to stop working (since the
|
* easy, however that prevents the actual app quit to stop working (since the
|
||||||
* window never gets closed).
|
* window never gets closed).
|
||||||
*
|
*
|
||||||
* So to achieve our original goal (hide window instead of closing) without
|
* So to achieve our original goal (hide window instead of closing) without
|
||||||
* disabling expected app quits, we keep this `allowWindowClose` flag. It is off
|
* disabling expected app quits, we keep a flag, and we turn it on when we're
|
||||||
* by default, but in the cases where we *do* want the app to quit, we set it to
|
* part of the quit sequence. When this flag is on, we bypass the code that
|
||||||
* true beforehand before calling the actual process that'll do the quitting.
|
* prevents the window from being closed.
|
||||||
*/
|
*/
|
||||||
let allowWindowClose = false;
|
let shouldAllowWindowClose = false;
|
||||||
|
|
||||||
export const setIsAppQuitting = (value: boolean): void => {
|
export const allowWindowClose = (): void => {
|
||||||
allowWindowClose = value;
|
shouldAllowWindowClose = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,8 +156,8 @@ const createMainWindow = async () => {
|
||||||
window.webContents.forcefullyCrashRenderer();
|
window.webContents.forcefullyCrashRenderer();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.on("close", function (event) {
|
window.on("close", (event) => {
|
||||||
if (!allowWindowClose) {
|
if (!shouldAllowWindowClose) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
window.hide();
|
window.hide();
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,7 @@ const main = () => {
|
||||||
// app, e.g. by clicking on its dock icon.
|
// app, e.g. by clicking on its dock icon.
|
||||||
app.on("activate", () => mainWindow?.show());
|
app.on("activate", () => mainWindow?.show());
|
||||||
|
|
||||||
app.on("before-quit", () => setIsAppQuitting(true));
|
app.on("before-quit", allowWindowClose);
|
||||||
};
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
MenuItemConstructorOptions,
|
MenuItemConstructorOptions,
|
||||||
shell,
|
shell,
|
||||||
} from "electron";
|
} from "electron";
|
||||||
import { setIsAppQuitting } from "../main";
|
import { allowWindowClose } from "../main";
|
||||||
import { forceCheckForAppUpdates } from "./services/app-update";
|
import { forceCheckForAppUpdates } from "./services/app-update";
|
||||||
import autoLauncher from "./services/autoLauncher";
|
import autoLauncher from "./services/autoLauncher";
|
||||||
import { userPreferences } from "./stores/user-preferences";
|
import { userPreferences } from "./stores/user-preferences";
|
||||||
|
@ -195,7 +195,7 @@ export const createTrayContextMenu = (mainWindow: BrowserWindow) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setIsAppQuitting(true);
|
allowWindowClose();
|
||||||
app.quit();
|
app.quit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { compareVersions } from "compare-versions";
|
||||||
import { app, BrowserWindow } from "electron";
|
import { app, BrowserWindow } from "electron";
|
||||||
import { default as electronLog } from "electron-log";
|
import { default as electronLog } from "electron-log";
|
||||||
import { autoUpdater } from "electron-updater";
|
import { autoUpdater } from "electron-updater";
|
||||||
import { setIsAppQuitting } from "../../main";
|
import { allowWindowClose } from "../../main";
|
||||||
import { AppUpdateInfo } from "../../types/ipc";
|
import { AppUpdateInfo } from "../../types/ipc";
|
||||||
import log from "../log";
|
import log from "../log";
|
||||||
import { userPreferences } from "../stores/user-preferences";
|
import { userPreferences } from "../stores/user-preferences";
|
||||||
|
@ -83,7 +83,7 @@ export const appVersion = () => `v${app.getVersion()}`;
|
||||||
|
|
||||||
export const updateAndRestart = () => {
|
export const updateAndRestart = () => {
|
||||||
log.info("Restarting the app to apply update");
|
log.info("Restarting the app to apply update");
|
||||||
setIsAppQuitting(true);
|
allowWindowClose();
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue