76 lines
2.9 KiB
JavaScript
76 lines
2.9 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')
|
|
}
|
|
|
|
// main:我的列表(手动收藏,全局)
|
|
patch('main/index.ts', [
|
|
[
|
|
` ipcMain.handle('pet:music:base', () => (musicServerPort ? 'http://127.0.0.1:' + musicServerPort + '/' : ''))`,
|
|
` ipcMain.handle('pet:music:base', () => (musicServerPort ? 'http://127.0.0.1:' + musicServerPort + '/' : ''))
|
|
const playlistPath = () => path.join(HOME, 'data', 'music-playlist.json')
|
|
const readPlaylist = (): Array<{ name: string; file: string }> => {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(playlistPath(), 'utf8')) as Array<{
|
|
name: string
|
|
file: string
|
|
}>
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
ipcMain.handle('pet:music:playlist', () => readPlaylist())
|
|
ipcMain.handle('pet:music:playlist:add', (_e, track: { name: string; file: string }) => {
|
|
const list = readPlaylist()
|
|
if (!list.some((t) => t.file === track.file)) list.push({ name: track.name, file: track.file })
|
|
fs.writeFileSync(playlistPath(), JSON.stringify(list, null, 2), 'utf8')
|
|
return list
|
|
})
|
|
ipcMain.handle('pet:music:playlist:remove', (_e, file: string) => {
|
|
const list = readPlaylist().filter((t) => t.file !== String(file))
|
|
fs.writeFileSync(playlistPath(), JSON.stringify(list, null, 2), 'utf8')
|
|
return list
|
|
})`
|
|
]
|
|
])
|
|
|
|
// preload / api
|
|
patch('preload/index.ts', [
|
|
[
|
|
" getMusicBase: () => Promise<string>",
|
|
` getMusicBase: () => Promise<string>
|
|
getMusicPlaylist: () => Promise<Array<{ name: string; file: string }>>
|
|
addMusicPlaylist: (t: { name: string; file: string }) => Promise<Array<{ name: string; file: string }>>
|
|
removeMusicPlaylist: (file: string) => Promise<Array<{ name: string; file: string }>>`
|
|
],
|
|
[
|
|
" getMusicBase: () => ipcRenderer.invoke('pet:music:base'),",
|
|
` getMusicBase: () => ipcRenderer.invoke('pet:music:base'),
|
|
getMusicPlaylist: () => ipcRenderer.invoke('pet:music:playlist'),
|
|
addMusicPlaylist: (t: { name: string; file: string }) => ipcRenderer.invoke('pet:music:playlist:add', t),
|
|
removeMusicPlaylist: (file: string) =>
|
|
ipcRenderer.invoke('pet:music:playlist:remove', file),`
|
|
]
|
|
])
|
|
patch('renderer/src/api.ts', [
|
|
[
|
|
" getMusicBase: () => Promise<string>",
|
|
` getMusicBase: () => Promise<string>
|
|
getMusicPlaylist: () => Promise<Array<{ name: string; file: string }>>
|
|
addMusicPlaylist: (t: { name: string; file: string }) => Promise<Array<{ name: string; file: string }>>
|
|
removeMusicPlaylist: (file: string) => Promise<Array<{ name: string; file: string }>>`
|
|
]
|
|
])
|
|
|
|
console.log('music playlist main patched')
|