Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## [v1.0.9] - 2026-10-21

- build: 去掉 Docker 镜像打包,Linux 改出 AppImage (2e3fba5a)
- fix(android): SSE 重连时对话区不再闪一下(像页面刷新) (75bc5c8f)
- chore: bump version to 0.7.21 (6e31eb01)
- fix(server): 健康检查探当前生效地址,不再盯着列表第一行 (e846d751)
- fix(settings): 地址列表默认收起,多入口不再把卡片撑成半屏 (46c1b259)
- chore: bump version to 0.7.20 (16f72544)
- refactor(settings): 地址列表成为唯一数据源,去掉重复的 URL 输入框 (82481049)
- feat(settings): 地址列表可手动增删排序,多地址不再只能靠重新配对 (0ccecccf)
- test(e2e): 真实服务端上的多地址探测、切换与延迟验证 (a6163db2)
- feat(server): 同一服务器支持多地址,内网优先、不可达降级、恢复后切回 (720e6a25)
- fix(reconnect): 网络恢复时主动重建半开连接,补齐面板补偿拉取 (35a7f7a8)
- feat(terminal): 终端字号与字体可独立调节 (8a460855)
- feat(panels): 文件改为在面板标签栏开新标签页打开 (965d35a1)
- fix(mobile): 触摸目标改为显式 opt-in,手机不再把按钮单方面顶高 (8e02ce37)
- style(markdown): 内联代码改用 0.875em/19px 的行内配比,修正垂直不居中 (08877a09)
- fix(reasoning): 折叠行里的行内代码去掉盒子,不再被裁掉上下边框 (ef948762)

## [v1.0.8] - 2026-10-19

- chore: bump version to 0.7.19 (81158b7e)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opencodeui",
"version": "1.0.8",
"version": "1.0.9",
"description": "A third-party web frontend for OpenCode",
"license": "GPL-3.0-only",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opencodeui"
version = "1.0.8"
version = "1.0.9"
description = "OpenCode UI - Tauri Mobile App"
authors = ["lehhair"]
license = "GPL-3.0-only"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "OpenCode",
"version": "1.0.8",
"version": "1.0.9",
"identifier": "com.opencodeui.app",
"build": {
"frontendDist": "../dist",
Expand Down
87 changes: 87 additions & 0 deletions src/api/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,50 @@ describe('v2 event dispatch', () => {
}
})

/**
* 断网又恢复:TCP 半开时流既不报错也不结束,连接状态会一直停在
* connected,只能等看门狗(45s 静默 + 15s tick)才发现。期间 UI 完全
* 不刷新 —— 用户的观感就是「网回来了但界面死的,得手动刷新」。
*
* online 事件是外部事实:网络确实变了,此时若连接已静默超过一个心跳
* 周期,就该主动掐断重连,而不是相信 state === 'connected'。
*/
it('forces a reconnect on online when the connected stream has gone silent', async () => {
vi.useFakeTimers()
try {
const harnesses: Array<ReturnType<typeof createEventStream>> = []
subscribeMock.mockImplementation(() => {
const harness = createEventStream()
harnesses.push(harness)
return harness.stream
})

const { subscribeToServerEvents, getServerConnectionInfo } = await import('./events')
const onReconnected = vi.fn()
const unsubscribe = subscribeToServerEvents('test-server', { onReconnected })
await Promise.resolve()

// 建立连接并保持有心跳
harnesses[0].emit(v2Event('session.idle', { sessionID: 's1' }))
await vi.advanceTimersByTimeAsync(0)
expect(getServerConnectionInfo('test-server').state).toBe('connected')

// 断网:心跳停了,连接状态仍是 connected(半开),且已静默超过阈值。
// 只推进到不足看门狗阈值,确保不是看门狗救的场。
await vi.advanceTimersByTimeAsync(25_000)
expect(getServerConnectionInfo('test-server').state).toBe('connected')

window.dispatchEvent(new Event('online'))
await vi.advanceTimersByTimeAsync(6_000)

// 半开连接被主动掐断并重连(不是等 45s 看门狗)
expect(subscribeMock.mock.calls.length).toBeGreaterThanOrEqual(2)
unsubscribe()
} finally {
vi.useRealTimers()
}
})

