Files
SodiumPet/tools/patch-fix3.cjs

178 lines
6.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 && (
<div className="submenu">`,
` {cat && (
<div className="submenu" style={{ left: subLeft }}>`
)
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<FileMeta[]>([])",
" const [files, setFiles] = useState<FileMeta[]>([])\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 && (
<div className="empty">还没有照片,点上面的「拍照」存一张吧</div>
)}
<div className="shop-grid">
{photos.map((p) => (`,
` <div className="chips">
{['全部', '默认', '表情', '纪念'].map((catName) => (
<button
key={catName}
className={\`chip \${photoCat === catName ? 'on' : ''}\`}
onClick={() => setPhotoCat(catName)}
>
{catName}
</button>
))}
</div>
{photos.filter((p) => photoCat === '全部' || p.category === photoCat).length ===
0 && <div className="empty">这个分类还没有照片</div>}
<div className="shop-grid">
{photos
.filter((p) => photoCat === '全部' || p.category === photoCat)
.map((p) => (`
)
c = c.replace(
` {photos.map((p) => (
<div className="card photo-card" key={p.id}>`,
` {photos.map((p) => (
<div className="card photo-card" key={p.id}>`
)
// 照片卡片加分类按钮
c = c.replace(
` <button
className="mini"
title="收藏"
onClick={() => void api()?.favPhoto(p.id)}
>
{p.favorite ? '★' : '☆'}
</button>`,
` <button
className="mini"
title="切换分类"
onClick={() => {
const cur = p.category || '默认'
const next = PHOTO_CATS[(PHOTO_CATS.indexOf(cur) + 1) % PHOTO_CATS.length]
void api()?.setPhotoCat(p.id, next)
}}
>
{p.category || '默认'}
</button>
<button
className="mini"
title="收藏"
onClick={() => void api()?.favPhoto(p.id)}
>
{p.favorite ? '★' : '☆'}
</button>`
)
// 文件行:图标 + 点击打开
c = c.replace(
` <div className="row-title">{f.name}</div>`,
` <div
className="row-title file-name"
title="点击打开"
onClick={() => void api()?.openFile(f.name)}
>
{fileIcon(f.name)} {f.name}
</div>`
)
// 照片 map 的收尾括号需要保持配对:把 photos.map 后的 `.map((p) => (` 已经由 filter 版本处理,
// 但原代码 map 结尾是 `)}`,filter 版本结尾需要 `))}`。
c = c.replace(
` </div>
))}
</div>
<div className="section-title">文件袋 · 把文件拖到小钠身上</div>`,
` </div>
))}
</div>
<div className="section-title">文件袋 · 把文件拖到小钠身上</div>`
)
fs.writeFileSync(p, c, 'utf8')
}
console.log('menu/panel patched')