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:
parent
177d364d3f
commit
a33b3cde73
@ -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;
|
||||
|
||||
@ -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[];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user