Files
SodiumPet/tools/patch-photos.cjs
T

97 lines
3.7 KiB
JavaScript

const fs = require('fs')
const p = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/renderer/src/panel/Panel.tsx'
let c = fs.readFileSync(p, 'utf8')
function rep(from, to) {
if (!c.includes(from)) {
console.log('MISS ::', from.slice(0, 80).replace(/\n/g, '\\n'))
return
}
c = c.replace(from, to)
}
rep(
"import type { JobDef } from '../../../shared/petState'",
"import type { JobDef } from '../../../shared/petState'\nimport type { FileMeta, PhotoMeta } from '../../../shared/media'"
)
rep(
" { id: 'shop', label: '试剂店' },",
" { id: 'shop', label: '试剂店' },\n { id: 'photos', label: '图库' },"
)
rep(
" const [llm, setLlm] = useState<LlmConfig | null>(null)",
" const [llm, setLlm] = useState<LlmConfig | null>(null)\n const [photos, setPhotos] = useState<PhotoMeta[]>([])\n const [files, setFiles] = useState<FileMeta[]>([])"
)
rep(
" void a?.getLlm().then(setLlm)\n const timer = setInterval(() => setNow(Date.now()), 500)",
" void a?.getLlm().then(setLlm)\n void a?.getPhotos().then(setPhotos)\n void a?.getFiles().then(setFiles)\n const offPhotos = a?.onPhotos(setPhotos)\n const offFiles = a?.onFiles(setFiles)\n const timer = setInterval(() => setNow(Date.now()), 500)"
)
rep(
" offState?.()\n offCfg?.()\n clearInterval(timer)",
" offState?.()\n offCfg?.()\n offPhotos?.()\n offFiles?.()\n clearInterval(timer)"
)
// 图库 tab:放在设置之前
rep(
` {tab === 'settings' && cfg && (`,
` {tab === 'photos' && (
<>
<div className="detail-bar">
<span>图库</span>
<button className="mini" onClick={() => void api()?.capturePhoto()}>
拍照
</button>
</div>
{photos.length === 0 && (
<div className="empty">还没有照片,点上面的「拍照」存一张吧</div>
)}
<div className="shop-grid">
{photos.map((p) => (
<div className="card photo-card" key={p.id}>
<img className="photo" src={\`pet://photos/\${p.file}\`} alt="" />
<div className="card-foot">
<button
className="mini"
title="收藏"
onClick={() => void api()?.favPhoto(p.id)}
>
{p.favorite ? '★' : '☆'}
</button>
<button className="mini" onClick={() => void api()?.openPhoto(p.id)}>
打开
</button>
<button className="mini" onClick={() => void api()?.delPhoto(p.id)}>
删除
</button>
</div>
</div>
))}
</div>
<div className="section-title">文件袋 · 把文件拖到小钠身上</div>
{files.length === 0 && <div className="empty">还没有文件,拖一个给她试试</div>}
<div className="list">
{files.map((f) => (
<div className="row" key={f.name}>
<div className="row-main">
<div className="row-title">{f.name}</div>
<div className="row-sub">{f.original}</div>
</div>
<button className="mini" onClick={() => void api()?.delFile(f.name)}>
删除
</button>
</div>
))}
</div>
</>
)}
{tab === 'settings' && cfg && (`
)
fs.writeFileSync(p, c, 'utf8')
console.log('panel photos patched')