chore: Replace all uses of stopServicesAndExitApp with requestQuitOfApp

- Also updated tests with new behaviour

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-04-12 15:15:36 -04:00
1 parent 4ff3186ca7
commit 2c4a7ecfb4
8 files changed
+43 -110

No files matched your search

@@ -6,16 +6,17 @@
import { kebabCase } from "lodash";
import { getGlobalOverride } from "@k8slens/test-utils";
import electronAppInjectable from "./electron-app.injectable";
import EventEmitter from "events";
export default getGlobalOverride(electronAppInjectable, () => {
const commandLineArgs: string[] = [];
const chromiumArgs = new Map<string, string | undefined>();
const appPaths = new Map<string, string>();
const app = ({
const app = (new EventEmitter(), {
getVersion: () => "6.0.0",
setLoginItemSettings: () => { },
on: () => app,
quit: () => {},
whenReady: async () => {},
getPath: (name) => appPaths.get(name) ?? `/some-directory-for-${kebabCase(name)}`,
setPath: (name, value) => appPaths.set(name, value),
@@ -0,0 +1,17 @@
/**
* 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 electronAppInjectable from "../electron-app.injectable";
const requestQuitOfAppInjectable = getInjectable({
id: "request-quit-of-app",
instantiate: (di) => {
const app = di.inject(electronAppInjectable);
return () => app.quit();
},
});
export default requestQuitOfAppInjectable;
@@ -1,20 +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 { applicationWindowInjectionToken } from "../application-window/application-window-injection-token";
const closeAllWindowsInjectable = getInjectable({
id: "close-all-windows",
instantiate: (di) => () => {
const lensWindows = di.injectMany(applicationWindowInjectionToken);
lensWindows.forEach((lensWindow) => {
lensWindow.close();
});
},
});
export default closeAllWindowsInjectable;
@@ -1,23 +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 forceAppExitInjectable from "./electron-app/features/force-app-exit.injectable";
import emitAppEventInjectable from "../common/app-event-bus/emit-event.injectable";
const stopServicesAndExitAppInjectable = getInjectable({
id: "stop-services-and-exit-app",
instantiate: (di) => {
const forceAppExit = di.inject(forceAppExitInjectable);
const emitAppEvent = di.inject(emitAppEventInjectable);
return async () => {
emitAppEvent({ name: "service", action: "close" });
setTimeout(forceAppExit, 1000);
};
},
});
export default stopServicesAndExitAppInjectable;
@@ -5,37 +5,20 @@
import { getInjectable } from "@ogre-tools/injectable";
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
import { computed } from "mobx";
import stopServicesAndExitAppInjectable from "../../../stop-services-and-exit-app.injectable";
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
import { pipeline } from "@ogre-tools/fp";
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
import requestQuitOfAppInjectable from "../../../electron-app/features/require-quit.injectable";
const quitAppTrayItemInjectable = getInjectable({
id: "quit-app-tray-item",
instantiate: (di) => {
const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable);
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
return {
id: "quit-app",
parentId: null,
orderNumber: 150,
label: computed(() => "Quit App"),
enabled: computed(() => true),
visible: computed(() => true),
click: pipeline(
stopServicesAndExitApp,
withErrorLoggingFor(() => "[TRAY]: Quitting application failed."),
// TODO: Find out how to improve typing so that instead of
// x => withErrorSuppression(x) there could only be withErrorSuppression
(x) => withErrorSuppression(x),
),
};
},
instantiate: (di) => ({
id: "quit-app",
parentId: null,
orderNumber: 150,
label: computed(() => "Quit App"),
enabled: computed(() => true),
visible: computed(() => true),
click: di.inject(requestQuitOfAppInjectable),
}),
injectionToken: trayMenuItemInjectionToken,
});