dsh-remote-vs 0.13.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +455 -443
- package/README.md +408 -396
- package/lib/client.js +8062 -2651
- package/lib/index.js +1058 -288
- package/lib/p2-router-fs.js +1 -1
- package/lib/p2-router-refs.js +89 -10
- package/lib/p2-router-spill.js +73 -1
- package/lib/p2-router-subprocess.js +18 -6
- package/lib/spill-retention-BwKEWrl5.js +115 -0
- package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
- package/lib/types/archive.d.ts +1 -1
- package/lib/types/changes/recorder.d.ts +34 -2
- package/lib/types/client/CodeEditor.d.ts +12 -0
- package/lib/types/client/ConnectionStatus.d.ts +17 -0
- package/lib/types/client/DirectoryFlow.d.ts +2 -0
- package/lib/types/client/DoctorPanel.d.ts +25 -0
- package/lib/types/client/QuickOpen.d.ts +17 -0
- package/lib/types/client/RemoteExplorer.d.ts +192 -1
- package/lib/types/client/RemoteRoot.d.ts +17 -0
- package/lib/types/client/SearchView.d.ts +55 -0
- package/lib/types/client/TerminalView.d.ts +38 -0
- package/lib/types/client/WorkspaceWizard.d.ts +17 -0
- package/lib/types/client/api.d.ts +54 -4
- package/lib/types/client/changes/undo-affordance.d.ts +16 -0
- package/lib/types/client/changes/undo-context.d.ts +14 -18
- package/lib/types/client/changes/undo-target.d.ts +78 -0
- package/lib/types/client/connection.d.ts +111 -0
- package/lib/types/client/doctor.d.ts +122 -0
- package/lib/types/client/download.d.ts +35 -5
- package/lib/types/client/downloads.d.ts +18 -1
- package/lib/types/client/file-open-probe.d.ts +64 -0
- package/lib/types/client/i18n.d.ts +1 -1
- package/lib/types/client/quickopen-model.d.ts +332 -0
- package/lib/types/client/scm/DiffView.d.ts +34 -0
- package/lib/types/client/scm/actions.d.ts +18 -0
- package/lib/types/client/scm/diff-model.d.ts +17 -1
- package/lib/types/client/scm/git-cache.d.ts +10 -2
- package/lib/types/client/scm/read-queue.d.ts +2 -1
- package/lib/types/client/scm/stage-queue.d.ts +13 -0
- package/lib/types/client/scm/status-map.d.ts +3 -1
- package/lib/types/client/store.d.ts +114 -5
- package/lib/types/client/vsc/FindWidget.d.ts +7 -0
- package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
- package/lib/types/deploy.d.ts +44 -2
- package/lib/types/git-format.d.ts +15 -0
- package/lib/types/http.d.ts +44 -0
- package/lib/types/p2/file-refs.d.ts +39 -2
- package/lib/types/p2/helper-rpc.d.ts +26 -0
- package/lib/types/p2/router-spill.d.ts +19 -0
- package/lib/types/p2/router-subprocess.d.ts +2 -0
- package/lib/types/p2/spill-retention.d.ts +74 -0
- package/lib/types/p2/worlds.d.ts +11 -0
- package/lib/types/pool.d.ts +73 -11
- package/lib/types/protocol.d.ts +63 -0
- package/lib/types/routes.d.ts +18 -0
- package/lib/types/sftp.d.ts +114 -8
- package/lib/types/store.d.ts +34 -0
- package/lib/types/timeouts.d.ts +14 -0
- package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
- package/package.json +1 -1
- package/src/archive.ts +41 -9
- package/src/changes/recorder.ts +227 -31
- package/src/changes/status.ts +37 -1
- package/src/client/CodeEditor.tsx +84 -2
- package/src/client/ConnectionStatus.tsx +130 -0
- package/src/client/DirectoryFlow.tsx +40 -5
- package/src/client/DoctorPanel.tsx +202 -0
- package/src/client/DownloadDock.tsx +13 -25
- package/src/client/EditorPane.tsx +291 -7
- package/src/client/HostsView.tsx +17 -8
- package/src/client/QuickOpen.tsx +371 -0
- package/src/client/RemoteDirectoryPicker.tsx +54 -3
- package/src/client/RemoteExplorer.tsx +879 -160
- package/src/client/RemoteRoot.tsx +178 -1
- package/src/client/SearchView.tsx +180 -6
- package/src/client/SettingsHosts.tsx +1 -1
- package/src/client/TerminalView.tsx +174 -9
- package/src/client/WorkspaceWizard.tsx +110 -16
- package/src/client/WorkspacesView.tsx +22 -6
- package/src/client/api.ts +197 -11
- package/src/client/changes/ChangesDock.tsx +35 -8
- package/src/client/changes/undo-affordance.ts +33 -0
- package/src/client/changes/undo-context.ts +14 -18
- package/src/client/changes/undo-target.ts +139 -0
- package/src/client/connection.ts +264 -0
- package/src/client/doctor.ts +441 -0
- package/src/client/download.ts +148 -12
- package/src/client/downloads.ts +43 -2
- package/src/client/file-open-probe.ts +83 -0
- package/src/client/i18n.ts +244 -0
- package/src/client/index.tsx +5 -2
- package/src/client/quickopen-model.ts +778 -0
- package/src/client/remote-file-open.ts +21 -33
- package/src/client/scm/DiffView.tsx +116 -6
- package/src/client/scm/ScmPanel.tsx +19 -0
- package/src/client/scm/actions.ts +34 -2
- package/src/client/scm/diff-model.ts +33 -37
- package/src/client/scm/git-cache.ts +61 -4
- package/src/client/scm/read-queue.ts +33 -2
- package/src/client/scm/stage-queue.ts +72 -1
- package/src/client/scm/status-map.ts +22 -1
- package/src/client/store.tsx +704 -21
- package/src/client/vsc/FindWidget.tsx +20 -0
- package/src/client/vsc/kit.tsx +115 -6
- package/src/client/vsc/reveal-line.ts +33 -14
- package/src/client/vsc/save-shortcut.ts +131 -0
- package/src/client/vsc/vsc.css +419 -0
- package/src/deploy.ts +185 -33
- package/src/git-format.ts +136 -22
- package/src/git-ops.ts +14 -6
- package/src/http.ts +80 -12
- package/src/importers.ts +80 -21
- package/src/index.ts +21 -1
- package/src/p2/file-refs.ts +112 -10
- package/src/p2/helper-rpc.ts +73 -36
- package/src/p2/router-spill.ts +96 -1
- package/src/p2/router-subprocess.ts +18 -5
- package/src/p2/spill-retention.ts +134 -0
- package/src/p2/ssh-proc.ts +22 -0
- package/src/p2/worlds.ts +24 -0
- package/src/pool.ts +329 -47
- package/src/protocol.ts +66 -0
- package/src/routes.ts +251 -43
- package/src/sftp.ts +486 -26
- package/src/store.ts +207 -85
- package/src/terminal.ts +38 -2
- package/src/timeouts.ts +14 -0
- package/src/tools.ts +14 -5
|
@@ -90,6 +90,18 @@ export interface CodeEditorHandle {
|
|
|
90
90
|
/** Compartment holding the fallback highlighter (armed only when needed). */
|
|
91
91
|
const fallbackCompartment = new Compartment()
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Compartment holding the read-only flag.
|
|
95
|
+
*
|
|
96
|
+
* It has to be reconfigurable, not baked into the initial state: the link can go
|
|
97
|
+
* down (or a truncated file can be re-read in full) while the buffer is mounted,
|
|
98
|
+
* and remounting it to change editability would throw away undo history and the
|
|
99
|
+
* caret. A Compartment instance may be shared by several EditorStates — each
|
|
100
|
+
* view keeps its own value for the key, and the effect below dispatches into its
|
|
101
|
+
* own view only.
|
|
102
|
+
*/
|
|
103
|
+
const readOnlyCompartment = new Compartment()
|
|
104
|
+
|
|
93
105
|
/**
|
|
94
106
|
* Compartment holding the session-change marks.
|
|
95
107
|
*
|
|
@@ -218,6 +230,18 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
218
230
|
savedText?: string
|
|
219
231
|
onSave: () => void
|
|
220
232
|
onDirty: (dirty: boolean) => void
|
|
233
|
+
/**
|
|
234
|
+
* Last chance to hand the LIVE document to the store, called from this
|
|
235
|
+
* component's own unmount cleanup while the EditorView still exists.
|
|
236
|
+
*
|
|
237
|
+
* The parent cannot do this itself: React clears a child's ref before the
|
|
238
|
+
* parent's cleanup runs, so `editorRef.current` is already null there. An
|
|
239
|
+
* unmount that is not one of the plugin's own switches (the host swapping the
|
|
240
|
+
* remote-editor view away) would otherwise drop every unsaved edit while the
|
|
241
|
+
* tab kept its dirty dot, and the next Ctrl+S would write the stale bytes
|
|
242
|
+
* back. Only called when the buffer is dirty, so clean unmounts stay free.
|
|
243
|
+
*/
|
|
244
|
+
onBuffer?: (tabId: string, text: string) => void
|
|
221
245
|
}>(function CodeEditor(props, ref) {
|
|
222
246
|
const hostRef = useRef<HTMLDivElement>(null)
|
|
223
247
|
const viewRef = useRef<EditorView | undefined>(undefined)
|
|
@@ -264,6 +288,16 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
264
288
|
const findOpenRef = useRef(false)
|
|
265
289
|
findOpenRef.current = findOpen
|
|
266
290
|
const [findSeed, setFindSeed] = useState({ text: '', id: 0 })
|
|
291
|
+
/**
|
|
292
|
+
* Bumped on every selection change while the find widget is open.
|
|
293
|
+
*
|
|
294
|
+
* The widget's `n/N` readout is derived from the caret, but F3 / Shift-F3, a
|
|
295
|
+
* click or an arrow key move the caret WITHOUT touching the widget, so nothing
|
|
296
|
+
* used to re-read it: the numbers stayed on the previous match while the caret
|
|
297
|
+
* had already moved on. Only bumped while open, so a closed widget costs no
|
|
298
|
+
* renders at all.
|
|
299
|
+
*/
|
|
300
|
+
const [findTick, setFindTick] = useState(0)
|
|
267
301
|
const [view, setView] = useState<EditorView | undefined>(undefined)
|
|
268
302
|
/** Landing highlight for a jump (null = nothing lit). */
|
|
269
303
|
const [litPosition, setLitPosition] = useState<number | null>(null)
|
|
@@ -491,6 +525,20 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
491
525
|
getChangeStale: () => viewRef.current?.state.field(changeStaleField, false) === true,
|
|
492
526
|
}), [])
|
|
493
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Read-only follows the link, live.
|
|
530
|
+
*
|
|
531
|
+
* Offline mode degrades the mounted buffer to a viewer; baked-in read-only
|
|
532
|
+
* state would leave the user typing into a buffer whose save is blocked, and a
|
|
533
|
+
* remount just to flip it would drop undo history and the caret. The
|
|
534
|
+
* compartment carries the flag through a reconfigure instead.
|
|
535
|
+
*/
|
|
536
|
+
useEffect(() => {
|
|
537
|
+
const view = viewRef.current
|
|
538
|
+
if (view === undefined) return
|
|
539
|
+
view.dispatch({ effects: readOnlyCompartment.reconfigure(EditorState.readOnly.of(props.readOnly === true)) })
|
|
540
|
+
}, [props.readOnly])
|
|
541
|
+
|
|
494
542
|
// Shown again after being hidden: remeasure layout.
|
|
495
543
|
useEffect(() => {
|
|
496
544
|
if (props.visible === false) return
|
|
@@ -630,7 +678,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
630
678
|
// `changeMarksCompartment`).
|
|
631
679
|
changeMarksCompartment.of([]),
|
|
632
680
|
EditorView.lineWrapping,
|
|
633
|
-
EditorState.readOnly.of(propsRef.current.readOnly === true),
|
|
681
|
+
readOnlyCompartment.of(EditorState.readOnly.of(propsRef.current.readOnly === true)),
|
|
634
682
|
...langFor(propsRef.current.path),
|
|
635
683
|
EditorView.updateListener.of((update) => {
|
|
636
684
|
if (!update.docChanged) return
|
|
@@ -715,6 +763,11 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
715
763
|
*/
|
|
716
764
|
EditorView.updateListener.of((update) => {
|
|
717
765
|
if (!update.selectionSet) return
|
|
766
|
+
// Nudge the find widget so its readout follows moves made OUTSIDE it
|
|
767
|
+
// (F3, a click, an arrow key). Folded into this existing listener rather
|
|
768
|
+
// than a new extension, and gated on `findOpenRef` so the widget being
|
|
769
|
+
// closed never costs a render.
|
|
770
|
+
if (findOpenRef.current) setFindTick(tick => tick + 1)
|
|
718
771
|
const handler = propsRef.current.onViewState
|
|
719
772
|
const tabId = propsRef.current.tabId
|
|
720
773
|
if (handler === undefined || tabId === undefined) return
|
|
@@ -896,7 +949,20 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
896
949
|
* tokenizer the diff panes use. The console line names which path colored
|
|
897
950
|
* the file, so a screenshot or a pasted line is enough to diagnose.
|
|
898
951
|
*/
|
|
952
|
+
/**
|
|
953
|
+
* Handle of the delayed `stamp` run (see `armFallback`).
|
|
954
|
+
*
|
|
955
|
+
* It used to be untracked, so unmounting between the 250 ms arm and the
|
|
956
|
+
* 120 ms stamp left it queued: it then measured a DETACHED host (0 colored
|
|
957
|
+
* spans) and reported `tok 0` for whichever tab was on screen by then — the
|
|
958
|
+
* exact number README calls "grammar did not fire". Tracked here so cleanup
|
|
959
|
+
* cancels it, like `armTimer` / `warmTimer`.
|
|
960
|
+
*/
|
|
961
|
+
let stampTimer: number | undefined
|
|
899
962
|
const stamp = (source: string): void => {
|
|
963
|
+
// Double guard: React can tear the mount down between the timer being
|
|
964
|
+
// queued and it running, and `host` is detached by then.
|
|
965
|
+
if (viewRef.current !== view) return
|
|
900
966
|
const primary = host.querySelectorAll('[class*="rvs-ck-"]').length
|
|
901
967
|
const fallback = host.querySelectorAll('span[class^="rvs-t-"]').length
|
|
902
968
|
const count = primary > 0 ? primary : fallback
|
|
@@ -916,7 +982,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
916
982
|
// A disposed view: nothing to color.
|
|
917
983
|
}
|
|
918
984
|
}
|
|
919
|
-
window.setTimeout(() => stamp(needsFallback ? 'fallback' : 'grammar'), 120)
|
|
985
|
+
stampTimer = window.setTimeout(() => stamp(needsFallback ? 'fallback' : 'grammar'), 120)
|
|
920
986
|
}
|
|
921
987
|
// Two passes: the first lets CodeMirror's own highlighter settle, the
|
|
922
988
|
// second reports what actually ended up on screen. Both handles are kept
|
|
@@ -944,6 +1010,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
944
1010
|
if (restoreFrame !== undefined) window.cancelAnimationFrame(restoreFrame)
|
|
945
1011
|
window.clearTimeout(armTimer)
|
|
946
1012
|
window.clearTimeout(warmTimer)
|
|
1013
|
+
window.clearTimeout(stampTimer)
|
|
947
1014
|
popupRef.current.hide()
|
|
948
1015
|
unwatchTheme()
|
|
949
1016
|
/**
|
|
@@ -953,6 +1020,20 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
953
1020
|
* cannot ask for it. Also covers a tab closed while it was the active one.
|
|
954
1021
|
*/
|
|
955
1022
|
disposeViewReport()
|
|
1023
|
+
/**
|
|
1024
|
+
* Hand the live document over BEFORE the view goes away (see `onBuffer`):
|
|
1025
|
+
* this is the only moment at which the buffer and the tab id are both
|
|
1026
|
+
* still readable. Dirty only — a clean unmount has nothing newer to keep.
|
|
1027
|
+
*/
|
|
1028
|
+
const bufferHandler = propsRef.current.onBuffer
|
|
1029
|
+
const bufferTabId = propsRef.current.tabId
|
|
1030
|
+
if (dirtyRef.current && bufferHandler !== undefined && bufferTabId !== undefined) {
|
|
1031
|
+
try {
|
|
1032
|
+
bufferHandler(bufferTabId, view.state.doc.toString())
|
|
1033
|
+
} catch {
|
|
1034
|
+
// A disposed view: nothing to carry.
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
956
1037
|
view.destroy()
|
|
957
1038
|
viewRef.current = undefined
|
|
958
1039
|
}
|
|
@@ -973,6 +1054,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, {
|
|
|
973
1054
|
view={view}
|
|
974
1055
|
open={findOpen}
|
|
975
1056
|
seed={findSeed}
|
|
1057
|
+
tick={findTick}
|
|
976
1058
|
anchor={anchor}
|
|
977
1059
|
onClose={() => {
|
|
978
1060
|
setFindOpen(false)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection status for the workspace on screen.
|
|
3
|
+
*
|
|
4
|
+
* Two renderings, one source of truth: a chip in the remote surface's top bar
|
|
5
|
+
* (dot + label) and a compact dot in the editor's info bar. The chip is a
|
|
6
|
+
* read-out in the healthy states and a RETRY control in the errored one.
|
|
7
|
+
*
|
|
8
|
+
* An errored link self-heals: a bounded auto-retry (one dial per tick, at most
|
|
9
|
+
* AUTO_RETRY_MAX_ATTEMPTS in a row) runs while the page is visible, so a network
|
|
10
|
+
* that comes back does not need a user action. It stops after the budget and
|
|
11
|
+
* leaves the manual click — repeated dials against a password-auth host can
|
|
12
|
+
* count towards a lockout, so this is deliberately not an endless loop.
|
|
13
|
+
*/
|
|
14
|
+
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
15
|
+
import { api } from './api.ts'
|
|
16
|
+
import {
|
|
17
|
+
applyConnectionStatuses,
|
|
18
|
+
AUTO_RETRY_MAX_ATTEMPTS,
|
|
19
|
+
AUTO_RETRY_MS,
|
|
20
|
+
connectionLabelKey,
|
|
21
|
+
consumeAutoRetry,
|
|
22
|
+
markConnectionProbeOk,
|
|
23
|
+
useConnectionStatus,
|
|
24
|
+
type ConnectionView,
|
|
25
|
+
} from './connection.ts'
|
|
26
|
+
import { useExplorer } from './store.tsx'
|
|
27
|
+
import { MiniSpinner } from './vsc/kit.tsx'
|
|
28
|
+
|
|
29
|
+
/** Tooltip: alias, state, the last failure (with its time) or the last success. */
|
|
30
|
+
function titleOf(connection: ConnectionView, t: (key: string) => string): string {
|
|
31
|
+
const parts = [`${connection.alias} · ${t(connectionLabelKey(connection.state))}`]
|
|
32
|
+
if (connection.state === 'error') {
|
|
33
|
+
if (connection.errorAt !== undefined) {
|
|
34
|
+
parts.push(`${t('connection.errorAt')} ${new Date(connection.errorAt).toLocaleTimeString()}`)
|
|
35
|
+
}
|
|
36
|
+
if (connection.error !== undefined) parts.push(`${t('connection.detail')}: ${connection.error}`)
|
|
37
|
+
parts.push(t('connection.retryHint'))
|
|
38
|
+
}
|
|
39
|
+
if (connection.state === 'ok' && connection.okAt !== undefined) {
|
|
40
|
+
parts.push(`${t('connection.lastOk')} ${new Date(connection.okAt).toLocaleTimeString()}`)
|
|
41
|
+
}
|
|
42
|
+
return parts.join('\n')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function ConnectionStatusChip(props: { compact?: boolean }): ReactNode {
|
|
46
|
+
const store = useExplorer()
|
|
47
|
+
const t = store.t
|
|
48
|
+
const alias = store.workspace?.alias ?? ''
|
|
49
|
+
const connection = useConnectionStatus()
|
|
50
|
+
const [retrying, setRetrying] = useState(false)
|
|
51
|
+
const alive = useRef(true)
|
|
52
|
+
/** Consecutive automatic attempts for the CURRENT error episode. */
|
|
53
|
+
const autoAttempts = useRef(0)
|
|
54
|
+
const busy = useRef(false)
|
|
55
|
+
useEffect(() => () => {
|
|
56
|
+
alive.current = false
|
|
57
|
+
}, [])
|
|
58
|
+
|
|
59
|
+
const attempt = async (): Promise<void> => {
|
|
60
|
+
if (alias === '' || busy.current) return
|
|
61
|
+
busy.current = true
|
|
62
|
+
setRetrying(true)
|
|
63
|
+
try {
|
|
64
|
+
// The Host records the attempt in the pool (success clears the error,
|
|
65
|
+
// failure records it); refresh right after so the chip reflects it now.
|
|
66
|
+
const result = await api.testHost(alias)
|
|
67
|
+
// A stale poll error must not undo a retry that just proved the link alive.
|
|
68
|
+
if (result.ok) markConnectionProbeOk(alias)
|
|
69
|
+
applyConnectionStatuses(await api.connectionStatus())
|
|
70
|
+
} catch {
|
|
71
|
+
// A transport failure already marked the alias through `call`; the next
|
|
72
|
+
// poll confirms it.
|
|
73
|
+
} finally {
|
|
74
|
+
busy.current = false
|
|
75
|
+
if (alive.current) setRetrying(false)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// A broken link is retried on its own, within a budget, while the page is
|
|
80
|
+
// visible. Recovery otherwise waits for the user to touch something.
|
|
81
|
+
const errored = connection?.state === 'error'
|
|
82
|
+
// The budget belongs to ONE error episode on ONE host: switching to another
|
|
83
|
+
// errored workspace must not inherit a spent budget.
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
autoAttempts.current = 0
|
|
86
|
+
}, [alias])
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!errored || alias === '') {
|
|
89
|
+
if (!errored) autoAttempts.current = 0
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
const timer = window.setInterval(() => {
|
|
93
|
+
if (document.hidden) return
|
|
94
|
+
const plan = consumeAutoRetry(errored ? 'error' : 'idle', autoAttempts.current)
|
|
95
|
+
autoAttempts.current = plan.attempts
|
|
96
|
+
if (!plan.run) {
|
|
97
|
+
window.clearInterval(timer)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
void attempt()
|
|
101
|
+
}, AUTO_RETRY_MS)
|
|
102
|
+
return () => window.clearInterval(timer)
|
|
103
|
+
// `attempt` is recreated each render; the interval only needs the episode.
|
|
104
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
+
}, [errored, alias])
|
|
106
|
+
|
|
107
|
+
if (alias === '' || connection === undefined) return null
|
|
108
|
+
const label = retrying ? t('connection.retrying') : t(connectionLabelKey(connection.state))
|
|
109
|
+
const className = `rvs-conn rvs-conn-${connection.state}${props.compact === true ? ' compact' : ''}${errored ? ' clickable' : ''}`
|
|
110
|
+
const title = titleOf(connection, t)
|
|
111
|
+
if (!errored) {
|
|
112
|
+
// A healthy/idle read-out must not be a button whose click does nothing.
|
|
113
|
+
return (
|
|
114
|
+
<span className={className} title={title} role="status" aria-label={label}>
|
|
115
|
+
<span className="rvs-conn-dot" aria-hidden="true" />
|
|
116
|
+
{props.compact !== true && <span className="rvs-conn-label">{label}</span>}
|
|
117
|
+
</span>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
// Errored stays a BUTTON even while an automatic attempt is in flight: that
|
|
121
|
+
// dial can take the whole ready-timeout, and hiding the manual affordance for
|
|
122
|
+
// its duration is exactly when the user reaches for it.
|
|
123
|
+
return (
|
|
124
|
+
<button type="button" className={className} title={title} aria-label={label} aria-busy={retrying} onClick={() => { void attempt() }}>
|
|
125
|
+
<span className="rvs-conn-dot" aria-hidden="true" />
|
|
126
|
+
{retrying && <MiniSpinner />}
|
|
127
|
+
{props.compact !== true && <span className="rvs-conn-label">{label}</span>}
|
|
128
|
+
</button>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
@@ -45,14 +45,17 @@ function errText(e: unknown): string {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** True when the failure is "this backend serves no browse primitives". */
|
|
48
|
-
function isUnavailable(e: unknown): boolean {
|
|
48
|
+
export function isUnavailable(e: unknown): boolean {
|
|
49
49
|
if (e !== null && typeof e === 'object' && 'rpcError' in e) {
|
|
50
50
|
const rpc = (e as { rpcError: unknown }).rpcError
|
|
51
51
|
if (rpc !== null && typeof rpc === 'object' && 'code' in rpc) {
|
|
52
52
|
return (rpc as { code: unknown }).code === 'directory-picker/unavailable'
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
// Only the protocol token, never a generic word: "remote host temporarily
|
|
56
|
+
// unavailable" is a real failure to show/retry, not "this backend serves no
|
|
57
|
+
// browse primitives" (using the native picker for it hid the actual error).
|
|
58
|
+
return errText(e).includes('directory-picker/unavailable')
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
function LocalLeg(props: {
|
|
@@ -345,6 +348,40 @@ export function RemoteDirectoryFlow(props: DirectoryFlowOwnerProps & DirectoryFl
|
|
|
345
348
|
wasOpen.current = props.open
|
|
346
349
|
}, [props.open])
|
|
347
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Keyboard/focus for the occupied directory-flow dialog.
|
|
353
|
+
*
|
|
354
|
+
* Escape used to be an `onKeyDown` on the inner box, so it only worked while
|
|
355
|
+
* focus was already inside the dialog (right after opening it was not); and
|
|
356
|
+
* closing left focus nowhere. A document-level listener while open fixes both
|
|
357
|
+
* without touching the owner's dialog contract.
|
|
358
|
+
*/
|
|
359
|
+
const boxRef = useRef<HTMLDivElement>(null)
|
|
360
|
+
const openerRef = useRef<HTMLElement | null>(null)
|
|
361
|
+
const cancelRef = useRef(props.onCancel)
|
|
362
|
+
cancelRef.current = props.onCancel
|
|
363
|
+
const busyRef = useRef(props.busy)
|
|
364
|
+
busyRef.current = props.busy
|
|
365
|
+
useEffect(() => {
|
|
366
|
+
if (!props.open) return
|
|
367
|
+
openerRef.current = typeof document === 'undefined' ? null : (document.activeElement as HTMLElement | null)
|
|
368
|
+
const focusTimer = window.setTimeout(() => {
|
|
369
|
+
boxRef.current?.querySelector<HTMLElement>('button:not([disabled])')?.focus()
|
|
370
|
+
}, 0)
|
|
371
|
+
const onKey = (e: KeyboardEvent): void => {
|
|
372
|
+
if (e.key !== 'Escape' || busyRef.current) return
|
|
373
|
+
e.preventDefault()
|
|
374
|
+
cancelRef.current()
|
|
375
|
+
}
|
|
376
|
+
window.addEventListener('keydown', onKey)
|
|
377
|
+
return () => {
|
|
378
|
+
window.clearTimeout(focusTimer)
|
|
379
|
+
window.removeEventListener('keydown', onKey)
|
|
380
|
+
const opener = openerRef.current
|
|
381
|
+
if (opener !== null && document.body.contains(opener)) opener.focus()
|
|
382
|
+
}
|
|
383
|
+
}, [props.open])
|
|
384
|
+
|
|
348
385
|
if (!props.open) return null
|
|
349
386
|
|
|
350
387
|
const injected: DirectoryFlowInjected = {
|
|
@@ -364,6 +401,7 @@ export function RemoteDirectoryFlow(props: DirectoryFlowOwnerProps & DirectoryFl
|
|
|
364
401
|
}}
|
|
365
402
|
>
|
|
366
403
|
<div
|
|
404
|
+
ref={boxRef}
|
|
367
405
|
style={{
|
|
368
406
|
width: 'min(600px, calc(100vw - 32px))',
|
|
369
407
|
maxHeight: 'min(680px, calc(100vh - 32px))',
|
|
@@ -377,9 +415,6 @@ export function RemoteDirectoryFlow(props: DirectoryFlowOwnerProps & DirectoryFl
|
|
|
377
415
|
fontSize: 13,
|
|
378
416
|
}}
|
|
379
417
|
onClick={(e) => e.stopPropagation()}
|
|
380
|
-
onKeyDown={(e) => {
|
|
381
|
-
if (e.key === 'Escape' && !props.busy) props.onCancel()
|
|
382
|
-
}}
|
|
383
418
|
>
|
|
384
419
|
<div style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 10 }}>
|
|
385
420
|
<strong>{t('flow.title')}</strong>
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote environment doctor panel: one screen of evidence about the host the
|
|
3
|
+
* workspace lives on, plus "copy all" as plain text.
|
|
4
|
+
*
|
|
5
|
+
* Rendered as a fixed overlay (like the input dialog) instead of joining the
|
|
6
|
+
* host list: the list lives in the DSH Settings dialog, and pushing it around
|
|
7
|
+
* while the first paint of a probe is still in flight would be worse than a
|
|
8
|
+
* layer on top of it.
|
|
9
|
+
*
|
|
10
|
+
* The run lives here, not in `HostsView`: the panel is mounted for exactly the
|
|
11
|
+
* lifetime of one report (the host row supplies `key={alias}`), so an unmount
|
|
12
|
+
* closes the door on a late answer instead of writing into the list. A second
|
|
13
|
+
* mount for the same alias joins the in-flight probe rather than spending
|
|
14
|
+
* another channel slot.
|
|
15
|
+
*
|
|
16
|
+
* Three states, one of which is `unknown` — see `doctor.ts`: an unanswered
|
|
17
|
+
* probe is never rendered as "not installed"; the hint line under the table
|
|
18
|
+
* says what "unknown" means so nobody reads a blank as a pass.
|
|
19
|
+
*/
|
|
20
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
21
|
+
import { api } from './api.ts'
|
|
22
|
+
import {
|
|
23
|
+
DOCTOR_STATE_KEY,
|
|
24
|
+
DOCTOR_TIMEOUT_MS,
|
|
25
|
+
doctorFailure,
|
|
26
|
+
doctorScript,
|
|
27
|
+
formatDoctorReport,
|
|
28
|
+
parseDoctor,
|
|
29
|
+
type DoctorItem,
|
|
30
|
+
} from './doctor.ts'
|
|
31
|
+
import { Btn, Spinner } from './ui.tsx'
|
|
32
|
+
|
|
33
|
+
function StateBadge(props: { item: DoctorItem; t: (key: string) => string }): ReactNode {
|
|
34
|
+
return (
|
|
35
|
+
<span className={`rvs-doctor-badge ${props.item.state}`}>
|
|
36
|
+
{props.t(DOCTOR_STATE_KEY[props.item.state])}
|
|
37
|
+
</span>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* One in-flight probe per alias.
|
|
43
|
+
*
|
|
44
|
+
* A StrictMode/replay remount (and a close→reopen that lands inside the 20 s
|
|
45
|
+
* budget) would otherwise start a second remote exec: another channel slot, and
|
|
46
|
+
* for a password host another authentication. Joining the running promise keeps
|
|
47
|
+
* "one button press = at most one probe" true.
|
|
48
|
+
*/
|
|
49
|
+
const inFlight = new Map<string, Promise<DoctorItem[]>>()
|
|
50
|
+
|
|
51
|
+
function probeOnce(alias: string): Promise<DoctorItem[]> {
|
|
52
|
+
const running = inFlight.get(alias)
|
|
53
|
+
if (running !== undefined) return running
|
|
54
|
+
const settled = api.exec(alias, doctorScript(), DOCTOR_TIMEOUT_MS).then(
|
|
55
|
+
result => parseDoctor(result.stdout, result.stderr, result.exitCode),
|
|
56
|
+
// The request itself failed (dead link, host refused the route). That is not
|
|
57
|
+
// an answer about any tool: every row is unknown, with the reason.
|
|
58
|
+
(e: unknown) => doctorFailure(e instanceof Error ? e.message : String(e)),
|
|
59
|
+
)
|
|
60
|
+
const tracked = settled.finally(() => {
|
|
61
|
+
if (inFlight.get(alias) === tracked) inFlight.delete(alias)
|
|
62
|
+
})
|
|
63
|
+
inFlight.set(alias, tracked)
|
|
64
|
+
return tracked
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Copy the report and say whether it worked.
|
|
69
|
+
*
|
|
70
|
+
* `copyText` in `kit.tsx` swallows both failures and resolves either way, so a
|
|
71
|
+
* panel using it would claim "copied" on a plain-HTTP origin where the clipboard
|
|
72
|
+
* API is blocked — a lie in the one action that exists to get evidence out. This
|
|
73
|
+
* returns the real outcome; the button then says which happened.
|
|
74
|
+
*/
|
|
75
|
+
async function copyReport(text: string): Promise<boolean> {
|
|
76
|
+
try {
|
|
77
|
+
await navigator.clipboard.writeText(text)
|
|
78
|
+
return true
|
|
79
|
+
} catch {
|
|
80
|
+
// Fall through: the clipboard API is unavailable over plain HTTP origins.
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const area = document.createElement('textarea')
|
|
84
|
+
area.value = text
|
|
85
|
+
area.style.position = 'fixed'
|
|
86
|
+
area.style.opacity = '0'
|
|
87
|
+
document.body.appendChild(area)
|
|
88
|
+
area.select()
|
|
89
|
+
const ok = document.execCommand('copy')
|
|
90
|
+
area.remove()
|
|
91
|
+
return ok
|
|
92
|
+
} catch {
|
|
93
|
+
return false
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function DoctorPanel(props: {
|
|
98
|
+
t: (key: string) => string
|
|
99
|
+
alias: string
|
|
100
|
+
onClose: () => void
|
|
101
|
+
}): ReactNode {
|
|
102
|
+
const t = props.t
|
|
103
|
+
/** `undefined` = the probe is still running. */
|
|
104
|
+
const [items, setItems] = useState<DoctorItem[] | undefined>(undefined)
|
|
105
|
+
const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>('idle')
|
|
106
|
+
const alive = useRef(true)
|
|
107
|
+
// Re-armed on every setup: a StrictMode/replay remount runs setup → cleanup →
|
|
108
|
+
// setup, and a flag that only ever got set to false would freeze the panel on
|
|
109
|
+
// "loading" for good. Declared BEFORE the run effect so it is re-armed first.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
alive.current = true
|
|
112
|
+
return () => {
|
|
113
|
+
alive.current = false
|
|
114
|
+
}
|
|
115
|
+
}, [])
|
|
116
|
+
|
|
117
|
+
const run = useCallback((): void => {
|
|
118
|
+
void probeOnce(props.alias).then((next) => {
|
|
119
|
+
if (alive.current) setItems(next)
|
|
120
|
+
})
|
|
121
|
+
}, [props.alias])
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
run()
|
|
125
|
+
}, [run])
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
const onKey = (e: KeyboardEvent): void => {
|
|
129
|
+
if (e.key !== 'Escape') return
|
|
130
|
+
// CAPTURE phase + stop: the panel lives inside the DSH Settings dialog,
|
|
131
|
+
// whose own Escape handler would otherwise close the whole dialog (and the
|
|
132
|
+
// report) together with this layer.
|
|
133
|
+
e.stopPropagation()
|
|
134
|
+
props.onClose()
|
|
135
|
+
}
|
|
136
|
+
document.addEventListener('keydown', onKey, true)
|
|
137
|
+
return () => document.removeEventListener('keydown', onKey, true)
|
|
138
|
+
}, [props.onClose])
|
|
139
|
+
|
|
140
|
+
const copy = (): void => {
|
|
141
|
+
if (items === undefined) return
|
|
142
|
+
void copyReport(formatDoctorReport(props.alias, items, t)).then((ok) => {
|
|
143
|
+
if (alive.current) setCopyState(ok ? 'copied' : 'failed')
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const copyLabel = copyState === 'copied'
|
|
148
|
+
? t('doctor.copied')
|
|
149
|
+
: copyState === 'failed'
|
|
150
|
+
? t('doctor.copyFailed')
|
|
151
|
+
: t('doctor.copy')
|
|
152
|
+
const title = t('doctor.title').replace('{alias}', props.alias)
|
|
153
|
+
const hasUnknown = items !== undefined && items.some(item => item.state === 'unknown')
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<div
|
|
157
|
+
className="rvs-doctor"
|
|
158
|
+
role="dialog"
|
|
159
|
+
aria-modal="true"
|
|
160
|
+
aria-label={title}
|
|
161
|
+
onClick={props.onClose}
|
|
162
|
+
>
|
|
163
|
+
<div className="rvs-doctor-card" onClick={(e) => e.stopPropagation()}>
|
|
164
|
+
<div className="rvs-doctor-head">
|
|
165
|
+
<span className="rvs-doctor-title">{title}</span>
|
|
166
|
+
<span style={{ flex: 1 }} />
|
|
167
|
+
<Btn onClick={copy} disabled={items === undefined}>{copyLabel}</Btn>
|
|
168
|
+
<Btn onClick={props.onClose}>{t('doctor.close')}</Btn>
|
|
169
|
+
</div>
|
|
170
|
+
{items === undefined
|
|
171
|
+
? (
|
|
172
|
+
<div className="rvs-doctor-body">
|
|
173
|
+
<div className="rvs-doctor-loading"><Spinner /> {t('doctor.loading')}</div>
|
|
174
|
+
</div>
|
|
175
|
+
)
|
|
176
|
+
: (
|
|
177
|
+
<div className="rvs-doctor-body">
|
|
178
|
+
<table className="rvs-doctor-table">
|
|
179
|
+
<thead>
|
|
180
|
+
<tr>
|
|
181
|
+
<th>{t('doctor.colItem')}</th>
|
|
182
|
+
<th>{t('doctor.colState')}</th>
|
|
183
|
+
<th>{t('doctor.colDetail')}</th>
|
|
184
|
+
</tr>
|
|
185
|
+
</thead>
|
|
186
|
+
<tbody>
|
|
187
|
+
{items.map(item => (
|
|
188
|
+
<tr key={item.key}>
|
|
189
|
+
<td className="rvs-doctor-item">{t(item.label)}</td>
|
|
190
|
+
<td><StateBadge item={item} t={t} /></td>
|
|
191
|
+
<td className="rvs-doctor-detail" title={item.detail}>{item.detail}</td>
|
|
192
|
+
</tr>
|
|
193
|
+
))}
|
|
194
|
+
</tbody>
|
|
195
|
+
</table>
|
|
196
|
+
</div>
|
|
197
|
+
)}
|
|
198
|
+
{hasUnknown && <div className="rvs-doctor-hint">{t('doctor.unknownHint')}</div>}
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
@@ -12,7 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
import { useSyncExternalStore, type ReactNode } from 'react'
|
|
14
14
|
import { createPortal } from 'react-dom'
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
cancelDownload,
|
|
17
|
+
dismissDownload,
|
|
18
|
+
downloadDetailText,
|
|
19
|
+
downloadPercent,
|
|
20
|
+
downloadsStore,
|
|
21
|
+
type DownloadTask,
|
|
22
|
+
} from './downloads.ts'
|
|
16
23
|
import { FileIcon, FolderIcon, IconButton, IconClose, IconStop } from './vsc/kit.tsx'
|
|
17
24
|
|
|
18
25
|
const STATUS_KEY: Record<DownloadTask['status'], string> = {
|
|
@@ -20,33 +27,14 @@ const STATUS_KEY: Record<DownloadTask['status'], string> = {
|
|
|
20
27
|
done: 'downloads.done',
|
|
21
28
|
failed: 'downloads.failed',
|
|
22
29
|
cancelled: 'downloads.cancelled',
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/** One line of detail under the bar (bytes, fallback note, or the failure). */
|
|
26
|
-
function detailText(task: DownloadTask, t: (key: string) => string): string {
|
|
27
|
-
if (task.status === 'failed') return task.error ?? t('downloads.failed')
|
|
28
|
-
if (task.status === 'cancelled') return t('downloads.cancelled')
|
|
29
|
-
if (task.status === 'done') {
|
|
30
|
-
return task.via === 'browserDefault' ? t('downloads.browserDefault') : t('downloads.done')
|
|
31
|
-
}
|
|
32
|
-
const loaded = formatByteCount(task.loaded)
|
|
33
|
-
const archive = task.directory || task.selection !== undefined
|
|
34
|
-
if (task.total !== undefined && task.total > 0) return `${loaded} / ${formatByteCount(task.total)}`
|
|
35
|
-
// An archive has no length by design (chunked tar). A plain FILE with no
|
|
36
|
-
// known total means a shell/proxy stripped content-length (DSH Desktop does)
|
|
37
|
-
// — saying "packaging…" there wrongly suggests we re-archive the file.
|
|
38
|
-
return `${loaded} · ${t(archive ? 'downloads.indeterminate' : 'downloads.sizeUnknown')}`
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Percent for the bar, or `undefined` while the size is unknown (archives). */
|
|
42
|
-
function percentOf(task: DownloadTask): number | undefined {
|
|
43
|
-
if (task.total === undefined || task.total <= 0) return undefined
|
|
44
|
-
return Math.min(100, Math.round((task.loaded / task.total) * 100))
|
|
30
|
+
handedOff: 'downloads.handedOff',
|
|
45
31
|
}
|
|
46
32
|
|
|
47
33
|
function DownloadRow(props: { task: DownloadTask; t: (key: string) => string }): ReactNode {
|
|
48
34
|
const { task, t } = props
|
|
49
|
-
|
|
35
|
+
// The formatting lives in `downloads.ts` (pure, node-gateable); the dock only
|
|
36
|
+
// renders it.
|
|
37
|
+
const percent = downloadPercent(task)
|
|
50
38
|
return (
|
|
51
39
|
<div className={`rvs-download ${task.status}`}>
|
|
52
40
|
<div className="rvs-download-head">
|
|
@@ -75,7 +63,7 @@ function DownloadRow(props: { task: DownloadTask; t: (key: string) => string }):
|
|
|
75
63
|
/>
|
|
76
64
|
</div>
|
|
77
65
|
)}
|
|
78
|
-
<div className={`rvs-download-meta ${task.status}`} title={task.error}>{
|
|
66
|
+
<div className={`rvs-download-meta ${task.status}`} title={task.error}>{downloadDetailText(task, t)}</div>
|
|
79
67
|
</div>
|
|
80
68
|
)
|
|
81
69
|
}
|