summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop-electron/src
diff options
context:
space:
mode:
authorBrendan Allan <[email protected]>2026-03-20 23:02:07 +0800
committerGitHub <[email protected]>2026-03-20 15:02:07 +0000
commitd0a57305efcf03f4fd69ca180d97ea85e6cb2f1d (patch)
treec4112592fa632f24544deab42e465b0e2c1d0ff6 /packages/desktop-electron/src
parent27a70ad70f30faf30d159f56b394c01f9474c7a4 (diff)
downloadopencode-d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d.tar.gz
opencode-d0a57305efcf03f4fd69ca180d97ea85e6cb2f1d.zip
app: file type filter on desktop + multiple files (#18403)
Diffstat (limited to 'packages/desktop-electron/src')
-rw-r--r--packages/desktop-electron/src/main/ipc.ts11
-rw-r--r--packages/desktop-electron/src/preload/types.ts2
-rw-r--r--packages/desktop-electron/src/renderer/index.tsx4
3 files changed, 16 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]
diff --git a/packages/desktop-electron/src/preload/types.ts b/packages/desktop-electron/src/preload/types.ts
index 100508fcd..f8e6d52c7 100644
--- a/packages/desktop-electron/src/preload/types.ts
+++ b/packages/desktop-electron/src/preload/types.ts
@@ -50,6 +50,8 @@ export type ElectronAPI = {
multiple?: boolean
title?: string
defaultPath?: string
+ accept?: string[]
+ extensions?: string[]
}) => Promise<string | string[] | null>
saveFilePicker: (opts?: { title?: string; defaultPath?: string }) => Promise<string | null>
openLink: (url: string) => void
diff --git a/packages/desktop-electron/src/renderer/index.tsx b/packages/desktop-electron/src/renderer/index.tsx
index 30e882e23..ec2b4d1e7 100644
--- a/packages/desktop-electron/src/renderer/index.tsx
+++ b/packages/desktop-electron/src/renderer/index.tsx
@@ -1,6 +1,8 @@
// @refresh reload
import {
+ ACCEPTED_FILE_EXTENSIONS,
+ ACCEPTED_FILE_TYPES,
AppBaseProviders,
AppInterface,
handleNotificationClick,
@@ -111,6 +113,8 @@ const createPlatform = (): Platform => {
const result = await window.api.openFilePicker({
multiple: opts?.multiple ?? false,
title: opts?.title ?? t("desktop.dialog.chooseFile"),
+ accept: opts?.accept ?? ACCEPTED_FILE_TYPES,
+ extensions: opts?.extensions ?? ACCEPTED_FILE_EXTENSIONS,
})
return handleWslPicker(result)
},