const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' // ---- Menu:子菜单对准所选分类 { const p = base + 'renderer/src/menu/Menu.tsx' let c = fs.readFileSync(p, 'utf8') c = c.replace( ` const sleeping = !!state?.sleeping`, ` const sleeping = !!state?.sleeping const catIdx = cat ? CATS.findIndex((x) => x.id === cat) : 0 const subLeft = Math.min(264, Math.max(4, 4 + catIdx * 78.4 + 39.2 - 66))` ) c = c.replace( ` {cat && (
`, ` {cat && (
` ) fs.writeFileSync(p, c, 'utf8') } // ---- Panel:导航 + 文件图标 + 照片分类 { const p = base + 'renderer/src/panel/Panel.tsx' let c = fs.readFileSync(p, 'utf8') // 文件图标助手 c = c.replace( `function effectText(item: Item): string {`, `const FILE_ICONS: Array<[RegExp, string]> = [ [/\\.(png|jpe?g|gif|webp|bmp|ico)$/i, '🖼️'], [/\\.(md|txt|docx?|pdf|pptx?)$/i, '📄'], [/\\.(mp3|wav|ogg|flac)$/i, '🎵'], [/\\.(mp4|mkv|avi|mov)$/i, '🎬'], [/\\.(zip|rar|7z)$/i, '📦'], [/\\.(xlsx?|csv)$/i, '📊'], [/\\.(exe|msi)$/i, '⚙️'], [/\\.(js|ts|py|c|cpp|java|json)$/i, '🧾'] ] function fileIcon(name: string): string { for (const [re, icon] of FILE_ICONS) if (re.test(name)) return icon return '📁' } const PHOTO_CATS = ['默认', '表情', '纪念'] function effectText(item: Item): string {` ) // 状态 c = c.replace( " const [files, setFiles] = useState([])", " const [files, setFiles] = useState([])\n const [photoCat, setPhotoCat] = useState('全部')" ) // 初始 arg 映射 + 导航订阅 c = c.replace( " void a?.getLlm().then(setLlm)", ` void a?.getLlm().then(setLlm) const applyNav = (nav: { tab: string; arg?: string }): void => { if (nav.tab === 'detail') { setTab('panel') setDetail(true) return } setTab(nav.tab as TabId) const arg = nav.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 (initialArg) applyNav({ tab: initialTab, arg: initialArg }) const offNav = a?.onNavigate(applyNav)` ) c = c.replace( " offPhotos?.()\n offFiles?.()\n clearInterval(timer)", " offPhotos?.()\n offFiles?.()\n offNav?.()\n clearInterval(timer)" ) // 照片分类 chips + 过滤 + 分类按钮 c = c.replace( ` {photos.length === 0 && (
还没有照片,点上面的「拍照」存一张吧
)}
{photos.map((p) => (`, `
{['全部', '默认', '表情', '纪念'].map((catName) => ( ))}
{photos.filter((p) => photoCat === '全部' || p.category === photoCat).length === 0 &&
这个分类还没有照片
}
{photos .filter((p) => photoCat === '全部' || p.category === photoCat) .map((p) => (` ) c = c.replace( ` {photos.map((p) => (
`, ` {photos.map((p) => (
` ) // 照片卡片加分类按钮 c = c.replace( ` `, ` ` ) // 文件行:图标 + 点击打开 c = c.replace( `
{f.name}
`, `
void api()?.openFile(f.name)} > {fileIcon(f.name)} {f.name}
` ) // 照片 map 的收尾括号需要保持配对:把 photos.map 后的 `.map((p) => (` 已经由 filter 版本处理, // 但原代码 map 结尾是 `)}`,filter 版本结尾需要 `))}`。 c = c.replace( `
))}
文件袋 · 把文件拖到小钠身上
`, `
))}
文件袋 · 把文件拖到小钠身上
` ) fs.writeFileSync(p, c, 'utf8') } console.log('menu/panel patched')