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') } patch('preload/index.ts', [ [ " importIcon: () => Promise", ` importIcon: () => Promise openMusic: () => void chooseMusicDir: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }> listMusic: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }> getLyric: (file: string) => Promise sendMusicNow: (payload: unknown) => void onMusicNow: (cb: (p: unknown) => void) => () => void onMusicList: ( cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void ) => () => void openLyric: () => void closeLyric: () => void` ], [ " importIcon: () => ipcRenderer.invoke('pet:icon:import'),", ` importIcon: () => ipcRenderer.invoke('pet:icon:import'), openMusic: () => ipcRenderer.send('pet:music:open'), chooseMusicDir: () => ipcRenderer.invoke('pet:music:choose'), listMusic: () => ipcRenderer.invoke('pet:music:list'), getLyric: (file: string) => ipcRenderer.invoke('pet:music:lyric', file), sendMusicNow: (payload: unknown) => ipcRenderer.send('pet:music:now', payload), onMusicNow: (cb: (p: unknown) => void) => { const l = (_e: unknown, p: unknown): void => cb(p) ipcRenderer.on('pet:music:now', l) return () => ipcRenderer.removeListener('pet:music:now', l) }, onMusicList: ( cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void ) => { const l = ( _e: unknown, p: { dir: string; tracks: Array<{ name: string; file: string }> } ): void => cb(p) ipcRenderer.on('pet:music:list', l) return () => ipcRenderer.removeListener('pet:music:list', l) }, openLyric: () => ipcRenderer.send('pet:lyric:open'), closeLyric: () => ipcRenderer.send('pet:lyric:close'),` ] ]) patch('renderer/src/api.ts', [ [ " importIcon: () => Promise", ` importIcon: () => Promise openMusic: () => void chooseMusicDir: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }> listMusic: () => Promise<{ dir: string; tracks: Array<{ name: string; file: string }> }> getLyric: (file: string) => Promise sendMusicNow: (payload: unknown) => void onMusicNow: (cb: (p: unknown) => void) => () => void onMusicList: ( cb: (p: { dir: string; tracks: Array<{ name: string; file: string }> }) => void ) => () => void openLyric: () => void closeLyric: () => void` ] ]) // 路由 + 菜单 + 设置入口 patch('renderer/src/main.tsx', [ [ "import Editor from './editor/Editor'", "import Editor from './editor/Editor'\nimport Music from './music/Music'\nimport Lyric from './lyric/Lyric'" ], [ " if (view === 'editor') return ", " if (view === 'editor') return \n if (view === 'music') return \n if (view === 'lyric') return " ] ]) patch('renderer/src/menu/Menu.tsx', [ [ " action?: 'sleep' | 'storage' | 'editor'", " action?: 'sleep' | 'storage' | 'editor' | 'music'" ], [ ` { label: '摸摸头', action: 'pet' },`, ` { label: '摸摸头', action: 'pet' }, { label: '听歌', action: 'music' },` ], [ ` if (item.action === 'editor') { api()?.openEditor() return }`, ` if (item.action === 'editor') { api()?.openEditor() return } if (item.action === 'music') { api()?.openMusic() return }` ] ]) // Panel:互动侧栏「听歌」 patch('renderer/src/panel/Panel.tsx', [ [ ` `, ` ` ] ]) console.log('music bridge patched')