Switch to using abstraction for getting absolute path to control explicit side effect

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2022-03-31 15:13:34 +03:00
1 parent 5ca3082572
commit 911481ea0f
11 files changed
+50 -29

No files matched your search

@@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import directoryForLensLocalStorageInjectable from "../../../common/directory-for-lens-local-storage/directory-for-lens-local-storage.injectable";
import { initIpcMainHandlers } from "./init-ipc-main-handlers";
import getAppMenuItemsInjectable from "../../menu/get-app-menu-items.injectable";
import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable";
const initIpcMainHandlersInjectable = getInjectable({
id: "init-ipc-main-handlers",
@@ -13,6 +14,7 @@ const initIpcMainHandlersInjectable = getInjectable({
instantiate: (di) => initIpcMainHandlers({
getAppMenuItems: () => di.inject(getAppMenuItemsInjectable)(),
directoryForLensLocalStorage: di.inject(directoryForLensLocalStorageInjectable),
getAbsolutePath: di.inject(getAbsolutePathInjectable),
}),
});
@@ -14,7 +14,6 @@ import { catalogEntityRegistry } from "../../catalog";
import { pushCatalogToRenderer } from "../../catalog-pusher";
import { ClusterManager } from "../../cluster-manager";
import { ResourceApplier } from "../../resource-applier";
import path from "path";
import { remove } from "fs-extra";
import { onLocationChange, handleWindowAction } from "../../ipc/window";
import { openFilePickingDialogChannel } from "../../../common/ipc/dialog";
@@ -23,13 +22,15 @@ import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppM
import { getNativeColorTheme } from "../../native-theme";
import { getNativeThemeChannel } from "../../../common/ipc/native-theme";
import type { MenuItemsOpts } from "../../menu/get-app-menu-items.injectable";
import type { GetAbsolutePath } from "../../../common/path/get-absolute-path.injectable";
interface Dependencies {
getAppMenuItems: () => MenuItemsOpts[];
directoryForLensLocalStorage: string;
getAbsolutePath: GetAbsolutePath;
}
export const initIpcMainHandlers = ({ getAppMenuItems, directoryForLensLocalStorage }: Dependencies) => () => {
export const initIpcMainHandlers = ({ getAppMenuItems, directoryForLensLocalStorage, getAbsolutePath }: Dependencies) => () => {
ipcMainHandle(clusterActivateHandler, (event, clusterId: ClusterId, force = false) => {
return ClusterStore.getInstance()
.getById(clusterId)
@@ -85,7 +86,7 @@ export const initIpcMainHandlers = ({ getAppMenuItems, directoryForLensLocalStor
try {
// remove the local storage file
const localStorageFilePath = path.resolve(directoryForLensLocalStorage, `${cluster.id}.json`);
const localStorageFilePath = getAbsolutePath(directoryForLensLocalStorage, `${cluster.id}.json`);
await remove(localStorageFilePath);
} catch {