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> * Fixup cherry-pick Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
c48b53fd5e
commit
2884dea195
@ -8,7 +8,7 @@ import { beforeQuitOfFrontEndInjectionToken, beforeQuitOfBackEndInjectionToken }
|
|||||||
import electronAppInjectable from "../electron-app.injectable";
|
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 "@k8slens/run-many";
|
import { runManySyncFor, runManyFor } from "@k8slens/run-many";
|
||||||
|
|
||||||
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
||||||
id: "setup-closing-of-application",
|
id: "setup-closing-of-application",
|
||||||
@ -16,8 +16,9 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
|||||||
instantiate: (di) => ({
|
instantiate: (di) => ({
|
||||||
run: () => {
|
run: () => {
|
||||||
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);
|
||||||
@ -27,17 +28,43 @@ const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
|||||||
isAutoUpdating = true;
|
isAutoUpdating = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("will-quit", (event) => {
|
app.on("will-quit", () => {
|
||||||
runRunnablesBeforeQuitOfFrontEnd();
|
runRunnablesBeforeQuitOfFrontEnd();
|
||||||
|
|
||||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
let isAsyncQuitting = false;
|
||||||
|
|
||||||
if (shouldQuitBackEnd) {
|
const doAsyncQuit = (event: Electron.Event, exitCode = 0) => {
|
||||||
runRunnablesBeforeQuitOfBackEnd();
|
if (isAsyncQuitting) {
|
||||||
} else {
|
return;
|
||||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
}
|
||||||
|
|
||||||
|
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();
|
event.preventDefault();
|
||||||
}
|
|
||||||
|
if (isIntegrationTesting || isAutoUpdating) {
|
||||||
|
doAsyncQuit(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on("quit", (event, exitCode) => {
|
||||||
|
event.preventDefault();
|
||||||
|
doAsyncQuit(event, exitCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@ -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.injectable";
|
import type { ClusterFrameInfo } from "../../../../common/cluster-frames.injectable";
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export const beforeQuitOfFrontEndInjectionToken = getInjectionToken<RunnableSync
|
|||||||
id: "before-quit-of-front-end",
|
id: "before-quit-of-front-end",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<RunnableSync>({
|
export const beforeQuitOfBackEndInjectionToken = getInjectionToken<Runnable>({
|
||||||
id: "before-quit-of-back-end",
|
id: "before-quit-of-back-end",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user