/**
* 端点变更重连必须广播 onReconnected:否则订阅者不做补偿拉取,
* WSL 端口变化等场景下状态/权限/消息全部陈旧。
Expand Down Expand Up @@ -381,4 +425,47 @@ describe('v2 event dispatch', () => {

unsubscribe()
})

/**
* 换入口地址(Issue #183):重连照做,但补偿广播必须是 'network'。
* 广播成 'server-switch' 会被 SessionContext / useSessions 显式跳过
* (那条路径假定 onServerChange 链负责重拉),换地址没有那条链,跳过就没人刷。
*/
it('broadcasts onReconnected with network reason on endpoint switch reconnect', async () => {
const harnesses: Array<ReturnType<typeof createEventStream>> = []
subscribeMock.mockImplementation(() => {
const harness = createEventStream()
harnesses.push(harness)
return harness.stream
})

const { subscribeToServerEvents, reconnectServerSSE } = await import('./events')
const onReconnected = vi.fn()
const unsubscribe = subscribeToServerEvents('test-server', { onReconnected })
await Promise.resolve()

// 先建立一次连接,让 hasConnectedBefore = true
harnesses[0].emit(v2Event('session.idle', { sessionID: 's1' }))
await new Promise(resolve => setTimeout(resolve, 0))
expect(onReconnected).not.toHaveBeenCalled()

reconnectServerSSE('test-server', { reason: 'network' })
await Promise.resolve()
expect(harnesses.length).toBe(2)

harnesses[1].emit(v2Event('session.idle', { sessionID: 's1' }))
await new Promise(resolve => setTimeout(resolve, 0))
expect(onReconnected).toHaveBeenCalledWith('network')

unsubscribe()
})

