1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix app crash on quit (#7407)

* Fix app crash on quit

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Back out disabling extensions on quit

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-23 17:45:53 -04:00 committed by GitHub
parent 0d9047c456
commit 1cab2a0fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 15 deletions

View File

@ -10,14 +10,16 @@ import electronAppInjectable from "../electron-app.injectable";
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable"; import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
import autoUpdaterInjectable from "../features/auto-updater.injectable"; import autoUpdaterInjectable from "../features/auto-updater.injectable";
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for"; import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
import { runManyFor } from "../../../common/runnable/run-many-for";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application", id: "setup-closing-of-application",
instantiate: (di) => { instantiate: (di) => {
const runManySync = runManySyncFor(di); const runManySync = runManySyncFor(di);
const runMany = runManyFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken); const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken); const runRunnablesBeforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
const app = di.inject(electronAppInjectable); const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable); const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable); const autoUpdater = di.inject(autoUpdaterInjectable);
@ -31,19 +33,41 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
isAutoUpdating = true; isAutoUpdating = true;
}); });
let isAsyncQuitting = false;
const doAsyncQuit = (event: Electron.Event, exitCode = 0) => {
if (isAsyncQuitting) {
return;
}
isAsyncQuitting = true;
void (async () => {
try {
await runRunnablesBeforeQuitOfBackEnd();
} catch (error) {
console.error("A beforeQuitOfBackEnd failed!!!!", error);
exitCode = 1;
}
app.exit(exitCode);
})();
};
app.on("will-quit", (event) => { app.on("will-quit", (event) => {
runRunnablesBeforeQuitOfFrontEnd(); runRunnablesBeforeQuitOfFrontEnd();
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
if (shouldQuitBackEnd) {
runRunnablesBeforeQuitOfBackEnd();
} else {
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
event.preventDefault(); event.preventDefault();
if (isIntegrationTesting || isAutoUpdating) {
doAsyncQuit(event);
} }
}); });
app.on("quit", (event, exitCode) => {
event.preventDefault();
doAsyncQuit(event, exitCode);
});
return undefined; return undefined;
}, },
}; };

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable"; import type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable";
import createElectronWindowForInjectable from "./create-electron-window.injectable"; import createElectronWindowInjectable from "./create-electron-window.injectable";
import type { ClusterFrameInfo } from "../../../../common/cluster-frames"; import type { ClusterFrameInfo } from "../../../../common/cluster-frames";
export interface ElectronWindow { export interface ElectronWindow {
@ -59,7 +59,7 @@ const createLensWindowInjectable = getInjectable({
id: "create-lens-window", id: "create-lens-window",
instantiate: (di) => { instantiate: (di) => {
const createElectronWindow = di.inject(createElectronWindowForInjectable); const createElectronWindow = di.inject(createElectronWindowInjectable);
return (configuration: LensWindowConfiguration): LensWindow => { return (configuration: LensWindowConfiguration): LensWindow => {
let browserWindow: ElectronWindow | undefined; let browserWindow: ElectronWindow | undefined;

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectionToken } from "@ogre-tools/injectable"; import { getInjectionToken } from "@ogre-tools/injectable";
import type { RunnableSync } from "../../../common/runnable/run-many-sync-for"; import type { Runnable } from "../../../common/runnable/run-many-for";
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<RunnableSync>({ export const beforeQuitOfBackEndInjectionToken = getInjectionToken<Runnable>({
id: "before-quit-of-back-end", id: "before-quit-of-back-end",
}); });

View File

@ -7,9 +7,9 @@ import { BrowserWindow } from "electron";
const resolveSystemProxyWindowInjectable = getInjectable({ const resolveSystemProxyWindowInjectable = getInjectable({
id: "resolve-system-proxy-window", id: "resolve-system-proxy-window",
instantiate: () => { instantiate: () => new BrowserWindow({
return new BrowserWindow({ show: false, paintWhenInitiallyHidden: false }); show: false,
}, }),
causesSideEffects: true, causesSideEffects: true,
}); });