feat(desktop): report current user online clients

This commit is contained in:
2026-05-06 18:25:05 +08:00
parent 930f095c64
commit 47681ab1f5
12 changed files with 297 additions and 12 deletions
@@ -203,6 +203,7 @@ export interface RuntimeControllerSnapshot {
lastPullStatus: 'idle' | 'success' | 'failed'
lastAccountsSyncAt: number
lastServerTime: string | null
onlineClientCount: number | null
lastError: string | null
}
@@ -251,6 +252,7 @@ interface RuntimeState {
lastPullStatus: 'idle' | 'success' | 'failed'
lastAccountsSyncAt: number
lastServerTime: string | null
onlineClientCount: number | null
lastError: string | null
activitySeq: number
}
@@ -280,6 +282,7 @@ const state: RuntimeState = {
lastPullStatus: 'idle',
lastAccountsSyncAt: 0,
lastServerTime: null,
onlineClientCount: null,
lastError: null,
activitySeq: 0,
}
@@ -532,6 +535,7 @@ export function getRuntimeControllerSnapshot(): RuntimeControllerSnapshot {
lastPullStatus: state.lastPullStatus,
lastAccountsSyncAt: state.lastAccountsSyncAt,
lastServerTime: state.lastServerTime,
onlineClientCount: state.onlineClientCount,
lastError: state.lastError,
}
}
@@ -627,6 +631,7 @@ function clearRuntimeState(): void {
state.lastPullStatus = 'idle'
state.lastAccountsSyncAt = 0
state.lastServerTime = null
state.onlineClientCount = null
state.lastError = null
state.publishFallbackBackoffUntil = 0
setSchedulerQueueDepth(localQueueDepth())
@@ -977,6 +982,8 @@ async function sendHeartbeat(source: 'startup' | 'timer'): Promise<void> {
state.lastHeartbeatAt = Date.now()
state.lastHeartbeatStatus = 'success'
state.lastServerTime = response.server_time
state.onlineClientCount =
response.current_user_online_client_count ?? response.online_client_count ?? null
state.lastError = null
noteTransportHeartbeat(true)