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('shared/petState.ts', [ [ ` /** 当前角色存档 id */ profile: string`, ` /** 当前角色存档 id */ profile: string /** 文本风格:auto 跟随皮肤,chemistry 强制化学,normal 强制普通 */ flavorMode: 'auto' | 'chemistry' | 'normal'` ], [ ` currentSkin: 'xiaona', profile: '',`, ` currentSkin: 'xiaona', profile: '', flavorMode: 'auto',` ] ]) // ---- main:currentFlavor 尊重 flavorMode;面板尺寸 16:10 patch('main/index.ts', [ [ `function currentFlavor(): string { try { const root = userSkins() const m = JSON.parse( fs.readFileSync(path.join(root, store.getConfig().currentSkin || 'xiaona', 'skin.json'), 'utf8') ) return m.flavor === 'normal' ? 'normal' : 'chemistry' } catch { return 'chemistry' } }`, `function currentFlavor(): string { const mode = store.getConfig().flavorMode || 'auto' if (mode === 'chemistry') return 'chemistry' if (mode === 'normal') return 'normal' try { const root = userSkins() const m = JSON.parse( fs.readFileSync(path.join(root, store.getConfig().currentSkin || 'xiaona', 'skin.json'), 'utf8') ) return m.flavor === 'normal' ? 'normal' : 'chemistry' } catch { return 'chemistry' } }` ], [ ` panelWindow = new BrowserWindow({ width: 400, height: 540,`, ` panelWindow = new BrowserWindow({ width: 640, height: 430,` ] ]) // ---- Panel:ChipsRow、重命名行内编辑、风格开关、普通风味残留文本、普通等级显示 patch('renderer/src/panel/Panel.tsx', [ // ChipsRow 组件 [ `const PHOTO_CATS = ['默认', '表情', '纪念']`, `const PHOTO_CATS = ['默认', '表情', '纪念'] function ChipsRow({ children }: { children: React.ReactNode }): React.ReactElement { const ref = React.useRef(null) const [more, setMore] = React.useState(false) React.useEffect(() => { const el = ref.current if (!el) return const check = (): void => setMore(el.scrollWidth > el.clientWidth + 4) check() window.addEventListener('resize', check) return () => window.removeEventListener('resize', check) }) return (
{children}
{more && ( )}
) }` ], // 重命名状态 [ " const [newSkin, setNewSkin] = useState('xiaona')", " const [newSkin, setNewSkin] = useState('xiaona')\n const [renamePid, setRenamePid] = useState('')\n const [renameSkinId, setRenameSkinId] = useState('')\n const [renameText, setRenameText] = useState('')" ], // 面板打开时重新检查 chips(ChipsRow effect 无 deps 但每次渲染重跑,够用) // 换三处 chips 包裹 [ `
{(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => ( ))}
`, ` {(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => ( ))} ` ], [ ` {(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => ( ))} {(() => {`, ` {(['all', 'meal', 'drink', 'drug', 'gear', 'book', 'gift'] as const).map((c) => ( ))} {(() => {` ], // 照片分类 chips [ `
{['全部', '默认', '表情', '纪念'].map((catName) => (`, ` {['全部', '默认', '表情', '纪念'].map((catName) => (` ], [ ` {catName} ))}
{(() => {`, ` {catName} ))} {(() => {` ], // 投喂页 chips 也在内:feed tab 有一个(feed 页的第一个 chips 已在上面对上) // 存档重命名行内编辑 [ ` `, ` {renamePid === p.id ? ( <> setRenameText(e.target.value)} /> ) : ( )}` ], // 皮肤重命名行内编辑 [ ` `, ` {renameSkinId === s.id ? ( <> setRenameText(e.target.value)} /> ) : ( )}` ], // 文本风格开关(设置里,放角色分区之前) [ `
角色存档
`, `
文本风格

不再与存档强制绑定,随时可切;下次聊天也会用对应人设。

角色存档
` ], // applyFlavor 结合 flavorMode [ ` const applyFlavor = (cfg2: { currentSkin?: string }): void => { const id = cfg2.currentSkin || 'xiaona' void fetch('pet://skins/' + id + '/skin.json') .then((r) => (r.ok ? r.json() : null)) .then((m) => setFlavor(m && m.flavor === 'normal' ? 'normal' : 'chemistry')) .catch(() => setFlavor('chemistry')) }`, ` const applyFlavor = (cfg2: { currentSkin?: string; flavorMode?: string }): void => { const mode = cfg2.flavorMode || 'auto' if (mode === 'chemistry') { setFlavor('chemistry') return } if (mode === 'normal') { setFlavor('normal') return } const id = cfg2.currentSkin || 'xiaona' void fetch('pet://skins/' + id + '/skin.json') .then((r) => (r.ok ? r.json() : null)) .then((m) => setFlavor(m && m.flavor === 'normal' ? 'normal' : 'chemistry')) .catch(() => setFlavor('chemistry')) }` ], // 普通风味:睡觉注释 / 去商店 / 等级显示 [ ` {state.sleeping ? '把她叫起来' : '电子回充中'}`, ` {state.sleeping ? '把她叫起来' : flavor === 'normal' ? '恢复精力中' : '电子回充中'} ` ], [ ` `, ` ` ], [ ` {state.name} `, ` {state.name}{' '} {flavor === 'normal' ? ( Lv.{level} ) : ( )}` ] ]) console.log('panel p27 patched')