/**
* 对没有任何订阅(因此没有连接)的服务器重连是空操作:
* 不该凭空创建连接对象,否则多地址探测每次切换都会往 Map 里塞死条目。
*/
it('reconnectServerSSE is a no-op for a server with no connection', async () => {
const { reconnectServerSSE } = await import('./events')
expect(() => reconnectServerSSE('never-subscribed', { reason: 'network' })).not.toThrow()
})
})
82 changes: 72 additions & 10 deletions src/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ const serverSwitchFlags = new Map<string, boolean>()
* 数据刷新由 server-change 监听器负责,首个连接不能重复广播;而这里针对的是
* 「本地 serve 就绪地址回写 / WSL 换端口后,初始拉取已在端点就绪前失败」,
* 首个成功连接必须广播让订阅者补偿拉取,否则失败态没有重试入口。
*
* 存的是 **广播 reason** 而不是布尔:默认 'server-switch'(保持既有行为),
* 换入口地址(Issue #183)传 'network'——数据主体没变,不该按换服务器处理。
*/
const endpointReconnectFlags = new Map<string, boolean>()
const endpointReconnectFlags = new Map<string, 'network' | 'server-switch'>()

let lifecycleListenersRegistered = false
let isInBackground = false
Expand Down Expand Up @@ -104,6 +107,15 @@ const IDLE_TIMEOUT = 45_000
* 走重连循环(官方客户端 connectTimeout 2s,这里取更宽容的 15s)。
*/
const CONNECT_STALL_TIMEOUT = 15_000
/**
* 网络恢复(online)时,连接静默多久就判定为「半开」并主动重连。
*
* 服务端心跳 15s,正常在线时 lastEventTime 最多落后一个心跳间隔。断网期间
* 心跳收不到,恢复时往往已经静默很久——这种情况不能等看门狗 45s,否则
* 用户看到的就是「网回来了界面还是死的」。取 20s:比心跳间隔略长,避免
* 刚收到心跳就被误判。
*/
const ONLINE_RESUME_SILENCE_MS = 20_000

const DEFAULT_CONNECTION_INFO: ConnectionInfo = {
state: 'disconnected',
Expand Down Expand Up @@ -584,7 +596,7 @@ async function connectServer(serverId: string): Promise<void> {
// 首次连接一般不广播 onReconnected:初始加载由各订阅方自己拉取。
// 但端点变更触发的重连(本地 serve 就绪 / WSL 换端口),此前的初始
// 拉取可能已在端点就绪前失败,必须广播让订阅者补偿拉取。
const endpointReconnect = endpointReconnectFlags.get(serverId) === true
const endpointReconnect = endpointReconnectFlags.get(serverId)
endpointReconnectFlags.delete(serverId)
serverSwitchFlags.delete(serverId)
updateConnectionState(serverId, {
Expand All @@ -593,7 +605,7 @@ async function connectServer(serverId: string): Promise<void> {
error: undefined,
})
if (endpointReconnect) {
broadcastReconnected(conn, 'server-switch')
broadcastReconnected(conn, endpointReconnect)
}
} else if (conn.info.state !== 'connected') {
updateConnectionState(serverId, { state: 'connected', reconnectAttempt: 0, error: undefined })
Expand Down Expand Up @@ -707,8 +719,36 @@ function registerLifecycleListeners(): void {

window.addEventListener('online', () => {
for (const conn of connections.values()) {
if (conn.subscribers.size > 0 && conn.info.state !== 'connected') {
if (conn.subscribers.size === 0) continue

if (conn.info.state !== 'connected') {
connectServer(conn.serverId)
continue
}

/**
* 状态停在 connected 不等于连着:断网时 TCP 常常是半开的——流既不报错
* 也不结束,状态就一直挂着,直到看门狗 45s 后才发现。等那么久,用户看到
* 的就是「网回来了但界面不动,得刷新」。
*
* 网络恢复是外部事实:此时若已有一段时间没收到任何字节(含心跳),
* 就当作可疑连接主动掐断重连。阈值取得比看门狗短得多——断网期间心跳
* 必然收不到,恢复后按心跳间隔算早该有几个了。
*/
const silentFor = Date.now() - conn.info.lastEventTime
if (conn.info.lastEventTime > 0 && silentFor > ONLINE_RESUME_SILENCE_MS) {
conn.watchdogDrop = true
conn.controller?.abort()
setTimeout(() => {
if (conn.isConnecting) {
conn.generation += 1
conn.isConnecting = false
conn.watchdogDrop = false
conn.connectStartedAt = 0
updateConnectionState(conn.serverId, { state: 'disconnected' })
scheduleReconnect(conn)
}
}, 5_000)
}
}
})
Expand Down Expand Up @@ -739,9 +779,23 @@ function stopBackgroundKeepalive(): void {

/**
* 强制重连指定服务器。
*
* @param options.reason 重连成功后广播给订阅者的 reason。默认 'server-switch'
* (换服务器 / 端点变更,数据由 onServerChange 链负责重拉)。
*
* 同一台服务器换入口地址(Issue #183)、网络恢复后的自我修复,数据主体
* 都没变,必须传 'network':消费方对 'server-switch' 是显式跳过的
* (换服务器由 onServerChange 链负责),跳过就没人补拉断流窗口里丢的
* 消息、权限、会话状态了。
*/
export function reconnectServerSSE(serverId: string): void {
const conn = getOrCreateConnection(serverId)
export function reconnectServerSSE(
serverId: string,
options?: { reason?: 'network' | 'server-switch' },
): void {
// 没有连接的服务器(没人订阅)无需重连,也避免凭空创建空的连接对象
const existing = connections.get(serverId)
if (!existing) return
const conn = existing
conn.info = { ...conn.info, reconnectAttempt: 0 }
// disconnectServerConnection 会把 hasConnectedBefore 重置为 false,
// 导致端点变更(如 WSL 端口变化)后的重连被当成「首次连接」,
Expand All @@ -750,12 +804,16 @@ export function reconnectServerSSE(serverId: string): void {
// 让重连成功走「重连 → 补偿拉取」链路。
const hadConnected = conn.hasConnectedBefore
disconnectServerConnection(conn)
const reason = options?.reason ?? 'server-switch'
if (hadConnected) {
conn.hasConnectedBefore = true
serverSwitchFlags.set(serverId, true)
// server-switch 需要走「换服务器」语义;其余(换入口/网络自愈)按普通重连补偿
if (reason === 'server-switch') {
serverSwitchFlags.set(serverId, true)
}
} else {
// 此前从未连上:首个成功连接也要走补偿广播(见 endpointReconnectFlags 注释)
endpointReconnectFlags.set(serverId, true)
endpointReconnectFlags.set(serverId, reason)
}
if (conn.subscribers.size > 0) {
connectServer(serverId)
Expand All @@ -765,8 +823,8 @@ export function reconnectServerSSE(serverId: string): void {
/**
* 强制重连活动服务器(兼容旧 API)。
*/
export function reconnectSSE(): void {
reconnectServerSSE(serverStore.getActiveServerId())
export function reconnectSSE(options?: { reason?: 'network' | 'server-switch' }): void {
reconnectServerSSE(serverStore.getActiveServerId(), options)
}

/**
Expand Down Expand Up @@ -874,6 +932,10 @@ export function subscribeToEvents(callbacks: EventCallbacks): () => void {
if (reason === 'server-runtime-updated') {
if (newServerId !== currentServerId) return
} else if (newServerId === currentServerId) {
// endpoint-switch 也走这里:同一台服务器换入口地址,serverId 没变,
// 订阅无需迁移。连接的重连由 events 模块的中央监听器负责
// (reconnectServerSSE(..., { reason: 'network' })),重连成功后
// broadcastReconnected 会通知该连接的全部订阅者补偿拉取。
return
}
unsubscribe()
Expand Down
3 changes: 1 addition & 2 deletions src/components/DiffViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ function CollapsedExpandButton({
<button
key={direction}
type="button"
data-compact=""
data-expand-button=""
data-expand-up={direction === 'up' ? '' : undefined}
data-expand-down={direction === 'down' ? '' : undefined}
Expand Down Expand Up @@ -454,7 +453,7 @@ function CollapsedLabel({
<div className="diff-separator-content-row" style={{ height }}>
{leadingDirections.length > 0 && <CollapsedExpandButton directions={leadingDirections} onExpand={onExpand} />}
<div data-separator-content="" className="diff-separator-content">
<button type="button" data-compact="" data-unmodified-lines="" className="diff-separator-text-button" onClick={() => onExpand?.('both')}>
<button type="button" data-unmodified-lines="" className="diff-separator-text-button" onClick={() => onExpand?.('both')}>
{t('diffViewer.linesUnchanged', { count })}
</button>
</div>
Expand Down
18 changes: 12 additions & 6 deletions src/components/MarkdownRenderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,22 @@ describe('MarkdownRenderer', () => {
render(<MarkdownRenderer content={'Use `code` here'} />)

const codeEl = screen.getByText('code')
// chip 样式:等宽 + 淡底 + 细描边 + flex 垂直居中;颜色继承正文
// chip:等宽 + 淡底 + 细描边 + flex 垂直居中;颜色继承正文
expect(codeEl.className).toMatch(/font-mono/)
expect(codeEl.className).not.toMatch(/text-text-\d/)
expect(codeEl.className).toMatch(/bg-bg-200/)
expect(codeEl.className).toMatch(/border-\[0\.5px\]/)
expect(codeEl.className).toMatch(/rounded-md/)
expect(codeEl.className).toMatch(/px-\[5px\]/)
// 纵向不能靠继承段落行高(leading-7=28px):chip 会高出一截,和正文对不上
expect(codeEl.className).toMatch(/inline-flex/)
expect(codeEl.className).toMatch(/items-center/)
expect(codeEl.className).toMatch(/leading-tight/)
// 居中不是靠调行高(行高只等比拉长上下留白,字体 ascent/descent 的不对称不变),
// 而是靠字号比例:0.875em(14px 正文 → 12.25px)+ 19px 行高,实测拉丁 −1.5px /
// 中文 +1.5px,是偏差最小的平衡点(配方对齐 DeepSeek Harness 的内联代码)
expect(codeEl.className).toMatch(/leading-\[19px\]/)
expect(codeEl.className).toMatch(/text-\[0\.875em\]/)
expect(codeEl.className).not.toMatch(/pb-\[/)
expect(codeEl.className).not.toMatch(/leading-none/)
expect(codeEl.className).not.toMatch(/text-accent-main/)
})

Expand All @@ -122,8 +127,8 @@ describe('MarkdownRenderer', () => {
expect(codeEl).toBeInTheDocument()
expect(codeEl).toHaveTextContent('单行代码')
expect(codeEl).toHaveClass('font-mono')
expect(codeEl).toHaveClass('bg-bg-200')
expect(codeEl).toHaveClass('inline-flex')
expect(codeEl).toHaveClass('bg-bg-200')
})

it('keeps inline emphasis styles on the markdown path', () => {
Expand Down Expand Up @@ -550,9 +555,10 @@ $$
expect(paragraph.className).toMatch(/text-text-400/)

const codeEl = screen.getByText('code')
// chip 也有描边(0.5px 细边),但底色不能是强调色
expect(codeEl.className).toMatch(/border-\[0\.5px\]/)
// reasoning 里 chip 与正文同款(不是强调色、行高/内边距与正文版一致)
expect(codeEl.className).not.toMatch(/bg-accent/)
expect(codeEl.className).toMatch(/leading-\[19px\]/)
expect(codeEl.className).toMatch(/text-\[0\.875em\]/)
})

it('passes reasoning variant to CodeBlock', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ function renderInlineTokensToReact(tokens: unknown[], _isReasoning: boolean): Re
return (
<code
key={index}
className="inline-flex items-center font-mono text-[0.875em] leading-tight py-px break-words bg-bg-200 border-[0.5px] border-text-100/10 rounded-md px-[5px]"
className="inline-flex items-center font-mono text-[0.875em] leading-[19px] break-words bg-bg-200 border-[0.5px] border-text-100/10 rounded-md px-[5px]"
>
{String(item.text ?? '')}
</code>
Expand Down
Loading
Loading