const fs = require('fs') const p = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/main/index.ts' let c = fs.readFileSync(p, 'utf8') function rep(from, to) { if (!c.includes(from)) { console.log('MISS ::', from.slice(0, 70).replace(/\n/g, '\\n')) return } c = c.replace(from, to) } // 配置监听并入 bindStoreBroadcast,切换存档后也能广播主题等配置 rep( `function bindStoreBroadcast(): void { store.subscribe((s) => { for (const w of BrowserWindow.getAllWindows()) { if (!w.isDestroyed()) w.webContents.send('pet:state:update', s) } }) }`, `function bindStoreBroadcast(): void { store.subscribe((s) => { for (const w of BrowserWindow.getAllWindows()) { if (!w.isDestroyed()) w.webContents.send('pet:state:update', s) } }) store.onConfig((cfg) => applyConfig(cfg)) }` ) // 移除 whenReady 里单独的注册(避免重复绑定旧实例) rep( ` store.onConfig((cfg) => applyConfig(cfg)) bindStoreBroadcast()`, ` bindStoreBroadcast()` ) fs.writeFileSync(p, c, 'utf8') console.log('config broadcast rebound')