mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Split setupRunnablesBeforeClosingOfApplication
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
802cbdb096
commit
c0eb4c6dea
@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||||
|
import { runManySyncFor } from "@k8slens/run-many";
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
|
||||||
|
import { afterQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||||
|
import electronAppInjectable from "../electron-app.injectable";
|
||||||
|
import isAutoUpdatingInjectable from "../features/is-auto-updating.injectable";
|
||||||
|
|
||||||
|
const setupBehaviourOnCloseOfLastWindowInjectable = getInjectable({
|
||||||
|
id: "setup-behaviour-on-close-of-last-window",
|
||||||
|
instantiate: (di) => ({
|
||||||
|
run: () => {
|
||||||
|
const runManySync = runManySyncFor(di);
|
||||||
|
const runAfterQuitOfFrontEnd = runManySync(afterQuitOfFrontEndInjectionToken);
|
||||||
|
const app = di.inject(electronAppInjectable);
|
||||||
|
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
||||||
|
const isAutoUpdating = di.inject(isAutoUpdatingInjectable);
|
||||||
|
|
||||||
|
app.on("window-all-closed", () => {
|
||||||
|
runAfterQuitOfFrontEnd();
|
||||||
|
|
||||||
|
if (isIntegrationTesting || isAutoUpdating.get()) {
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default setupBehaviourOnCloseOfLastWindowInjectable;
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||||
|
import { onQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||||
|
import electronAppInjectable from "../electron-app.injectable";
|
||||||
|
import { runManyFor } from "@k8slens/run-many";
|
||||||
|
import { once } from "lodash";
|
||||||
|
|
||||||
|
const setupCleanupOfBackendOnQuitInjectable = getInjectable({
|
||||||
|
id: "setup-cleanup-of-backend-on-quit",
|
||||||
|
|
||||||
|
instantiate: (di) => ({
|
||||||
|
run: () => {
|
||||||
|
const runMany = runManyFor(di);
|
||||||
|
const runOnQuitOfBackEnd = runMany(onQuitOfBackEndInjectionToken);
|
||||||
|
const app = di.inject(electronAppInjectable);
|
||||||
|
|
||||||
|
const doAsyncQuit = once(() => void (async () => {
|
||||||
|
try {
|
||||||
|
await runOnQuitOfBackEnd();
|
||||||
|
app.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("A beforeQuitOfBackEnd failed!!!!", error);
|
||||||
|
app.exit(1);
|
||||||
|
}
|
||||||
|
})());
|
||||||
|
|
||||||
|
app.on("will-quit", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
doAsyncQuit();
|
||||||
|
});
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default setupCleanupOfBackendOnQuitInjectable;
|
||||||
@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
|
||||||
import { afterQuitOfFrontEndInjectionToken, onQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
|
||||||
import electronAppInjectable from "../electron-app.injectable";
|
|
||||||
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
|
|
||||||
import { runManySyncFor, runManyFor } from "@k8slens/run-many";
|
|
||||||
import isAutoUpdatingInjectable from "../features/is-auto-updating.injectable";
|
|
||||||
|
|
||||||
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
|
||||||
id: "setup-closing-of-application",
|
|
||||||
|
|
||||||
instantiate: (di) => ({
|
|
||||||
run: () => {
|
|
||||||
const runManySync = runManySyncFor(di);
|
|
||||||
const runMany = runManyFor(di);
|
|
||||||
const runAfterQuitOfFrontEnd = runManySync(afterQuitOfFrontEndInjectionToken);
|
|
||||||
const runOnQuitOfBackEnd = runMany(onQuitOfBackEndInjectionToken);
|
|
||||||
const app = di.inject(electronAppInjectable);
|
|
||||||
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
|
||||||
const isAutoUpdating = di.inject(isAutoUpdatingInjectable);
|
|
||||||
|
|
||||||
app.on("will-quit", () => {
|
|
||||||
runAfterQuitOfFrontEnd();
|
|
||||||
|
|
||||||
let isAsyncQuitting = false;
|
|
||||||
|
|
||||||
const doAsyncQuit = (event: Electron.Event, exitCode = 0) => {
|
|
||||||
if (isAsyncQuitting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isAsyncQuitting = true;
|
|
||||||
|
|
||||||
void (async () => {
|
|
||||||
try {
|
|
||||||
await runOnQuitOfBackEnd();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("A beforeQuitOfBackEnd failed!!!!", error);
|
|
||||||
exitCode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.exit(exitCode);
|
|
||||||
})();
|
|
||||||
};
|
|
||||||
|
|
||||||
app.on("will-quit", (event) => {
|
|
||||||
runAfterQuitOfFrontEnd();
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if (isIntegrationTesting || isAutoUpdating.get()) {
|
|
||||||
doAsyncQuit(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on("quit", (event, exitCode) => {
|
|
||||||
event.preventDefault();
|
|
||||||
doAsyncQuit(event, exitCode);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default setupRunnablesBeforeClosingOfApplicationInjectable;
|
|
||||||
@ -15,7 +15,6 @@ import setupDeepLinkingInjectable from "./electron-app/runnables/setup-deep-link
|
|||||||
import setupMainWindowVisibilityAfterActivationInjectable from "./electron-app/runnables/setup-main-window-visibility-after-activation.injectable";
|
import setupMainWindowVisibilityAfterActivationInjectable from "./electron-app/runnables/setup-main-window-visibility-after-activation.injectable";
|
||||||
import setupDeviceShutdownInjectable from "./electron-app/runnables/setup-device-shutdown.injectable";
|
import setupDeviceShutdownInjectable from "./electron-app/runnables/setup-device-shutdown.injectable";
|
||||||
import setupApplicationNameInjectable from "./electron-app/runnables/setup-application-name.injectable";
|
import setupApplicationNameInjectable from "./electron-app/runnables/setup-application-name.injectable";
|
||||||
import setupRunnablesBeforeClosingOfApplicationInjectable from "./electron-app/runnables/setup-runnables-before-closing-of-application.injectable";
|
|
||||||
import { runInAction } from "mobx";
|
import { runInAction } from "mobx";
|
||||||
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
|
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
|
||||||
import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable";
|
import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable";
|
||||||
@ -104,7 +103,6 @@ const overrideElectronFeatures = (di: DiContainer) => {
|
|||||||
setupDeviceShutdownInjectable,
|
setupDeviceShutdownInjectable,
|
||||||
setupDeepLinkingInjectable,
|
setupDeepLinkingInjectable,
|
||||||
setupApplicationNameInjectable,
|
setupApplicationNameInjectable,
|
||||||
setupRunnablesBeforeClosingOfApplicationInjectable,
|
|
||||||
].forEach((injectable) => {
|
].forEach((injectable) => {
|
||||||
di.override(injectable, () => ({
|
di.override(injectable, () => ({
|
||||||
id: injectable.id,
|
id: injectable.id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user