mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix application quit by calling Electron's event.preventDefault in a very specific way and preventing async
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
98cecaa91c
commit
b3dab6b781
@ -5,17 +5,17 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeApplicationIsReadyInjectionToken } from "../../start-main-application/before-application-is-ready/before-application-is-ready-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/before-quit-of-front-end/before-quit-of-front-end-injection-token";
|
||||
import { runManyFor } from "../../start-main-application/run-many-for";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/before-quit-of-back-end/before-quit-of-back-end-injection-token";
|
||||
import electronAppInjectable from "../electron-app.injectable";
|
||||
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
|
||||
import autoUpdaterInjectable from "../features/auto-updater.injectable";
|
||||
import { runManySyncFor } from "../../start-main-application/run-many-sync-for";
|
||||
|
||||
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
||||
id: "setup-closing-of-application",
|
||||
|
||||
instantiate: (di) => {
|
||||
const runMany = runManyFor(di);
|
||||
const runMany = runManySyncFor(di);
|
||||
|
||||
const runRunnablesBeforeQuitOfFrontEnd = runMany(
|
||||
beforeQuitOfFrontEndInjectionToken,
|
||||
@ -38,15 +38,16 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
||||
isAutoUpdating = true;
|
||||
});
|
||||
|
||||
app.on("will-quit", async ({ preventDefault: cancelNativeQuit }) => {
|
||||
await runRunnablesBeforeQuitOfFrontEnd();
|
||||
app.on("will-quit", (event) => {
|
||||
runRunnablesBeforeQuitOfFrontEnd();
|
||||
|
||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
||||
|
||||
if (shouldQuitBackEnd) {
|
||||
await runRunnablesBeforeQuitOfBackEnd();
|
||||
runRunnablesBeforeQuitOfBackEnd();
|
||||
} else {
|
||||
cancelNativeQuit();
|
||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
import type { RunnableSync } from "../run-many-sync-for";
|
||||
|
||||
export const beforeQuitOfBackEndInjectionToken =
|
||||
getInjectionToken<Runnable>({
|
||||
getInjectionToken<RunnableSync>({
|
||||
id: "before-quit-of-back-end",
|
||||
});
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Runnable } from "../run-many-for";
|
||||
import type { RunnableSync } from "../run-many-sync-for";
|
||||
|
||||
export const beforeQuitOfFrontEndInjectionToken =
|
||||
getInjectionToken<Runnable>({
|
||||
getInjectionToken<RunnableSync>({
|
||||
id: "before-quit-of-front-end",
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user