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') } // ---- main:删除存档 + 等级标识 + 全屏视线 + 皮肤自动扫描 patch('main/index.ts', [ [ "import { ITEMS, itemById } from '../shared/petState'", "import { ITEMS, itemById, levelOf } from '../shared/petState'\nimport { elementOf } from '../shared/elements'" ], // 列表带等级标识 [ `function listProfiles(): Array<{ id: string; active: boolean }> { const dir = path.join(HOME, 'data', 'profiles') fs.mkdirSync(dir, { recursive: true }) return fs .readdirSync(dir, { withFileTypes: true }) .filter((d) => d.isDirectory()) .map((d) => ({ id: d.name, active: d.name === profileId })) }`, `function listProfiles(): Array<{ id: string; active: boolean; level: string }> { const dir = path.join(HOME, 'data', 'profiles') fs.mkdirSync(dir, { recursive: true }) return fs .readdirSync(dir, { withFileTypes: true }) .filter((d) => d.isDirectory()) .map((d) => { let level = '' try { const raw = fs.readFileSync(path.join(dir, d.name, 'save.json'), 'utf8') const sv = JSON.parse(raw) as { exp?: number } const lv = levelOf(sv.exp ?? 0) const el = elementOf(lv) level = 'Lv.' + lv + ' · ' + el.symbol + ' ' + el.configSuper } catch { level = '' } return { id: d.name, active: d.name === profileId, level } }) }` ], // 删除存档 [ ` ipcMain.handle('pet:profiles:switch', (_e, id: string) => {`, ` ipcMain.handle('pet:profiles:del', (_e, id: string) => { const pid = sanitizeId(String(id)) if (pid === profileId) return listProfiles() const target = path.join(HOME, 'data', 'profiles', pid) if (target.startsWith(path.join(HOME, 'data', 'profiles'))) { fs.rmSync(target, { recursive: true, force: true }) } return listProfiles() }) ipcMain.handle('pet:profiles:switch', (_e, id: string) => {` ], // 全屏视线跟随:主进程轮询光标 [ ` scheduleBarks() scheduleSuggestions() scheduleEvents()`, ` scheduleBarks() scheduleSuggestions() scheduleEvents() // 全屏视线跟随:主进程按 50ms 轮询光标位置,发给宠物窗口 setInterval(() => { const cfgNow = store.getConfig() if (!cfgNow.eyeFollow || !mainWindow || !mainWindow.isVisible()) return const p = screen.getCursorScreenPoint() const b = mainWindow.getBounds() mainWindow.webContents.send('pet:look', { x: p.x - b.x + cfgNow.cropLeft, y: p.y - b.y + cfgNow.cropTop }) }, 50)` ], // 皮肤自动扫描:用户手动放进文件夹后自动生成预设 [ `function listSkins(): Array<{ id: string; name: string; active: boolean }> {`, `function scanSkinsForNew(): boolean { const root = userSkins() let changed = false for (const d of fs.readdirSync(root, { withFileTypes: true })) { if (!d.isDirectory()) continue const dir = path.join(root, d.name) if (fs.existsSync(path.join(dir, 'skin.json'))) continue const modelFile = fs.readdirSync(dir).find((f) => f.endsWith('.model3.json')) if (!modelFile) continue const skin = { id: d.name, name: d.name, version: '1.0.0', flavor: 'normal', avatar: { type: 'live2d', entry: modelFile, scale: 0.4 }, motions: {}, expressions: {} } fs.writeFileSync(path.join(dir, 'skin.json'), JSON.stringify(skin, null, 2), 'utf8') console.log('[skin] 自动生成预设:', d.name) changed = true } return changed } function listSkins(): Array<{ id: string; name: string; active: boolean }> {` ], [ ` // 全屏视线跟随:主进程按 50ms 轮询光标位置,发给宠物窗口 setInterval(() => {`, ` // 皮肤目录扫描:手动放入的模型自动生成预设 setInterval(() => { if (!scanSkinsForNew()) return for (const w of BrowserWindow.getAllWindows()) { if (!w.isDestroyed()) w.webContents.send('pet:skins:update', listSkins()) } }, 3000) // 全屏视线跟随:主进程按 50ms 轮询光标位置,发给宠物窗口 setInterval(() => {` ], // 导入按钮改为打开模型文件夹 [ ` ipcMain.handle('pet:skins:import', async () => { const res = await dialog.showOpenDialog({`, ` ipcMain.handle('pet:skins:import', () => { void shell.openPath(userSkins()) scanSkinsForNew() return listSkins() }) ipcMain.handle('pet:skins:import:legacy', async () => { const res = await dialog.showOpenDialog({` ] ]) console.log('profiles/eye/skins main patched')