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') } // ---- 音乐协议:支持 Range(音频拖动/播放必需) patch('main/index.ts', [ [ ` } else if (url.host === 'music') { const dir = readMusicDir() if (!dir) return new Response('no music dir', { status: 404 }) abs = path.join(dir, rel) root = dir } else if (url.host === 'data') {`, ` } else if (url.host === 'music') { const dir = readMusicDir() if (!dir) return new Response('no music dir', { status: 404 }) abs = path.join(dir, rel) root = dir } else if (url.host === 'data') {` ], [ ` if (!isInside(root, abs)) return new Response('forbidden', { status: 403 }) return await net.fetch(pathToFileURL(abs).toString())`, ` if (!isInside(root, abs)) return new Response('forbidden', { status: 403 }) // 音频需要 Range 支持,才能拖动进度条 / 正常播放 if (url.host === 'music' && fs.existsSync(abs) && fs.statSync(abs).isFile()) { const data = fs.readFileSync(abs) const ext = path.extname(abs).toLowerCase() const mime = ext === '.mp3' ? 'audio/mpeg' : ext === '.flac' ? 'audio/flac' : ext === '.wav' ? 'audio/wav' : ext === '.ogg' ? 'audio/ogg' : ext === '.m4a' || ext === '.aac' ? 'audio/mp4' : 'application/octet-stream' const range = request.headers.get('Range') if (range) { const m = /bytes=(\\d*)-(\\d*)/.exec(range) const start = m && m[1] ? Number(m[1]) : 0 const end = m && m[2] ? Math.min(Number(m[2]), data.length - 1) : data.length - 1 const chunk = data.subarray(start, end + 1) return new Response(chunk, { status: 206, headers: { 'Content-Type': mime, 'Accept-Ranges': 'bytes', 'Content-Range': \`bytes \${start}-\${end}/\${data.length}\`, 'Content-Length': String(chunk.length) } }) } return new Response(data, { status: 200, headers: { 'Content-Type': mime, 'Accept-Ranges': 'bytes', 'Content-Length': String(data.length) } }) } return await net.fetch(pathToFileURL(abs).toString())` ] ]) // ---- 音乐窗口:日间背景 + 实时跟随主题 patch('renderer/src/music/music.css', [ [ `html, body, #root { margin: 0; padding: 0; width: 100%; height: 100%; background: #0d1017; overflow: hidden; }`, `html, body, #root { margin: 0; padding: 0; width: 100%; height: 100%; background: #0d1017; overflow: hidden; } [data-theme='day'] html, [data-theme='day'] body, [data-theme='day'] #root { background: #eef2f8; } [data-theme='day'] .music { background: #eef2f8; }` ] ]) patch('renderer/src/music/Music.tsx', [ [ ` api()?.setPanelTitle('本地音乐') void api()?.getConfig().then((c) => setTheme(c.theme))`, ` api()?.setPanelTitle('本地音乐') void api()?.getConfig().then((c) => setTheme(c.theme)) const offCfg = api()?.onConfig((c) => setTheme(c.theme))` ], [ ` return () => offList?.()`, ` return () => { offList?.() offCfg?.() }` ] ]) console.log('music range + theme patched')