diff options
| author | AAGaming <aa@mail.catvibers.me> | 2023-08-05 01:11:43 -0400 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2023-11-14 00:04:56 +0200 |
| commit | 34d1a34b10f4386865f3c241c5ae4026d2bfd8bd (patch) | |
| tree | d9560bceecd2cb3d0a2b89d9f75bc29a7dfdc3dd /frontend/src/components | |
| parent | cfb6fe69e3f111de0d75a9d90e570bac392e1ee3 (diff) | |
| download | decky-loader-34d1a34b10f4386865f3c241c5ae4026d2bfd8bd.tar.gz decky-loader-34d1a34b10f4386865f3c241c5ae4026d2bfd8bd.zip | |
Migrate most of frontend callServerMethod usage over to websocket
Diffstat (limited to 'frontend/src/components')
4 files changed, 53 insertions, 58 deletions
diff --git a/frontend/src/components/modals/PluginUninstallModal.tsx b/frontend/src/components/modals/PluginUninstallModal.tsx index e7ecbc99..e9c243b6 100644 --- a/frontend/src/components/modals/PluginUninstallModal.tsx +++ b/frontend/src/components/modals/PluginUninstallModal.tsx @@ -1,6 +1,8 @@ import { ConfirmModal } from 'decky-frontend-lib'; import { FC } from 'react'; +import { uninstallPlugin } from '../../plugin'; + interface PluginUninstallModalProps { name: string; title: string; @@ -14,7 +16,7 @@ const PluginUninstallModal: FC<PluginUninstallModalProps> = ({ name, title, butt <ConfirmModal closeModal={closeModal} onOK={async () => { - await window.DeckyPluginLoader.callServerMethod('uninstall_plugin', { name }); + await uninstallPlugin(name); // uninstalling a plugin resets the hidden setting for it server-side // we invalidate here so if you re-install it, you won't have an out-of-date hidden filter await window.DeckyPluginLoader.hiddenPluginsService.invalidate(); diff --git a/frontend/src/components/modals/filepicker/index.tsx b/frontend/src/components/modals/filepicker/index.tsx index c4e72d95..2dfa3ccd 100644 --- a/frontend/src/components/modals/filepicker/index.tsx +++ b/frontend/src/components/modals/filepicker/index.tsx @@ -95,29 +95,20 @@ const sortOptions = [ }, ]; -function getList( - path: string, - includeFiles: boolean, - includeFolders: boolean = true, - includeExt: string[] | null = null, - includeHidden: boolean = false, - orderBy: SortOptions = SortOptions.name_desc, - filterFor: RegExp | ((file: File) => boolean) | null = null, - pageNumber: number = 1, - max: number = 1000, -): Promise<{ result: FileListing | string; success: boolean }> { - return window.DeckyPluginLoader.callServerMethod('filepicker_ls', { - path, - include_files: includeFiles, - include_folders: includeFolders, - include_ext: includeExt ? includeExt : [], - include_hidden: includeHidden, - order_by: orderBy, - filter_for: filterFor, - page: pageNumber, - max: max, - }); -} +const getList = window.DeckyBackend.callable< + [ + path: string, + includeFiles?: boolean, + includeFolders?: boolean, + includeExt?: string[] | null, + includeHidden?: boolean, + orderBy?: SortOptions, + filterFor?: RegExp | ((file: File) => boolean) | null, + pageNumber?: number, + max?: number, + ], + FileListing +>('utilities/filepicker_ls'); const iconStyles = { paddingRight: '10px', @@ -126,20 +117,20 @@ const iconStyles = { const FilePicker: FunctionComponent<FilePickerProps> = ({ startPath, - //What are we allowing to show in the file picker + // What are we allowing to show in the file picker includeFiles = true, includeFolders = true, - //Parameter for specifying a specific filename match + // Parameter for specifying a specific filename match filter = undefined, - //Filter for specific extensions as an array + // Filter for specific extensions as an array validFileExtensions = undefined, - //Allow to override the fixed extension above + // Allow to override the fixed extension above allowAllFiles = true, - //If we need to show hidden files and folders (both Win and Linux should work) + // If we need to show hidden files and folders (both Win and Linux should work) defaultHidden = false, // false by default makes sense for most users - //How much files per page to show, default 1000 + // How many files per page to show, default 1000 max = 1000, - //Which picking option to select by default + // Which picking option to select by default fileSelType = FileSelectionType.FOLDER, onSubmit, closeModal, @@ -190,21 +181,27 @@ const FilePicker: FunctionComponent<FilePickerProps> = ({ useEffect(() => { (async () => { setLoading(true); - const listing = await getList( - path, - includeFiles, - includeFolders, - selectedExts, - showHidden, - sort, - filter, - page, - max, - ); - if (!listing.success) { + try { + const listing = await getList( + path, + includeFiles, + includeFolders, + selectedExts, + showHidden, + sort, + filter, + page, + max, + ); + setRawError(null); + setError(FileErrorTypes.None); + setFiles(listing.files); + setLoading(false); + setListing(listing); + logger.log('reloaded', path, listing); + } catch (theError: any) { setListing({ files: [], realpath: path, total: 0 }); setLoading(false); - const theError = listing.result as string; switch (theError) { case theError.match(/\[Errno\s2.*/i)?.input: case theError.match(/\[WinError\s3.*/i)?.input: @@ -220,14 +217,7 @@ const FilePicker: FunctionComponent<FilePickerProps> = ({ } logger.debug(theError); return; - } else { - setRawError(null); - setError(FileErrorTypes.None); - setFiles((listing.result as FileListing).files); } - setLoading(false); - setListing(listing.result as FileListing); - logger.log('reloaded', path, listing); })(); }, [error, path, includeFiles, includeFolders, showHidden, sort, selectedExts, page]); diff --git a/frontend/src/components/settings/pages/developer/index.tsx b/frontend/src/components/settings/pages/developer/index.tsx index 5ed76515..36d3b5c0 100644 --- a/frontend/src/components/settings/pages/developer/index.tsx +++ b/frontend/src/components/settings/pages/developer/index.tsx @@ -91,13 +91,16 @@ export default function DeveloperSettings() { > <DialogButton onClick={async () => { - let res = await window.DeckyPluginLoader.callServerMethod('get_tab_id', { name: 'SharedJSContext' }); - if (res.success) { + try { + let tabId = await window.DeckyBackend.call<[name: string], string>( + 'utilities/get_tab_id', + 'SharedJSContext', + ); Navigation.NavigateToExternalWeb( - 'localhost:8080/devtools/inspector.html?ws=localhost:8080/devtools/page/' + res.result, + 'localhost:8080/devtools/inspector.html?ws=localhost:8080/devtools/page/' + tabId, ); - } else { - console.error('Unable to find ID for SharedJSContext tab ', res.result); + } catch (e) { + console.error('Unable to find ID for SharedJSContext tab ', e); Navigation.NavigateToExternalWeb('localhost:8080'); } }} diff --git a/frontend/src/components/settings/pages/general/RemoteDebugging.tsx b/frontend/src/components/settings/pages/general/RemoteDebugging.tsx index 60d57d91..60e0e3c1 100644 --- a/frontend/src/components/settings/pages/general/RemoteDebugging.tsx +++ b/frontend/src/components/settings/pages/general/RemoteDebugging.tsx @@ -18,8 +18,8 @@ export default function RemoteDebuggingSettings() { value={allowRemoteDebugging || false} onChange={(toggleValue) => { setAllowRemoteDebugging(toggleValue); - if (toggleValue) window.DeckyPluginLoader.callServerMethod('allow_remote_debugging'); - else window.DeckyPluginLoader.callServerMethod('disallow_remote_debugging'); + if (toggleValue) window.DeckyBackend.call('allow_remote_debugging'); + else window.DeckyBackend.call('disallow_remote_debugging'); }} /> </Field> |
