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')
}
// ---- Panel:自动购买/作息开关 + 图库分页
patch('renderer/src/panel/Panel.tsx', [
[
" const [photoCat, setPhotoCat] = useState('全部')\n const [kbList, setKbList]",
" const [photoCat, setPhotoCat] = useState('全部')\n const [photoPage, setPhotoPage] = useState(0)\n const [kbList, setKbList]"
],
// 设置:自动购买 + 作息(放在视线跟随开关后)
[
`
视线跟随鼠标
void patchConfig({ eyeFollow: e.target.checked })}
/>
`,
`
视线跟随鼠标
void patchConfig({ eyeFollow: e.target.checked })}
/>
饿了自动买饭团
void patchConfig({ autoBuy: e.target.checked })}
/>
睡觉时间
void patchConfig({ sleepAt: e.target.value })}
/>
起床时间
void patchConfig({ wakeAt: e.target.value })}
/>
`
],
// 图库分页:把过滤后的数组换成分页切片
[
` {photos.filter((p) => photoCat === '全部' || p.category === photoCat).length ===
0 && 这个分类还没有照片
}
{photos
.filter((p) => photoCat === '全部' || p.category === photoCat)
.map((p) => (`,
` {(() => {
const filtered = photos.filter((p) => photoCat === '全部' || p.category === photoCat)
const PAGE = 8
const pages = Math.max(1, Math.ceil(filtered.length / PAGE))
const cur = Math.min(photoPage, pages - 1)
const pageItems = filtered.slice(cur * PAGE, cur * PAGE + PAGE)
return (
<>
{filtered.length === 0 &&
这个分类还没有照片
}
{pages > 1 && (
{cur + 1} / {pages}
)}
{pageItems.map((p) => (`
],
// 收尾:map 的闭合需要与 IIFE 配对
[
`
))}
文件袋 · 把文件拖到小钠身上
`,
`
))}
>
)
})()}
文件袋 · 把文件拖到小钠身上
`
]
])
// ---- Storage:分页 + 工作区
patch('renderer/src/storage/Storage.tsx', [
[
" const [cat, setCat] = useState('全部')",
" const [cat, setCat] = useState('全部')\n const [page, setPage] = useState(0)\n const [ws, setWs] = useState>([])"
],
[
" void a?.getKb().then(setKbList)",
" void a?.getKb().then(setKbList)\n void a?.getWs().then(setWs)"
],
[
` const shown = photos.filter((p) => cat === '全部' || p.category === cat)`,
` const filtered = photos.filter((p) => cat === '全部' || p.category === cat)
const PAGE = 12
const pages = Math.max(1, Math.ceil(filtered.length / PAGE))
const cur = Math.min(page, pages - 1)
const shown = filtered.slice(cur * PAGE, cur * PAGE + PAGE)`
],
[
` {shown.length === 0 && 还没有照片,用上面的「拍照」或「导入照片」吧
}
`,
` {filtered.length === 0 &&
还没有照片,用上面的「拍照」或「导入照片」吧
}
{pages > 1 && (
{cur + 1} / {pages}
)}
`
],
// 工作区 section(放在知识库之后,组件末尾)
[
`
{kbList.map((k) => (
))}
)
}`,
`
{kbList.map((k) => (
))}
工作区({ws.length})· 对话里说「保存 xxx.md」就会写到这里
{ws.length === 0 && 还没有文件
}
{ws.map((f) => (
))}
)
}`
]
])
console.log('pager/settings/ws-ui patched')