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) (#7452)

* 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>

* Fixup cherry-pick

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-31 14:21:07 -04:00 committed by GitHub
parent c48b53fd5e
commit 2884dea195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 14 deletions

View File

@ -8,7 +8,7 @@ import { beforeQuitOfFrontEndInjectionToken, beforeQuitOfBackEndInjectionToken }
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 "@k8slens/run-many";
import { runManySyncFor, runManyFor } from "@k8slens/run-many";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
@ -16,8 +16,9 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
instantiate: (di) => ({
run: () => {
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);
@ -27,17 +28,43 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
isAutoUpdating = true;
});
app.on("will-quit", (event) => {
app.on("will-quit", () => {
runRunnablesBeforeQuitOfFrontEnd();
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
let isAsyncQuitting = false;
if (shouldQuitBackEnd) {
runRunnablesBeforeQuitOfBackEnd();
} else {
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
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();
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.injectable";
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

@ -10,7 +10,7 @@ export const beforeQuitOfFrontEndInjectionToken = getInjectionToken<RunnableSync
id: "before-quit-of-front-end",
});
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<RunnableSync>({
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<Runnable>({
id: "before-quit-of-back-end",
});

View File

@ -12,13 +12,13 @@ const resolveSystemProxyWindowInjectable = getInjectable({
const app = di.inject(electronAppInjectable);
await app.whenReady();
const window = new BrowserWindow({
show: false,
paintWhenInitiallyHidden: false,
});
window.hide();
window.hide();
return window;
},