Files
SodiumPet/tools/patch-p27-c.cjs

112 lines
3.3 KiB
JavaScript

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')
}
// ---- 窗口标题:存档名-页面
patch('main/index.ts', [
[
` ipcMain.on('pet:storage:open', () => createStorageWindow())`,
` let lastPanelLabel = '面板'
ipcMain.on('pet:panel:title', (e, label: string) => {
const w = BrowserWindow.fromWebContents(e.sender)
if (!w) return
const name = store.snapshot().name || profileId
w.setTitle(name + '-' + String(label))
if (w === panelWindow) lastPanelLabel = String(label)
})
ipcMain.on('pet:storage:open', () => createStorageWindow())`
],
// 切换存档后刷新各窗口标题
[
` loadProfile(String(id))
store.start()
const meta = readProfileMeta(sanitizeId(String(id)))
store.renamePet(meta.name)
store.setConfig({ currentSkin: meta.skinId })
applyConfig(store.getConfig())`,
` loadProfile(String(id))
store.start()
const meta = readProfileMeta(sanitizeId(String(id)))
store.renamePet(meta.name)
store.setConfig({ currentSkin: meta.skinId })
applyConfig(store.getConfig())
const pname = meta.name || sanitizeId(String(id))
mainWindow?.setTitle(pname)
panelWindow?.setTitle(pname + '-' + lastPanelLabel)
if (storageWindow) storageWindow.setTitle(pname + '-资料库')`
]
])
// ---- preload / api
patch('preload/index.ts', [
[
" saveCalibration: (id: string, cal: unknown) => void",
" saveCalibration: (id: string, cal: unknown) => void\n setPanelTitle: (label: string) => void"
],
[
" saveCalibration: (id: string, cal: unknown) => ipcRenderer.invoke('pet:skin:calibrate', id, cal),",
" saveCalibration: (id: string, cal: unknown) => ipcRenderer.invoke('pet:skin:calibrate', id, cal),\n setPanelTitle: (label: string) => ipcRenderer.send('pet:panel:title', label),"
]
])
patch('renderer/src/api.ts', [
[
" saveCalibration: (id: string, cal: unknown) => void",
" saveCalibration: (id: string, cal: unknown) => void\n setPanelTitle: (label: string) => void"
]
])
// ---- Panel:切页时更新标题
patch('renderer/src/panel/Panel.tsx', [
[
` useEffect(() => {
if (!pendingSection) return`,
` function tabTitle(t: TabId): string {
switch (t) {
case 'feed':
return '投喂'
case 'panel':
return '面板'
case 'interact':
return '互动'
case 'shop':
return flavor === 'normal' ? '商店' : '试剂店'
case 'photos':
return '图库'
case 'settings':
return '设置'
}
}
useEffect(() => {
api()?.setPanelTitle(tabTitle(tab))
}, [tab, flavor])
useEffect(() => {
if (!pendingSection) return`
]
])
// ---- Storage:挂载时标题
patch('renderer/src/storage/Storage.tsx', [
[
` void a?.getPhotos().then(setPhotos)`,
` api()?.setPanelTitle('资料库')
void a?.getPhotos().then(setPhotos)`
]
])
console.log('titles patched')