Files

80 lines
2.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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', [
[
`function createPanel(tab?: string, arg?: string): void {
if (panelWindow && !panelWindow.isDestroyed()) {
panelWindow.show()
panelWindow.focus()
return
}`,
`function createPanel(tab?: string, arg?: string): void {
if (panelWindow && !panelWindow.isDestroyed()) {
panelWindow.show()
panelWindow.focus()
if (tab) panelWindow.webContents.send('pet:panel:navigate', { tab, arg })
return
}`
],
[
` ipcMain.handle('pet:files:list', () => media.files)`,
` ipcMain.handle('pet:files:list', () => media.files)
ipcMain.handle('pet:files:open', (_e, name: string) => {
const target = path.join(media.fileDir, String(name))
if (target.startsWith(media.fileDir)) void shell.openPath(target)
})`
],
[
` ipcMain.handle('pet:photos:open', (_e, id: string) => {`,
` ipcMain.handle('pet:photos:cat', (_e, id: string, cat: string) => {
media.setCategory(String(id), String(cat))
broadcastMedia()
return media.photos
})
ipcMain.handle('pet:photos:open', (_e, id: string) => {`
]
])
// ---- preload:openFile / onNavigate / photos cat
patch('preload/index.ts', [
[
" delFile: (name: string) => Promise<FileMeta[]>",
" delFile: (name: string) => Promise<FileMeta[]>\n openFile: (name: string) => Promise<void>\n onNavigate: (cb: (nav: { tab: string; arg?: string }) => void) => () => void\n setPhotoCat: (id: string, cat: string) => Promise<PhotoMeta[]>"
],
[
" delFile: (name: string) => ipcRenderer.invoke('pet:files:del', name),",
` delFile: (name: string) => ipcRenderer.invoke('pet:files:del', name),
openFile: (name: string) => ipcRenderer.invoke('pet:files:open', name),
onNavigate: (cb: (nav: { tab: string; arg?: string }) => void) => {
const l = (_e: unknown, nav: { tab: string; arg?: string }): void => cb(nav)
ipcRenderer.on('pet:panel:navigate', l)
return () => ipcRenderer.removeListener('pet:panel:navigate', l)
},
setPhotoCat: (id: string, cat: string) => ipcRenderer.invoke('pet:photos:cat', id, cat),`
]
])
// ---- api.ts
patch('renderer/src/api.ts', [
[
" delFile: (name: string) => Promise<FileMeta[]>",
" delFile: (name: string) => Promise<FileMeta[]>\n openFile: (name: string) => Promise<void>\n onNavigate: (cb: (nav: { tab: string; arg?: string }) => void) => () => void\n setPhotoCat: (id: string, cat: string) => Promise<PhotoMeta[]>"
]
])
console.log('bugfix patch done')