mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Routes preview://event (navigated/ready) from Rust into the browser store via a new subscribePreviewEvents subscriber; adds title field and setNavigated/setReady reducers to BrowserSessionState; BrowserSurface subscribes on mount to replace M1 optimistic nav-state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
14 lines
638 B
TypeScript
14 lines
638 B
TypeScript
import { listen } from '@tauri-apps/api/event'
|
|
import { useBrowserPanelStore } from '../stores/browserPanelStore'
|
|
|
|
export async function subscribePreviewEvents(sessionId: string): Promise<() => void> {
|
|
return listen<string>('preview://event', (e) => {
|
|
let msg: { type?: string; url?: string; title?: string }
|
|
try { msg = JSON.parse(e.payload) } catch { return }
|
|
const store = useBrowserPanelStore.getState()
|
|
if (msg.type === 'navigated' && msg.url) store.setNavigated(sessionId, msg.url, msg.title ?? '')
|
|
else if (msg.type === 'ready') store.setReady(sessionId)
|
|
// selection / screenshot 在 M4/M5 接入
|
|
})
|
|
}
|