merge fix/412-win32-open-external into dev(#412 Windows 在应用中打开:cmd start → rundll32 候选链,元字符 URL 跳过 cmd;全失败返回结构化错误并落到 UI 提示条,不再静默成功)

This commit is contained in:
Menghuan1918 committed 2026-10-05 23:17:33 +08:00
commit 235212e72a
9 files changed
+538 -72

No files matched your search

+25 -12
View File
@@ -100,6 +100,18 @@ function clampTreeWidth(value: number): number {
return Math.min(TREE_WIDTH_MAX, Math.max(TREE_WIDTH_MIN, Math.round(value)))
}
/** Whether one external-open call was accepted: a rejected launch is logged
* for diagnosis and answered `false`, so the caller can surface it. */
function accepted(pending: Promise<unknown>): Promise<boolean> {
return pending.then(
() => true,
(error: unknown) => {
console.error('open external failed', error)
return false
},
)
}
export function EditorHost(props: {
ctx: Context
store: SidebarStore
@@ -254,22 +266,23 @@ export function EditorHost(props: {
* manager, or hand the target's URL to its opener — local `file` URLs go
* to the host's external opener, while the SSH-remote form for
* VSCode-family editors launches on the browser/client machine (see
* api.openExternal). Failures are logged only — a missing handler is the
* OS's/browser's dialog, not a sidebar error. */
const openWith = (targetId: string, absolute: string): void => {
* api.openExternal).
*
* Answers whether the hand-off was accepted. The host route now reports a
* real failure when EVERY opener candidate fails (see
* `src/open-external.ts`) instead of the old silent `{ started: true }`, so
* a refusal is returned to the tree, which renders it — the log stays for
* diagnosis. A missing handler on the other machine is still the OS's or
* browser's own dialog. */
const openWith = (targetId: string, absolute: string): Promise<boolean> => {
const target = openWithTargets.find(item => item.id === targetId)
if (target === undefined) return
if (target === undefined) return Promise.resolve(false)
if (target.kind === 'reveal') {
void api.openExternal({ action: 'reveal', path: absolute }).catch(
(error: unknown) => { console.error('open external failed', error) },
)
return
return accepted(api.openExternal({ action: 'reveal', path: absolute }))
}
const url = openWithUrl(target, absolute, openWithConfig)
if (url === undefined) return
void api.openExternal({ action: 'url', url }).catch(
(error: unknown) => { console.error('open external failed', error) },
)
if (url === undefined) return Promise.resolve(false)
return accepted(api.openExternal({ action: 'url', url }))
}
/** Toggle one target's pinned state. The write is serialized (see
+13 -3
View File
@@ -481,8 +481,10 @@ export function FileTree(props: {
openWithPinned?: string[]
/** Whether the workspace is remote (appends the SSH hint to target labels). */
openWithSsh?: boolean
/** Open one plugin target externally (reveal or URL — the caller decides). */
onOpenWith?: (targetId: string, path: string) => void
/** Open one plugin target externally (reveal or URL — the caller decides).
* It answers `false` (or rejects) when the hand-off did not happen, and the
* strip then reports it exactly like the host-backed rows. */
onOpenWith?: (targetId: string, path: string) => void | boolean | Promise<void | boolean>
/** Toggle one plugin target's pinned state (the submenu row's pushpin). */
onToggleOpenWithPin?: (targetId: string) => void
/** Insert `@<relative path>` into the composer draft (file vs directory). */
@@ -2121,7 +2123,15 @@ export function FileTree(props: {
// The plugin's own targets share one id space (pinned rows and
// submenu children alike), so the caller gets the target id + path.
if (id.startsWith('open-with:')) {
onOpenWith?.(id.slice('open-with:'.length), target.path)
// The caller owns the launch and answers whether it was accepted;
// a refusal (or a rejection) means nothing opened, so the failure
// lands in the same strip as the host-backed rows instead of only
// reaching the console (#412 was silence in this exact spot).
const pending = onOpenWith?.(id.slice('open-with:'.length), target.path)
void Promise.resolve(pending).then(
(accepted) => { if (accepted === false) reportOpenFailure(target.path) },
() => { reportOpenFailure(target.path) },
)
return
}
if (id === 'reveal-in-file-manager') {
+3 -1
View File
@@ -69,7 +69,9 @@ export function TreePanel(props: {
openWithTargets?: OpenWithTarget[]
openWithPinned?: string[]
openWithSsh?: boolean
onOpenWith?: (targetId: string, path: string) => void
/** Open one plugin target (passed through to FileTree; `false`/rejection →
* the tree reports the failure in its strip). */
onOpenWith?: (targetId: string, path: string) => void | boolean | Promise<void | boolean>
onToggleOpenWithPin?: (targetId: string) => void
/** Show the plugin's own open-with targets even when the host lists local
* applications for the path (the `openWithPluginTargets` setting; passed