diff options
| author | Brendan Allan <[email protected]> | 2026-03-20 23:02:07 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-20 15:02:07 +0000 |
| commit | d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d (patch) | |
| tree | c4112592fa632f24544deab42e465b0e2c1d0ff6 /packages/desktop-electron/src/main | |
| parent | 27a70ad70f30faf30d159f56b394c01f9474c7a4 (diff) | |
| download | opencode-d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d.tar.gz opencode-d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d.zip | |
app: file type filter on desktop + multiple files (#18403)
Diffstat (limited to 'packages/desktop-electron/src/main')
| -rw-r--r-- | packages/desktop-electron/src/main/ipc.ts | 11 |
1 files changed, 10 insertions, 1 deletions
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<string> @@ -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] |
