const fs = require('fs') const p = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/renderer/src/App.tsx' let c = fs.readFileSync(p, 'utf8') function rep(from, to) { if (!c.includes(from)) { console.log('MISS ::', from.slice(0, 80).replace(/\n/g, '\\n')) return } c = c.replace(from, to) } rep( " const [toast, setToast] = useState('')", " const [toast, setToast] = useState('')\n const [eventInfo, setEventInfo] = useState<{ id: string; type: string; until: number } | null>(null)\n const [eventNow, setEventNow] = useState(Date.now())" ) rep( " const offToast = a?.onToast((t) => showToast(t))", ` const offToast = a?.onToast((t) => showToast(t)) const offEvent = a?.onEvent(setEventInfo) const offMotion = a?.onMotion((name) => { void adapterRef.current?.play(name) }) const eventTimer = window.setInterval(() => setEventNow(Date.now()), 500)` ) rep( " offToast?.()\n adapterRef.current?.destroy()", " offToast?.()\n offEvent?.()\n offMotion?.()\n window.clearInterval(eventTimer)\n adapterRef.current?.destroy()" ) rep( ` function onPointerDown(e: React.PointerEvent): void { if (e.button !== 0) return`, ` function onPointerDown(e: React.PointerEvent): void { if (e.button !== 0) return // 遇水危机:点击 = 擦干 if (eventInfo) { api()?.eventResolve(eventInfo.id) setEventInfo(null) return }` ) rep( ` {toast &&
{toast}
}`, ` {toast &&
{toast}
} {eventInfo && (
💧
快擦干!{Math.max(0, Math.ceil((eventInfo.until - eventNow) / 1000))}s
)}` ) fs.writeFileSync(p, c, 'utf8') console.log('app patched')