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 autoUpdaterInjectable from "../features/auto-updater.injectable";
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
import { runManyFor } from "../../../common/runnable/run-many-for";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
instantiate: (di) => {
const runManySync = runManySyncFor(di);
const runMany = runManyFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
const runRunnablesBeforeQuitOfBackEnd = runMany(beforeQuitOfBackEndInjectionToken);
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
@ -31,19 +33,41 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
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) => {
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();
if (isIntegrationTesting || isAutoUpdating) {
doAsyncQuit(event);
}
});
app.on("quit", (event, exitCode) => {
event.preventDefault();
doAsyncQuit(event, exitCode);
});
return undefined;
},
};

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/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";
export interface ElectronWindow {
@ -59,7 +59,7 @@ const createLensWindowInjectable = getInjectable({
id: "create-lens-window",
instantiate: (di) => {
const createElectronWindow = di.inject(createElectronWindowForInjectable);
const createElectronWindow = di.inject(createElectronWindowInjectable);
return (configuration: LensWindowConfiguration): LensWindow => {
let browserWindow: ElectronWindow | undefined;

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
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",
});

View File

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