fix(desktop): wait for channel status to settle before returning

The listStates IPC handler now waits for any "starting" status to
settle (max 3.5s) before returning, ensuring the UI always gets the
final status (running/error) instead of the transient "starting" state.

Also fixes unused variable lint warning in profile page.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Naiyuan Qing 2026-02-12 16:25:48 +08:00
parent 07c05b145c
commit 304c6a9bc6
2 changed files with 13 additions and 2 deletions

View file

@ -30,11 +30,22 @@ function maskToken(token: unknown): string | undefined {
export function registerChannelsIpcHandlers(): void {
/**
* List all channel account states (running / stopped / error).
* Waits for any "starting" status to settle before returning.
*/
ipcMain.handle('channels:listStates', async () => {
const hub = getCurrentHub()
if (!hub) return []
return hub.channelManager.listAccountStates()
let states = hub.channelManager.listAccountStates()
// Wait for "starting" status to settle (max 3.5s, since internal timeout is 3s)
const start = Date.now()
while (states.some(s => s.status === 'starting') && Date.now() - start < 3500) {
await new Promise(r => setTimeout(r, 100))
states = hub.channelManager.listAccountStates()
}
return states
})
/**

View file

@ -26,7 +26,7 @@ export default function ProfilePage() {
const { providers, current, setProvider, refresh, loading: providerLoading } = useProviderStore()
const [profileLoading, setProfileLoading] = useState(true)
const [saving, setSaving] = useState(false)
const [_saving, setSaving] = useState(false)
const [name, setName] = useState('')
const [userContent, setUserContent] = useState('')
const [hasChanges, setHasChanges] = useState(false)