experiment: better web picker using @pierre/tree (#31208)
This commit is contained in:
parent
25cb2be619
commit
88f5b9a90e
39 changed files with 1297 additions and 211 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { contextBridge, ipcRenderer } from "electron"
|
||||
import { contextBridge, ipcRenderer, webUtils } from "electron"
|
||||
import type { ElectronAPI, WslServersEvent } from "./types"
|
||||
import type { UpdaterState } from "@opencode-ai/app/updater"
|
||||
|
||||
|
|
@ -88,6 +88,7 @@ const api: ElectronAPI = {
|
|||
openFilePicker: (opts) => ipcRenderer.invoke("open-file-picker", opts),
|
||||
readPickedFile: (token, path) => ipcRenderer.invoke("read-picked-file", token, path),
|
||||
releasePickedFiles: (token) => ipcRenderer.invoke("release-picked-files", token),
|
||||
getPathForFile: (file) => webUtils.getPathForFile(file),
|
||||
saveFilePicker: (opts) => ipcRenderer.invoke("save-file-picker", opts),
|
||||
openLink: (url) => ipcRenderer.send("open-link", url),
|
||||
openPath: (path, app) => ipcRenderer.invoke("open-path", path, app),
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ export type ElectronAPI = {
|
|||
}) => Promise<{ token: string; files: { path: string; name: string; size: number }[] } | null>
|
||||
readPickedFile: (token: string, path: string) => Promise<ArrayBuffer>
|
||||
releasePickedFiles: (token: string) => Promise<void>
|
||||
getPathForFile: (file: File) => string
|
||||
saveFilePicker: (opts?: { title?: string; defaultPath?: string }) => Promise<string | null>
|
||||
openLink: (url: string) => void
|
||||
openPath: (path: string, app?: string) => Promise<void>
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ const listenForDeepLinks = () => {
|
|||
}
|
||||
|
||||
const createPlatform = (): Platform => {
|
||||
const attachmentPaths = new WeakMap<File, string>()
|
||||
const os = (() => {
|
||||
const ua = navigator.userAgent
|
||||
if (ua.includes("Mac")) return "macos"
|
||||
|
|
@ -153,13 +154,19 @@ const createPlatform = (): Platform => {
|
|||
if (!result) return
|
||||
try {
|
||||
for (const file of result.files) {
|
||||
await onFile(new File([await window.api.readPickedFile(result.token, file.path)], file.name))
|
||||
const selected = new File([await window.api.readPickedFile(result.token, file.path)], file.name)
|
||||
attachmentPaths.set(selected, file.path)
|
||||
await onFile(selected)
|
||||
}
|
||||
} finally {
|
||||
await window.api.releasePickedFiles(result.token)
|
||||
}
|
||||
},
|
||||
|
||||
getPathForFile(file) {
|
||||
return attachmentPaths.get(file) ?? window.api.getPathForFile(file)
|
||||
},
|
||||
|
||||
async saveFilePickerDialog(opts) {
|
||||
return window.api.saveFilePicker({
|
||||
title: opts?.title ?? t("desktop.dialog.saveFile"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue