60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
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<HTMLDivElement>): void {
|
|
if (e.button !== 0) return`,
|
|
` function onPointerDown(e: React.PointerEvent<HTMLDivElement>): void {
|
|
if (e.button !== 0) return
|
|
// 遇水危机:点击 = 擦干
|
|
if (eventInfo) {
|
|
api()?.eventResolve(eventInfo.id)
|
|
setEventInfo(null)
|
|
return
|
|
}`
|
|
)
|
|
|
|
rep(
|
|
` {toast && <div className="pet-toast">{toast}</div>}`,
|
|
` {toast && <div className="pet-toast">{toast}</div>}
|
|
{eventInfo && (
|
|
<div className="water-event">
|
|
<div className="water-droplet">💧</div>
|
|
<div className="water-text">
|
|
快擦干!{Math.max(0, Math.ceil((eventInfo.until - eventNow) / 1000))}s
|
|
</div>
|
|
</div>
|
|
)}`
|
|
)
|
|
|
|
fs.writeFileSync(p, c, 'utf8')
|
|
console.log('app patched')
|