1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Remove another use of legacy requestOpenPathPicker

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-12-06 09:15:37 -05:00
parent 177d364d3f
commit a33b3cde73
2 changed files with 18 additions and 25 deletions

View File

@ -3,37 +3,30 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { requestOpenFilePickingDialog } from "../../ipc";
import { supportedExtensionFormats } from "./supported-extension-formats";
import attemptInstallsInjectable from "./attempt-installs.injectable";
import directoryForDownloadsInjectable from "../../../common/app-paths/directory-for-downloads/directory-for-downloads.injectable";
import openPathPickingDialogInjectable from "../../../features/path-picking-dialog/renderer/pick-paths.injectable";
interface Dependencies {
attemptInstalls: (filePaths: string[]) => Promise<void>;
directoryForDownloads: string;
}
const installFromSelectFileDialog = ({ attemptInstalls, directoryForDownloads }: Dependencies) => async () => {
const { canceled, filePaths } = await requestOpenFilePickingDialog({
defaultPath: directoryForDownloads,
properties: ["openFile", "multiSelections"],
message: `Select extensions to install (formats: ${supportedExtensionFormats.join(", ")}), `,
buttonLabel: "Use configuration",
filters: [{ name: "tarball", extensions: supportedExtensionFormats }],
});
if (!canceled) {
await attemptInstalls(filePaths);
}
};
export type InstallFromSelectFileDialog = () => Promise<void>;
const installFromSelectFileDialogInjectable = getInjectable({
id: "install-from-select-file-dialog",
instantiate: (di) => installFromSelectFileDialog({
attemptInstalls: di.inject(attemptInstallsInjectable),
directoryForDownloads: di.inject(directoryForDownloadsInjectable),
}),
instantiate: (di): InstallFromSelectFileDialog => {
const attemptInstalls = di.inject(attemptInstallsInjectable);
const directoryForDownloads = di.inject(directoryForDownloadsInjectable);
const openPathPickingDialog = di.inject(openPathPickingDialogInjectable);
return () => openPathPickingDialog({
defaultPath: directoryForDownloads,
properties: ["openFile", "multiSelections"],
message: `Select extensions to install (formats: ${supportedExtensionFormats.join(", ")}), `,
buttonLabel: "Use configuration",
filters: [{ name: "tarball", extensions: supportedExtensionFormats }],
onPick: attemptInstalls,
});
},
});
export default installFromSelectFileDialogInjectable;

View File

@ -14,8 +14,8 @@ import { Button } from "../button";
export interface PathPickOpts {
message: string;
onPick?: (paths: string[]) => any;
onCancel?: () => any;
onPick?: (paths: string[]) => void | Promise<void>;
onCancel?: () => void | Promise<void>;
defaultPath?: string;
buttonLabel?: string;
filters?: FileFilter[];