1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/app-paths/get-electron-app-path/get-electron-app-path.injectable.ts
Sebastian Malton 5b505e339d Remove need to override lensLocalStoragePath in tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-01-05 13:29:10 -05:00

32 lines
901 B
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 type { PathName } from "../../../common/app-paths/app-path-names";
import electronAppInjectable from "../../electron-app/electron-app.injectable";
export type GetElectronAppPath = (name: PathName | "currentApp") => string;
const getElectronAppPathInjectable = getInjectable({
id: "get-electron-app-path",
instantiate: (di): GetElectronAppPath => {
const electronApp = di.inject(electronAppInjectable);
return (name) => {
try {
if (name === "currentApp") {
return electronApp.getAppPath();
}
return electronApp.getPath(name);
} catch (e) {
return "";
}
};
},
});
export default getElectronAppPathInjectable;