1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/electron-app/before-application-is-ready/setup-runnables-before-closing-of-application.injectable.ts
Iku-turso 57a1677c48
Consolidate runnables related to Electron
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2022-05-11 08:25:32 +03:00

60 lines
2.2 KiB
TypeScript

/**
* 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 { beforeApplicationIsReadyInjectionToken } from "../../start-main-application/before-application-is-ready/before-application-is-ready-injection-token";
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/before-quit-of-front-end/before-quit-of-front-end-injection-token";
import { runManyFor } from "../../start-main-application/run-many-for";
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/before-quit-of-back-end/before-quit-of-back-end-injection-token";
import electronAppInjectable from "../electron-app.injectable";
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
import autoUpdaterInjectable from "../features/auto-updater.injectable";
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
id: "setup-closing-of-application",
instantiate: (di) => {
const runMany = runManyFor(di);
const runRunnablesBeforeQuitOfFrontEnd = runMany(
beforeQuitOfFrontEndInjectionToken,
);
const runRunnablesBeforeQuitOfBackEnd = runMany(
beforeQuitOfBackEndInjectionToken,
);
return {
run: () => {
const app = di.inject(electronAppInjectable);
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
const autoUpdater = di.inject(autoUpdaterInjectable);
let isAutoUpdating = false;
autoUpdater.on("before-quit-for-update", () => {
isAutoUpdating = true;
});
app.on("will-quit", async ({ preventDefault: cancelNativeQuit }) => {
await runRunnablesBeforeQuitOfFrontEnd();
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
if (shouldQuitBackEnd) {
await runRunnablesBeforeQuitOfBackEnd();
} else {
cancelNativeQuit();
}
});
},
};
},
injectionToken: beforeApplicationIsReadyInjectionToken,
});
export default setupRunnablesBeforeClosingOfApplicationInjectable;