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') } // 0) 配置:工具栏图标映射 patch('shared/petState.ts', [ [ ` /** 歌词浮窗:底色 / 文字色 / 描边色 / 字号 */ lyricBg: string`, ` /** 底栏图标:tab id -> 'sticker:1.0.png' 或 'img:icons/xxx.png' */ tabIcons: Record /** 歌词浮窗:底色 / 文字色 / 描边色 / 字号 */ lyricBg: string` ], [ ` lyricBg: 'rgba(16,20,30,0.55)',`, ` tabIcons: {}, lyricBg: 'rgba(16,20,30,0.55)',` ] ]) // 1) 协议:pet://stickers/(内置表情包) patch('main/index.ts', [ [ ` } else if (url.host === 'music') {`, ` } else if (url.host === 'stickers') { const dir = path.join(APP_DIR, 'assets', 'stickers') abs = path.join(dir, rel) root = dir } else if (url.host === 'music') {` ] ]) // 2) 渲染端图标地址解析 { const p = base + 'renderer/src/ui/iconUrl.ts' fs.writeFileSync( p, `/** 把配置里的图标值转成可访问 URL */ export function iconUrl(value?: string): string { if (!value) return '' if (value.startsWith('sticker:')) return 'pet://stickers/' + encodeURIComponent(value.slice(8)) if (value.startsWith('img:')) return 'pet://data/' + value.slice(4).split('/').map(encodeURIComponent).join('/') return '' } `, 'utf8' ) } // 3) Panel:TABS 渲染图标 patch('renderer/src/panel/Panel.tsx', [ [ "import { Icon } from '../ui/Icon'", "import { Icon } from '../ui/Icon'\nimport { iconUrl } from '../ui/iconUrl'" ], [ ` {t.id === 'shop' && flavor === 'normal' ? '商店' : t.label}`, ` {cfg?.tabIcons?.[t.id] && ( )} {t.id === 'shop' && flavor === 'normal' ? '商店' : t.label}` ] ]) // 4) Menu:底栏分类也支持图标 patch('renderer/src/menu/Menu.tsx', [ [ "import { api } from '../api'", "import { api } from '../api'\nimport { iconUrl } from '../ui/iconUrl'" ], [ ` {c.id === 'shop' && flavor === 'normal' ? '商店' : c.label}`, ` {cfg?.tabIcons?.[c.id] && ( )} {c.id === 'shop' && flavor === 'normal' ? '商店' : c.label}` ] ]) console.log('tab icons patched')