const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' function patch(file, pairs) { const p = base + file let c = fs.readFileSync(p, 'utf8') for (const [from, to] of pairs) { if (!c.includes(from)) { console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n')) continue } c = c.replace(from, to) } fs.writeFileSync(p, c, 'utf8') } // ---- preload / api patch('preload/index.ts', [ [ " getProfiles: () => Promise>", " getProfiles: () => Promise>\n delProfile: (id: string) => Promise>\n onLook: (cb: (p: { x: number; y: number }) => void) => () => void\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => () => void" ], [ " switchProfile: (id: string) => ipcRenderer.invoke('pet:profiles:switch', id),", " switchProfile: (id: string) => ipcRenderer.invoke('pet:profiles:switch', id),\n delProfile: (id: string) => ipcRenderer.invoke('pet:profiles:del', id),\n onLook: (cb: (p: { x: number; y: number }) => void) => {\n const l = (_e: unknown, p: { x: number; y: number }): void => cb(p)\n ipcRenderer.on('pet:look', l)\n return () => ipcRenderer.removeListener('pet:look', l)\n },\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => {\n const l = (_e: unknown, list: Array<{ id: string; name: string; active: boolean }>): void => cb(list)\n ipcRenderer.on('pet:skins:update', l)\n return () => ipcRenderer.removeListener('pet:skins:update', l)\n }," ] ]) patch('renderer/src/api.ts', [ [ " getProfiles: () => Promise>", " getProfiles: () => Promise>\n delProfile: (id: string) => Promise>\n onLook: (cb: (p: { x: number; y: number }) => void) => () => void\n onSkins: (cb: (list: Array<{ id: string; name: string; active: boolean }>) => void) => () => void" ] ]) // ---- App:全屏视线 + 复位改正前方 patch('renderer/src/App.tsx', [ [ " const offMotion = a?.onMotion((name) => {\n void adapterRef.current?.play(name)\n })", " const offMotion = a?.onMotion((name) => {\n void adapterRef.current?.play(name)\n })\n const offLook = a?.onLook((p) => {\n adapterRef.current?.lookAt?.(p.x, p.y)\n })" ], [ " offMotion?.()\n window.clearInterval(eventTimer)", " offMotion?.()\n offLook?.()\n window.clearInterval(eventTimer)" ], // 本地悬停跟随可保留,但全屏轮询已覆盖;本地仍保留以更平滑 [ ` // 视线跟随:只要鼠标在窗口内移动就更新(不要求按住) if (cfg.eyeFollow) { adapterRef.current?.lookAt?.(e.clientX + cfg.cropLeft, e.clientY + cfg.cropTop) } const d = dragRef.current`, ` const d = dragRef.current` ] ]) patch('renderer/src/pet/adapters/live2d.ts', [ [ ` if (x < 0 || y < 0) { // 复位:看向画布中央偏下,即正前方 this.model?.focus(this.baseSize.w / 2, this.baseSize.h * 1.5) return }`, ` if (x < 0 || y < 0) { // 复位:看向画布中央(正前方) this.model?.focus(this.baseSize.w / 2, this.baseSize.h / 2) return }` ] ]) // ---- Panel:删除存档 + 等级标识 + 分区锚点 + 皮肤订阅 patch('renderer/src/panel/Panel.tsx', [ [ " const [profiles, setProfiles] = useState>([])", " const [profiles, setProfiles] = useState>([])\n const [pendingSection, setPendingSection] = useState('')" ], [ " void a?.getProfiles().then(setProfiles)", " void a?.getProfiles().then(setProfiles)\n const offSkins = a?.onSkins(setSkins)" ], [ " offFlavor?.()\n clearInterval(timer)", " offFlavor?.()\n offSkins?.()\n clearInterval(timer)" ], // 锚点滚动 [ " const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])", " const level = useMemo(() => (state ? levelOf(state.exp) : 1), [state])\n\n useEffect(() => {\n if (!pendingSection) return\n const t = window.setTimeout(() => {\n document.getElementById('sec-' + pendingSection)?.scrollIntoView({ behavior: 'smooth', block: 'start' })\n }, 150)\n return () => window.clearTimeout(t)\n }, [pendingSection, tab])" ], // 导航 arg 支持分区 [ ` if (arg) { const cats = ['meal', 'drink', 'drug', 'gear', 'book', 'gift'] if (cats.includes(arg)) setCat(arg as ItemCategory) if (arg === 'work' || arg === 'study' || arg === 'play') { setKind(arg) setTaskId(JOBS.find((j) => j.kind === arg)?.id ?? '') } }`, ` if (arg) { const cats = ['meal', 'drink', 'drug', 'gear', 'book', 'gift'] if (cats.includes(arg)) setCat(arg as ItemCategory) if (arg === 'work' || arg === 'study' || arg === 'play') { setKind(arg) setTaskId(JOBS.find((j) => j.kind === arg)?.id ?? '') } if (['ai', 'profile', 'skin'].includes(arg)) setPendingSection(arg) }` ], // 存档行:等级 + 删除 [ ` {profiles.map((p) => (
{p.id} {p.active && (当前)}
))}`, ` {profiles.map((p) => (
{p.id} {p.active && (当前)}
{p.level}
))}` ], // 分区锚点 [ `
角色存档
`, `
角色存档
` ], [ `
角色 · Live2D
`, `
角色 · Live2D
` ], [ `
AI 对话
`, `
AI 对话
` ] ]) // ---- Menu:设置子菜单加功能索引 patch('renderer/src/menu/Menu.tsx', [ [ ` settings: [ { label: '图形', tab: 'settings' }, { label: 'AI 与人设', tab: 'settings', arg: 'ai' } ]`, ` settings: [ { label: '图形', tab: 'settings' }, { label: 'AI 与人设', tab: 'settings', arg: 'ai' }, { label: '角色存档', tab: 'settings', arg: 'profile' }, { label: '角色 · Live2D', tab: 'settings', arg: 'skin' }, { label: '图库', tab: 'photos' }, { label: '资料库', action: 'storage' } ]` ] ]) console.log('p24 renderer patched')