// Optional bridge exposed by the Electron preload (desktop/src/preload.js). Absent in a normal browser. export interface DesktopBridge { notify: (title: string, body: string) => void; openSettings: () => void; version: string; } declare global { interface Window { fptDesktop?: DesktopBridge } } export const desktop = (): DesktopBridge | undefined => (typeof window !== 'undefined' ? window.fptDesktop : undefined); const NOTIFY_ON: Record = { waiting_approval: 'is waiting for case approval', waiting_sign_in: 'is waiting for someone to sign in to the pod', waiting_review: 'is waiting for defect review', completed: 'finished', failed: 'failed', killed: 'was stopped by the kill switch', }; /** Compare two run-status snapshots; returns notification texts for runs that changed into an attention state. */ export function statusTransitions(prev: Record, next: Record): { title: string; body: string }[] { const out: { title: string; body: string }[] = []; for (const [id, raw] of Object.entries(next)) { const [st, attention] = raw.split('|'); const [pst, pattention] = (prev[id] ?? '').split('|'); if (prev[id] === undefined) continue; if (pst !== st && NOTIFY_ON[st]) out.push({ title: 'Astra (mock app)', body: `Run ${id} ${NOTIFY_ON[st]}` }); else if (attention && attention !== pattention) out.push({ title: 'Astra (mock app)', body: attention }); } return out; }