1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+extensions/attempt-installs.injectable.ts
Sebastian Malton c2a359295b Fix extensions not being able to be installed in some cases
- Specifically, when an empty folder exists with the name that would be
  used to install it

- Make extensions and IPC more injected, so that
  ExtensionInstallationStateStore can be removed

- Add test to cover bug

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-02-10 09:43:11 -05:00

46 lines
1.5 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import attemptInstallInjectable from "./attempt-install/attempt-install.injectable";
import { readFileNotify } from "./read-file-notify/read-file-notify";
import path from "path";
import type { InstallRequest } from "./attempt-install/install-request";
import type { Disposer } from "../../utils";
import startPreInstallInjectable from "../../extensions/installation-state/start-pre-install.injectable";
interface Dependencies {
attemptInstall: (request: InstallRequest, disposer: Disposer) => Promise<void>;
startPreInstall: () => Disposer;
}
export const attemptInstalls = ({ attemptInstall, startPreInstall }: Dependencies) => (
async (filePaths: string[]): Promise<void> => {
const promises: Promise<void>[] = [];
const disposer = startPreInstall();
for (const filePath of filePaths) {
promises.push(
attemptInstall({
fileName: path.basename(filePath),
dataP: readFileNotify(filePath),
}, disposer),
);
}
await Promise.allSettled(promises);
}
);
const attemptInstallsInjectable = getInjectable({
instantiate: (di) => attemptInstalls({
attemptInstall: di.inject(attemptInstallInjectable),
startPreInstall: di.inject(startPreInstallInjectable),
}),
lifecycle: lifecycleEnum.singleton,
});
export default attemptInstallsInjectable;