Import packages/plugin/src/client/workspaces.ts
This commit is contained in:
parent
78123ee169
commit
de9744db95
|
|
@ -1,6 +1,7 @@
|
|||
import { mountAccountEntry } from './account-entry.js'
|
||||
import { createHostPairingPanel } from './pairing.js'
|
||||
import { createServerNotice } from './server-notice.js'
|
||||
import { createFastModeSwitches } from './fast-mode-switches.js'
|
||||
import { renderBodyPortal } from './portal.js'
|
||||
import QRCode from 'qrcode'
|
||||
import type { Translate } from '../client-locale.js'
|
||||
|
|
@ -10,6 +11,7 @@ import { compareVersions } from '../version-compare.js'
|
|||
import { deepSeekWorkspaceIcon, gptWorkspaceIcon } from './icons.js'
|
||||
import { pendingWorkspaceSelectionKey } from './navigation.js'
|
||||
import { connectedClientModeLabel, connectedProgress, connectionErrorMessage, displayRemoteAccount, formatPlatform, messageOf, startupErrorMessage } from './presentation.js'
|
||||
import { settleLostUpgrade } from './plugin-upgrade.js'
|
||||
import { createRemoteProgressView, runConnectHostProgress } from './progress.js'
|
||||
import type {
|
||||
ClientReact,
|
||||
|
|
@ -30,75 +32,10 @@ import type {
|
|||
SidebarEntryStyle,
|
||||
} from './types.js'
|
||||
|
||||
type ToggleConfigKey = 'liteMode' | 'forceRelay'
|
||||
|
||||
const TOGGLES: Record<ToggleConfigKey, { label: 'liteMode' | 'forceRelay', hint: 'liteModeHint' | 'forceRelayHint', endpoint: string }> = {
|
||||
liteMode: { label: 'liteMode', hint: 'liteModeHint', endpoint: 'settings.lite.set' },
|
||||
forceRelay: { label: 'forceRelay', hint: 'forceRelayHint', endpoint: 'settings.forceRelay.set' },
|
||||
}
|
||||
|
||||
function createRemoteToggleSwitch(React: ClientReact) {
|
||||
return function RemoteToggleSwitch(props: {
|
||||
control: <T>(endpoint: string, payload?: unknown) => Promise<T>
|
||||
t: Translate
|
||||
configKey: ToggleConfigKey
|
||||
}) {
|
||||
const meta = TOGGLES[props.configKey]
|
||||
const [enabled, setEnabled] = React.useState(false)
|
||||
const [busy, setBusy] = React.useState(false)
|
||||
const [showHint, setShowHint] = React.useState(false)
|
||||
React.useEffect(() => {
|
||||
props.control<PluginSettingsView>('settings.get')
|
||||
.then(view => setEnabled(view.config[props.configKey] === true))
|
||||
.catch(() => undefined)
|
||||
}, [props.control, props.configKey])
|
||||
const toggle = async (next: boolean) => {
|
||||
setEnabled(next)
|
||||
setBusy(true)
|
||||
try {
|
||||
const view = await props.control<PluginSettingsView>(meta.endpoint, { enabled: next })
|
||||
setEnabled(view.config[props.configKey] === true)
|
||||
} catch {
|
||||
setEnabled(!next)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
const label = props.t(meta.label)
|
||||
const hint = props.t(meta.hint)
|
||||
return React.createElement('div', {
|
||||
className: 'dshRemoteHostControlToggle',
|
||||
style: { marginLeft: '14px', position: 'relative' },
|
||||
},
|
||||
React.createElement('span', { title: hint, style: { cursor: 'help' } }, label),
|
||||
React.createElement('button', {
|
||||
type: 'button',
|
||||
title: hint,
|
||||
'aria-label': hint,
|
||||
onClick: () => setShowHint(!showHint),
|
||||
style: { width: '14px', height: '14px', borderRadius: '50%', border: '1px solid currentColor', background: 'transparent', color: 'inherit', fontSize: '10px', lineHeight: '12px', padding: '0', cursor: 'pointer', opacity: 0.65, fontFamily: 'inherit' },
|
||||
}, '?'),
|
||||
React.createElement('input', {
|
||||
type: 'checkbox',
|
||||
role: 'switch',
|
||||
checked: enabled,
|
||||
disabled: busy,
|
||||
'aria-label': label,
|
||||
onChange: (event: Event) => void toggle((event.target as HTMLInputElement).checked),
|
||||
}),
|
||||
showHint
|
||||
? React.createElement('div', {
|
||||
style: { position: 'absolute', top: '100%', left: '0', zIndex: 30, marginTop: '6px', width: '280px', padding: '8px 10px', borderRadius: '6px', background: 'rgba(24,24,28,0.94)', color: '#fff', fontSize: '12px', fontWeight: 400, lineHeight: '1.5', boxShadow: '0 4px 16px rgba(0,0,0,0.28)', whiteSpace: 'normal' },
|
||||
}, hint)
|
||||
: null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalRenderer) {
|
||||
const ServerNotice = createServerNotice(React)
|
||||
const HostPairingPanel = createHostPairingPanel(React)
|
||||
const RemoteToggleSwitch = createRemoteToggleSwitch(React)
|
||||
const FastModeSwitches = createFastModeSwitches(React)
|
||||
const RemoteProgressView = createRemoteProgressView(React)
|
||||
|
||||
/**
|
||||
|
|
@ -178,6 +115,8 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
const [showAllWorkspaces, setShowAllWorkspaces] = React.useState(false)
|
||||
const [showAllCodexWorkspaces, setShowAllCodexWorkspaces] = React.useState(false)
|
||||
const [devicesOpen, setDevicesOpen] = React.useState(false)
|
||||
const [upgradePhase, setUpgradePhase] = React.useState<'idle' | 'running' | 'verifying' | 'started' | 'failed' | 'unknown'>('idle')
|
||||
const [upgradeError, setUpgradeError] = React.useState<string | undefined>(undefined)
|
||||
const [showAllCursorWorkspaces, setShowAllCursorWorkspaces] = React.useState(false)
|
||||
const [showAllAntigravityWorkspaces, setShowAllAntigravityWorkspaces] = React.useState(false)
|
||||
const [showAllPiWorkspaces, setShowAllPiWorkspaces] = React.useState(false)
|
||||
|
|
@ -200,6 +139,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
const claudeWorkspaceListId = 'dsh-remote-claude-workspace-list'
|
||||
const hermesWorkspaceListId = 'dsh-remote-hermes-workspace-list'
|
||||
const [busy, setBusy] = React.useState(false)
|
||||
const [refreshingHosts, setRefreshingHosts] = React.useState(false)
|
||||
// Remain undecided until local credentials or an explicit auth rejection
|
||||
// establish that login is required. Network failures are not sign-outs.
|
||||
const [needsAuthorization, setNeedsAuthorization] = React.useState<boolean | undefined>(undefined)
|
||||
|
|
@ -613,6 +553,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
|
||||
const refreshRemote = async (): Promise<void> => {
|
||||
setBusy(true)
|
||||
setRefreshingHosts(true)
|
||||
setNotice(undefined)
|
||||
setError(undefined)
|
||||
try {
|
||||
|
|
@ -811,6 +752,7 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
} catch (reason) {
|
||||
setError(connectionErrorMessageFor(reason, t))
|
||||
} finally {
|
||||
setRefreshingHosts(false)
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
|
@ -1140,6 +1082,44 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
const updateNotice = updateInfo !== undefined && localUpdateAvailable
|
||||
? t('updateAvailable', { latest: updateInfo.latestVersion, current: updateInfo.currentVersion })
|
||||
: undefined
|
||||
const releasesUrl = 'https://github.com/rainow/ds-harness-remote-fast/releases'
|
||||
const canUpgradeInPlace = updateInfo?.upgrade === 'ready'
|
||||
const startLocalUpgrade = async (): Promise<void> => {
|
||||
if (!canUpgradeInPlace || updateInfo === undefined) return
|
||||
setUpgradePhase('running')
|
||||
setUpgradeError(undefined)
|
||||
try {
|
||||
const result = await props.control<{ status: string; message?: string }>('plugin.update', {
|
||||
version: updateInfo.latestVersion,
|
||||
})
|
||||
if (result.status === 'started') {
|
||||
setUpgradePhase('started')
|
||||
return
|
||||
}
|
||||
if (result.status === 'manual') {
|
||||
setUpgradePhase('idle')
|
||||
window.open(releasesUrl, '_blank', 'noopener')
|
||||
return
|
||||
}
|
||||
setUpgradePhase('failed')
|
||||
setUpgradeError(typeof result.message === 'string' && result.message !== '' ? result.message : t('pluginUpdateFailed'))
|
||||
} catch (reason) {
|
||||
// A lost response is ambiguous: the manager unloads this plugin once
|
||||
// installation starts, but a network error before the request reached
|
||||
// the Host looks identical. Decide from the Host's reported version.
|
||||
setUpgradePhase('verifying')
|
||||
const outcome = await settleLostUpgrade(
|
||||
() => props.control<RemoteStatus>('status'),
|
||||
updateInfo.latestVersion,
|
||||
)
|
||||
if (outcome === 'upgraded') {
|
||||
setUpgradePhase('started')
|
||||
return
|
||||
}
|
||||
setUpgradePhase('unknown')
|
||||
setUpgradeError(messageOf(reason, t))
|
||||
}
|
||||
}
|
||||
const deviceUpdateAvailable = (device: RemoteDevice): boolean =>
|
||||
updateInfo !== undefined
|
||||
&& device.clientVersion !== undefined
|
||||
|
|
@ -1254,9 +1234,9 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
disabled: busy,
|
||||
onClick: () => void openLocalWorkspaces(),
|
||||
}, t('exitRemote')) : null)
|
||||
// The Compact style drops the label and lives in the account row, so it is
|
||||
// always a plain icon button regardless of the current Remote mode.
|
||||
const accountEntry = React.createElement('div', { className: `dshRemoteAccountEntry${remoteActive ? ' isActive' : ''}` },
|
||||
// Compact stays in the account row, but remote mode must expose the Host
|
||||
// identity and the same explicit exit action as the standard entry.
|
||||
const accountEntry = remoteActive ? entry : React.createElement('div', { className: `dshRemoteAccountEntry${remoteActive ? ' isActive' : ''}` },
|
||||
React.createElement('button', {
|
||||
type: 'button',
|
||||
className: 'dshRemoteAccountEntryButton',
|
||||
|
|
@ -1478,14 +1458,13 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
checked: status.host?.authorized === true,
|
||||
onChange: (event: Event) => void setCurrentDeviceControl((event.target as HTMLInputElement).checked),
|
||||
})) : null,
|
||||
React.createElement(RemoteToggleSwitch, { control: props.control, t, configKey: 'liteMode' }),
|
||||
React.createElement(RemoteToggleSwitch, { control: props.control, t, configKey: 'forceRelay' }),
|
||||
connectedMenu)),
|
||||
React.createElement(FastModeSwitches, { control: props.control, t }),
|
||||
React.createElement('div', {
|
||||
className: `dshRemoteHostList${connectingHost === undefined ? '' : ' isCollapsed'}`,
|
||||
'aria-busy': connectingHost === undefined ? undefined : true,
|
||||
}, listedHosts.length === 0
|
||||
? (error !== undefined ? null : React.createElement('p', null, busy ? t('checkingConnection') : t(status?.host?.pairingHostOnly ? 'pairingHostOnly' : 'noRemoteHosts')))
|
||||
? (error !== undefined || refreshingHosts ? null : React.createElement('p', null, t(status?.host?.pairingHostOnly ? 'pairingHostOnly' : 'noRemoteHosts')))
|
||||
: listedHosts.map(device => React.createElement('button', {
|
||||
type: 'button',
|
||||
key: device.deviceId,
|
||||
|
|
@ -1506,6 +1485,8 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
? (connectingHost === undefined ? React.createElement(React.Fragment, null,
|
||||
status?.host?.pairingHostOnly ? null : React.createElement('p', { className: 'dshRemoteHint' }, t('selectHostHint')),
|
||||
React.createElement('footer', { className: 'dshRemoteAccountFooter' },
|
||||
refreshingHosts ? React.createElement('span', { className: 'dshRemoteHostLoading', role: 'status', 'aria-label': t('checkingConnection') },
|
||||
React.createElement('span', { className: 'dshRemoteLoginSpinner', 'aria-hidden': true })) : null,
|
||||
React.createElement('span', { className: 'dshRemoteHostNameLine' },
|
||||
React.createElement('span', null, status?.target?.name ?? status?.deviceName ?? (status?.host?.account === undefined ? t('account') : displayRemoteAccount(status.host.account))),
|
||||
React.createElement(ServerNotice, {
|
||||
|
|
@ -1513,13 +1494,36 @@ export function createRemoteWorkspaceAction(React: ClientReact, portal?: PortalR
|
|||
linked: connectedCount > 0 || status?.connected === true,
|
||||
expiresAt: status?.host?.recoveryExpiresAt ?? status?.network?.recoveryExpiresAt, t,
|
||||
})),
|
||||
updateNotice === undefined ? null : React.createElement('a', {
|
||||
className: 'dshRemoteAccountUpdate',
|
||||
href: 'https://github.com/rainow/ds-harness-remote-fast/releases',
|
||||
target: '_blank',
|
||||
rel: 'noreferrer',
|
||||
title: updateNotice,
|
||||
}, t('updateAvailableShort', { version: updateInfo?.latestVersion ?? '' })),
|
||||
updateNotice === undefined ? null : canUpgradeInPlace
|
||||
? React.createElement(React.Fragment, null,
|
||||
React.createElement('button', {
|
||||
type: 'button',
|
||||
className: 'dshRemoteAccountUpdate',
|
||||
disabled: upgradePhase === 'running' || upgradePhase === 'verifying' || upgradePhase === 'started',
|
||||
title: upgradePhase === 'failed' || upgradePhase === 'unknown' ? upgradeError ?? updateNotice : updateNotice,
|
||||
onClick: () => void startLocalUpgrade(),
|
||||
}, t(
|
||||
upgradePhase === 'running' || upgradePhase === 'verifying' ? 'pluginUpdating'
|
||||
: upgradePhase === 'started' ? 'pluginUpdateReload'
|
||||
: upgradePhase === 'failed' ? 'pluginUpdateFailed'
|
||||
: upgradePhase === 'unknown' ? 'pluginUpdateUnknown'
|
||||
: 'updateAvailableShort',
|
||||
{ version: updateInfo?.latestVersion ?? '' },
|
||||
)),
|
||||
React.createElement('a', {
|
||||
className: 'dshRemoteAccountUpdate',
|
||||
href: releasesUrl,
|
||||
target: '_blank',
|
||||
rel: 'noreferrer',
|
||||
title: updateNotice,
|
||||
}, t('pluginUpdateManual')))
|
||||
: React.createElement('a', {
|
||||
className: 'dshRemoteAccountUpdate',
|
||||
href: releasesUrl,
|
||||
target: '_blank',
|
||||
rel: 'noreferrer',
|
||||
title: updateNotice,
|
||||
}, t('updateAvailableShort', { version: updateInfo?.latestVersion ?? '' })),
|
||||
props.openSettings === undefined ? null : React.createElement('button', {
|
||||
type: 'button', className: 'dshRemoteAccountSettings',
|
||||
onClick: props.openSettings,
|
||||
|
|
|
|||
Loading…
Reference in New Issue