From d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Fri, 20 Mar 2026 23:02:07 +0800 Subject: app: file type filter on desktop + multiple files (#18403) --- packages/desktop-electron/src/main/ipc.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'packages/desktop-electron/src/main') diff --git a/packages/desktop-electron/src/main/ipc.ts b/packages/desktop-electron/src/main/ipc.ts index 71b3c3395..543f857a5 100644 --- a/packages/desktop-electron/src/main/ipc.ts +++ b/packages/desktop-electron/src/main/ipc.ts @@ -6,6 +6,11 @@ import type { InitStep, ServerReadyData, SqliteMigrationProgress, TitlebarTheme, import { getStore } from "./store" import { setTitlebar } from "./windows" +const pickerFilters = (ext?: string[]) => { + if (!ext || ext.length === 0) return undefined + return [{ name: "Files", extensions: ext }] +} + type Deps = { killSidecar: () => void installCli: () => Promise @@ -94,11 +99,15 @@ export function registerIpcHandlers(deps: Deps) { ipcMain.handle( "open-file-picker", - async (_event: IpcMainInvokeEvent, opts?: { multiple?: boolean; title?: string; defaultPath?: string }) => { + async ( + _event: IpcMainInvokeEvent, + opts?: { multiple?: boolean; title?: string; defaultPath?: string; accept?: string[]; extensions?: string[] }, + ) => { const result = await dialog.showOpenDialog({ properties: ["openFile", ...(opts?.multiple ? ["multiSelections" as const] : [])], title: opts?.title ?? "Choose a file", defaultPath: opts?.defaultPath, + filters: pickerFilters(opts?.extensions), }) if (result.canceled) return null return opts?.multiple ? result.filePaths : result.filePaths[0] -- cgit v1.2.3