Merge pull request #522 from wang-kaopu/fix/517-client-ssh-open
fix(editor): open SSH remote editor links on the client
This commit is contained in:
@@ -192,10 +192,11 @@ export function EditorHost(props: {
|
||||
}
|
||||
|
||||
/** The context menu's "open with" action: reveal the path in the OS file
|
||||
* manager, or hand the target's URL (a local `file` URL, or the SSH-remote
|
||||
* form for VSCode-family editors in remote mode) to the host's external
|
||||
* opener. Failures are logged only — a missing handler is the OS's
|
||||
* dialog, not a sidebar error. */
|
||||
* 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 => {
|
||||
const target = openWithTargets.find(item => item.id === targetId)
|
||||
if (target === undefined) return
|
||||
|
||||
+49
-6
@@ -216,6 +216,51 @@ function gitPayload(scope: SessionScope, worktree: string | undefined, extra: Re
|
||||
return scopePayload(scope, { ...(worktree !== undefined && worktree !== '' ? { worktree } : {}), ...extra })
|
||||
}
|
||||
|
||||
/** One external-open request from the file tree. */
|
||||
type OpenExternalPayload =
|
||||
| { action: 'reveal'; path: string }
|
||||
| { action: 'url'; url: string }
|
||||
|
||||
/** The host route's success shape. */
|
||||
type OpenExternalResult = { started: boolean }
|
||||
|
||||
/**
|
||||
* Remote VSCode-family URLs must be consumed on the browser/client machine:
|
||||
* the DSH host can be a headless remote server with no editor or DISPLAY.
|
||||
* Local editor URLs and reveal actions still belong to the host opener.
|
||||
*/
|
||||
function shouldOpenExternalOnClient(payload: OpenExternalPayload): payload is { action: 'url'; url: string } {
|
||||
if (payload.action !== 'url') return false
|
||||
let parsed: URL
|
||||
try {
|
||||
parsed = new URL(payload.url)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
return parsed.protocol !== 'http:'
|
||||
&& parsed.protocol !== 'https:'
|
||||
&& parsed.hostname === 'vscode-remote'
|
||||
&& parsed.pathname.startsWith('/ssh-remote+')
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an external-open request to the correct machine. SSH remote-editor
|
||||
* URLs stay in the synchronous user-click chain and navigate the client so
|
||||
* its registered vscode:// / cursor:// handler can launch. Everything else
|
||||
* keeps using the DSH host route.
|
||||
*/
|
||||
function openExternal(payload: OpenExternalPayload): Promise<OpenExternalResult> {
|
||||
if (!shouldOpenExternalOnClient(payload)) {
|
||||
return call<OpenExternalResult>('open.external', payload)
|
||||
}
|
||||
try {
|
||||
window.location.assign(payload.url)
|
||||
return Promise.resolve({ started: true })
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
/** The sidebar API surface (session scope threaded through every call). */
|
||||
export const api = {
|
||||
sessionCwd: (scope: SessionScope, signal?: AbortSignal) =>
|
||||
@@ -350,12 +395,10 @@ export const api = {
|
||||
* check; see the host's browser.probe route). */
|
||||
browserProbe: (url: string, signal?: AbortSignal) =>
|
||||
call<BrowserProbeResult>('browser.probe', { url }, signal),
|
||||
/** External open for the file tree's "open with" menu: reveal a path in
|
||||
* the OS file manager, or hand a custom-scheme URL (vscode://, cursor://,
|
||||
* zed://, custom editors) to its registered handler. The host launches
|
||||
* the platform opener (argv, no shell). */
|
||||
openExternal: (payload: { action: 'reveal'; path: string } | { action: 'url'; url: string }) =>
|
||||
call<{ started: boolean }>('open.external', payload),
|
||||
/** External open for the file tree's "open with" menu. Remote SSH editor
|
||||
* URLs are launched on the browser/client machine; reveal and local URLs
|
||||
* keep using the host's platform opener. */
|
||||
openExternal,
|
||||
}
|
||||
|
||||
/** Absolute URL of the media route for one path (images only). */
|
||||
|
||||
Reference in New Issue
Block a user