mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-06 18:22:44 +08:00
feat(app): Refactor app opening logic to prevent runtime errors
This commit is contained in:
@@ -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() || '';
|
||||
|
||||
@@ -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)}
|
||||
|
||||
@@ -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<AppWindow[]>([]);
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user