feat: 更新 UI 状态管理,移除全局状态显示并优化连接状态指示

This commit is contained in:
cmliu committed 2026-07-29 12:21:19 +08:00
1 parent b8b2f63073
commit 2a685aaba3
4 files changed
+77 -72

No files matched your search

+9 -11
View File
@@ -43,10 +43,6 @@
</div>
<div class="topbar-actions">
<div id="global-status" class="status-pill" data-state="idle" role="status" aria-live="polite">
<span class="status-dot"></span>
<span id="global-status-label">离线</span>
</div>
<button id="language-toggle" class="icon-button" type="button" aria-label="切换到英文" title="切换到英文" data-language="zh-CN">
<span class="language-icon" aria-hidden="true"><span>中</span><span>E</span></span>
</button>
@@ -248,7 +244,7 @@
data-i18n-aria-label-zh="实时连接状态"
data-i18n-aria-label-en="Live connection status"
>
<span class="live-orb" id="live-orb"></span>
<span class="live-orb idle" id="live-orb" role="status" aria-live="polite" aria-label="离线" title="离线"></span>
<div>
<strong id="session-title">无活动会话</strong>
<span id="session-subtitle">选择目标并连接</span>
@@ -297,9 +293,10 @@
aria-controls="file-manager-panel"
aria-expanded="false"
tabindex="0"
data-i18n-zh="文件管理"
data-i18n-en="Files"
>文件管理</button>
>
<svg class="dock-tab-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M3.5 7.5h6l2-2h9a1.5 1.5 0 0 1 1.5 1.5v11a1.5 1.5 0 0 1-1.5 1.5h-17A1.5 1.5 0 0 1 2 18V9a1.5 1.5 0 0 1 1.5-1.5Z" /></svg>
<span data-i18n-zh="文件管理" data-i18n-en="Files">文件管理</span>
</button>
<button
id="event-toggle"
class="dock-tab"
@@ -309,9 +306,10 @@
aria-controls="event-log"
aria-expanded="false"
tabindex="-1"
data-i18n-zh="会话日志"
data-i18n-en="Session log"
>会话日志</button>
>
<svg class="dock-tab-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 2.5h9l4 4V21H6a2 2 0 0 1-2-2V4.5a2 2 0 0 1 2-2Z" /><path d="M15 2.5V7h4M8 11h7M8 15h7" /></svg>
<span data-i18n-zh="会话日志" data-i18n-en="Session log">会话日志</span>
</button>
</div>
</div>
+4 -5
View File
@@ -272,8 +272,6 @@ const ui = {
formError: element<HTMLElement>('form-error'),
connect: element<HTMLButtonElement>('connect-button'),
shareLink: element<HTMLButtonElement>('share-link'),
globalStatus: element<HTMLElement>('global-status'),
globalStatusLabel: element<HTMLElement>('global-status-label'),
languageToggle: element<HTMLButtonElement>('language-toggle'),
themeToggle: element<HTMLButtonElement>('theme-toggle'),
sessionTitle: element<HTMLElement>('session-title'),
@@ -1049,8 +1047,7 @@ function toast(message: string, kind: 'info' | 'error' = 'info'): void {
function setState(state: ConnectionState, label?: string): void {
connectionState = state;
ui.globalStatus.dataset.state = state;
ui.globalStatusLabel.textContent = label ?? ({
const stateLabel = label ?? ({
idle: bilingual('离线', 'Offline'),
connecting: bilingual('连接中', 'Connecting'),
connected: bilingual('在线', 'Online'),
@@ -1058,6 +1055,8 @@ function setState(state: ConnectionState, label?: string): void {
error: bilingual('错误', 'Error'),
} satisfies Record<ConnectionState, string>)[state];
ui.liveOrb.className = `live-orb ${state}`;
ui.liveOrb.setAttribute('aria-label', stateLabel);
ui.liveOrb.title = stateLabel;
const control = resolveConnectionControl(state, historyPasswordLoading);
const controlLabel = control.action === 'cancel'
? bilingual('取消连接', 'Cancel connection')
@@ -1489,7 +1488,7 @@ async function connect(): Promise<void> {
ui.sessionSubtitle.textContent = localize(currentSessionSubtitle);
ui.metricRtt.textContent = '--';
ui.metricHostKey.textContent = '--';
event(bilingual(`正在连接 ${username}@${host}:${port}`, `Starting ${username}@${host}:${port}`), 'connect');
event(bilingual(`正在连接 ${currentTargetLabel}`, `Starting ${currentTargetLabel}`), 'connect');
try {
const password = ui.password.value;
+59 -55
View File
@@ -147,8 +147,7 @@ button:disabled {
.event-bar,
.file-picker,
.profile-main,
.profile-meta,
.status-pill {
.profile-meta {
display: flex;
align-items: center;
}
@@ -289,69 +288,72 @@ button:disabled {
stroke: none;
}
.status-pill {
gap: 7px;
min-width: 92px;
justify-content: center;
padding: 7px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--surface);
color: var(--muted);
font-family: var(--mono);
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
}
.status-dot,
.live-orb {
position: relative;
display: block;
width: 7px;
height: 7px;
width: 9px;
height: 9px;
flex: 0 0 auto;
margin: 0 2px;
border-radius: 50%;
background: var(--muted-2);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted-2) 14%, transparent);
box-shadow:
0 0 0 3px color-mix(in srgb, var(--muted-2) 16%, transparent),
inset 0 1px 1px rgba(255, 255, 255, 0.25);
transition: background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}
.live-orb::after {
position: absolute;
inset: -5px;
border: 1px solid transparent;
border-radius: inherit;
content: '';
pointer-events: none;
}
.status-pill[data-state='connecting'] .status-dot,
.live-orb.connecting {
background: var(--warning);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 14%, transparent);
animation: pulse 1.25s ease-in-out infinite;
box-shadow:
0 0 0 3px color-mix(in srgb, var(--warning) 18%, transparent),
0 0 12px color-mix(in srgb, var(--warning) 42%, transparent);
}
.status-pill[data-state='disconnecting'] {
color: var(--danger);
.live-orb.connecting::after {
border-color: color-mix(in srgb, var(--warning) 50%, transparent);
animation: live-orb-ring 1.35s ease-out infinite;
}
.status-pill[data-state='disconnecting'] .status-dot,
.live-orb.disconnecting {
background: var(--danger);
box-shadow: 0 0 0 3px var(--danger-dim);
animation: pulse 1.25s ease-in-out infinite;
box-shadow:
0 0 0 3px var(--danger-dim),
0 0 10px color-mix(in srgb, var(--danger) 35%, transparent);
animation: live-orb-pulse 1.1s ease-in-out infinite;
}
.status-pill[data-state='connected'] {
border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
color: var(--accent);
}
.status-pill[data-state='connected'] .status-dot,
.live-orb.connected {
background: var(--accent);
box-shadow: 0 0 0 3px var(--accent-dim), 0 0 12px color-mix(in srgb, var(--accent) 50%, transparent);
box-shadow:
0 0 0 3px var(--accent-dim),
0 0 14px color-mix(in srgb, var(--accent) 55%, transparent),
inset 0 1px 1px rgba(255, 255, 255, 0.35);
}
.status-pill[data-state='error'] {
color: var(--danger);
}
.status-pill[data-state='error'] .status-dot,
.live-orb.error {
background: var(--danger);
box-shadow: 0 0 0 3px var(--danger-dim);
box-shadow:
0 0 0 3px var(--danger-dim),
0 0 12px color-mix(in srgb, var(--danger) 45%, transparent);
}
@keyframes live-orb-ring {
0% { opacity: 0.9; transform: scale(0.55); }
75%, 100% { opacity: 0; transform: scale(1.35); }
}
@keyframes live-orb-pulse {
50% { transform: scale(0.72); opacity: 0.7; }
}
.app-shell {
@@ -1141,7 +1143,11 @@ button:disabled {
.dock-tab {
position: relative;
display: inline-flex;
min-width: 92px;
align-items: center;
justify-content: center;
gap: 6px;
padding: 0 13px;
border: 0;
border-left: 1px solid var(--border);
@@ -1151,6 +1157,17 @@ button:disabled {
font-size: inherit;
}
.dock-tab-icon {
width: 14px;
height: 14px;
flex: 0 0 auto;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.7;
}
.dock-tab:hover {
background: var(--surface-3);
color: var(--text);
@@ -1665,10 +1682,6 @@ button:disabled {
display: none;
}
@keyframes pulse {
50% { opacity: 0.45; }
}
@keyframes toast-in {
from { opacity: 0; transform: translateY(8px); }
}
@@ -1810,15 +1823,6 @@ button:disabled {
display: none;
}
.status-pill {
min-width: 0;
padding: 7px 9px;
}
#global-status-label {
display: none;
}
.field-grid.two {
grid-template-columns: 1fr;
}
+5 -1
View File
@@ -130,7 +130,11 @@ export class SSHSessionDO implements DurableObject {
if (config.port === 25) throw new Error('Cloudflare Workers cannot connect to outbound TCP port 25');
const verifiedAddresses = await assertPublicTarget(config.host);
this.assertConnectionActive(ws, pending);
ws.send(JSON.stringify({ type: 'status', event: 'tcp_connecting', message: `Connecting to ${config.host}:${config.port}` }));
ws.send(JSON.stringify({
type: 'status',
event: 'tcp_connecting',
message: `Connecting to ${toSocketHostname(config.host)}:${config.port}`,
}));
// Connect to the exact address that passed SSRF validation. Keeping the
// original hostname only for host-key pinning prevents DNS rebinding.