diff options
| author | Marco Rodolfi <marco.rodolfi@tuta.io> | 2023-06-22 11:36:17 +0200 |
|---|---|---|
| committer | Marco Rodolfi <marco.rodolfi@tuta.io> | 2023-06-22 11:37:45 +0200 |
| commit | 388526d02d46720dd7942d0633d4688e89584449 (patch) | |
| tree | 0e4d674a24c2a44ff41086d56614dafa56734ec6 /frontend | |
| parent | cb65fb4b110b5ca2ce5f7597b93832622552997b (diff) | |
| download | decky-loader-388526d02d46720dd7942d0633d4688e89584449.tar.gz decky-loader-388526d02d46720dd7942d0633d4688e89584449.zip | |
Fix: add an API compatibility layer for the old file picker and change the new implementation as V2
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/src/components/modals/filepicker/index.tsx | 14 | ||||
| -rw-r--r-- | frontend/src/plugin-loader.tsx | 36 |
2 files changed, 47 insertions, 3 deletions
diff --git a/frontend/src/components/modals/filepicker/index.tsx b/frontend/src/components/modals/filepicker/index.tsx index de5af2db..102f813b 100644 --- a/frontend/src/components/modals/filepicker/index.tsx +++ b/frontend/src/components/modals/filepicker/index.tsx @@ -34,6 +34,7 @@ export interface FilePickerProps { allowAllFiles?: boolean; defaultHidden?: boolean; max?: number; + fileSelType?: FileSelectionType; onSubmit: (val: { path: string; realpath: string }) => void; closeModal?: () => void; } @@ -48,6 +49,12 @@ export interface File { created: number; } +export enum FileSelectionType { + FILE, + FOLDER, + NONE, +} + interface FileListing { realpath: string; files: File[]; @@ -127,6 +134,7 @@ const FilePicker: FunctionComponent<FilePickerProps> = ({ allowAllFiles = true, defaultHidden = false, // false by default makes sense for most users max = 1000, + fileSelType = FileSelectionType.NONE, onSubmit, closeModal, }) => { @@ -327,7 +335,7 @@ const FilePicker: FunctionComponent<FilePickerProps> = ({ </Focusable> </DialogControlsSection> </DialogBody> - {!loading && error === FileErrorTypes.None && !includeFiles && ( + {!loading && error === FileErrorTypes.None && fileSelType !== FileSelectionType.NONE && ( <DialogFooter> <DialogButton className="Primary" @@ -337,7 +345,9 @@ const FilePicker: FunctionComponent<FilePickerProps> = ({ closeModal?.(); }} > - {t('FilePickerIndex.folder.select')} + {fileSelType === FileSelectionType.FILE + ? t('FilePickerIndex.file.select') + : t('FilePickerIndex.folder.select')} </DialogButton> </DialogFooter> )} diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index c4063557..8190fbc4 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -14,7 +14,7 @@ import { FaExclamationCircle, FaPlug } from 'react-icons/fa'; import { DeckyState, DeckyStateContextProvider, UserInfo, useDeckyState } from './components/DeckyState'; import LegacyPlugin from './components/LegacyPlugin'; -import { File } from './components/modals/filepicker'; +import { File, FileSelectionType } from './components/modals/filepicker'; import { deinitFilepickerPatches, initFilepickerPatches } from './components/modals/filepicker/patches'; import MultiplePluginsInstallModal from './components/modals/MultiplePluginsInstallModal'; import PluginInstallModal from './components/modals/PluginInstallModal'; @@ -361,6 +361,38 @@ class PluginLoader extends Logger { openFilePicker( startPath: string, + selectFiles?: boolean, + regex?: RegExp, + ): Promise<{ path: string; realpath: string }> { + if (selectFiles) { + return this.openFilePickerV2( + startPath, + true, + regex, + true, + undefined, + undefined, + undefined, + undefined, + FileSelectionType.FILE, + ); + } else { + return this.openFilePickerV2( + startPath, + false, + regex, + true, + undefined, + undefined, + undefined, + undefined, + FileSelectionType.FOLDER, + ); + } + } + + openFilePickerV2( + startPath: string, includeFiles?: boolean, filter?: RegExp | ((file: File) => boolean), includeFolders?: boolean, @@ -368,6 +400,7 @@ class PluginLoader extends Logger { showHiddenFiles?: boolean, allowAllFiles?: boolean, max?: number, + select?: FileSelectionType, ): Promise<{ path: string; realpath: string }> { return new Promise((resolve, reject) => { const Content = ({ closeModal }: { closeModal?: () => void }) => ( @@ -389,6 +422,7 @@ class PluginLoader extends Logger { defaultHidden={showHiddenFiles} onSubmit={resolve} closeModal={closeModal} + fileSelType={select} max={max} /> </WithSuspense> |
