diff --git a/web/src/apps/registry.ts b/web/src/apps/registry.ts index 0cf3cd5..239512b 100644 --- a/web/src/apps/registry.ts +++ b/web/src/apps/registry.ts @@ -26,6 +26,10 @@ export function getAppsForEntry(entry: VfsEntry): AppDescriptor[] { return apps.filter(a => a.supported(entry)); } +export function getAppByKey(key: string): AppDescriptor | undefined { + return apps.find(a => a.key === key); +} + export function getDefaultAppForEntry(entry: VfsEntry): AppDescriptor | undefined { if (entry.is_dir) return; const ext = entry.name.split('.').pop()?.toLowerCase() || ''; diff --git a/web/src/pages/FileExplorerPage/FileExplorerPage.tsx b/web/src/pages/FileExplorerPage/FileExplorerPage.tsx index f862c48..a6233c7 100644 --- a/web/src/pages/FileExplorerPage/FileExplorerPage.tsx +++ b/web/src/pages/FileExplorerPage/FileExplorerPage.tsx @@ -132,7 +132,7 @@ const FileExplorerPage = memo(function FileExplorerPage() { onRowClick={(r, e) => handleSelect(r, e.ctrlKey || e.metaKey)} onSelectionChange={setSelectedEntries} onOpen={handleOpenEntry} - onOpenWith={(entry, appKey) => confirmOpenWithApp(entry, { key: appKey, name: '' } as any)} + onOpenWith={(entry, appKey) => confirmOpenWithApp(entry, appKey)} onRename={setRenaming} onDelete={(entry) => doDelete([entry])} onContextMenu={openContextMenu} @@ -192,7 +192,7 @@ const FileExplorerPage = memo(function FileExplorerPage() { processorTypes={processorTypes} onClose={closeContextMenus} onOpen={handleOpenEntry} - onOpenWith={(entry, appKey) => confirmOpenWithApp(entry, { key: appKey, name: '' } as any)} + onOpenWith={(entry, appKey) => confirmOpenWithApp(entry, appKey)} onDownload={doDownload} onRename={setRenaming} onDelete={(entriesToDelete) => doDelete(entriesToDelete)} diff --git a/web/src/pages/FileExplorerPage/hooks/useAppWindows.tsx b/web/src/pages/FileExplorerPage/hooks/useAppWindows.tsx index 699ee1d..5689d6b 100644 --- a/web/src/pages/FileExplorerPage/hooks/useAppWindows.tsx +++ b/web/src/pages/FileExplorerPage/hooks/useAppWindows.tsx @@ -3,7 +3,7 @@ import { Modal, Checkbox } from 'antd'; import type { VfsEntry } from '../../../api/client'; import type { AppDescriptor } from '../../../apps/registry'; import type { AppWindow } from '../types'; -import { getAppsForEntry, getDefaultAppForEntry } from '../../../apps/registry'; +import { getAppsForEntry, getDefaultAppForEntry, getAppByKey } from '../../../apps/registry'; export function useAppWindows(path: string) { const [appWindows, setAppWindows] = useState([]); @@ -47,7 +47,12 @@ export function useAppWindows(path: string) { openWithApp(entry, defaultApp); }, [openWithApp]); - const confirmOpenWithApp = useCallback((entry: VfsEntry, app: AppDescriptor) => { + const confirmOpenWithApp = useCallback((entry: VfsEntry, appKey: string) => { + const app = getAppByKey(appKey); + if (!app) { + Modal.error({ title: '错误', content: `应用 "${appKey}" 不存在。` }); + return; + } const ext = entry.name.split('.').pop()?.toLowerCase() || ''; let setDefault = false; Modal.confirm({