diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 0d98427..fdc448b 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -80,9 +80,20 @@ function summarizeResult(toolName: string, result: Record): str } export async function setupIPC(): Promise { - ipcMain.handle('dialog:openFile', async (_, options?: { filters?: Array<{ name: string; extensions: string[] }> }) => { + ipcMain.handle('dialog:openFile', async (_, options?: { filters?: Array<{ name: string; extensions: string[] }>; properties?: string[]; multiple?: boolean }) => { + const dialogProperties: Array<'openFile' | 'multiSelections' | 'openDirectory'> = ['openFile']; + if (options?.multiple !== false && !options?.properties?.includes('openFile')) { + dialogProperties.push('multiSelections'); + } + if (options?.properties) { + for (const p of options.properties) { + if (p === 'multiSelections' && !dialogProperties.includes('multiSelections')) { + dialogProperties.push('multiSelections'); + } + } + } const result = await dialog.showOpenDialog(mainWindow!, { - properties: ['openFile', 'multiSelections'], + properties: dialogProperties, filters: options?.filters || [{ name: '所有文件', extensions: ['*'] }] }); if (result.canceled) return null; diff --git a/src/main/preload.ts b/src/main/preload.ts index 1bf739b..1ad5f5b 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -8,7 +8,7 @@ contextBridge.exposeInMainWorld('metonaDesktop', { isDesktop: true, info: () => ipcRenderer.invoke('app:info'), dialog: { - openFile: (filters?: unknown) => ipcRenderer.invoke('dialog:openFile', { filters }), + openFile: (options?: unknown) => ipcRenderer.invoke('dialog:openFile', options), saveFile: (options?: unknown) => ipcRenderer.invoke('dialog:saveFile', options) }, fs: { diff --git a/src/renderer/components/input-area.ts b/src/renderer/components/input-area.ts index 7bb557e..8142ca2 100644 --- a/src/renderer/components/input-area.ts +++ b/src/renderer/components/input-area.ts @@ -90,7 +90,9 @@ export function initInputArea(): void { const bridge = getBridge(); if (!bridge) return; const paths = await bridge.dialog.openFile({ - filters: [{ name: '图片', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'] }] + filters: [{ name: '图片', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'] }], + properties: ['openFile'], + multiple: false }); if (!paths || paths.length === 0) return; await handleImagePaths(paths); diff --git a/src/renderer/index.html b/src/renderer/index.html index a6dca93..2f0d2a1 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -413,11 +413,15 @@ @@ -426,7 +430,7 @@