60 lines
3.1 KiB
JavaScript
60 lines
3.1 KiB
JavaScript
const fs = require('fs')
|
|
const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/'
|
|
|
|
// ---- preload
|
|
{
|
|
const p = base + 'preload/index.ts'
|
|
let c = fs.readFileSync(p, 'utf8')
|
|
c = c.replace(
|
|
"import { contextBridge, ipcRenderer } from 'electron'",
|
|
"import { contextBridge, ipcRenderer, webUtils } from 'electron'\nimport type { FileMeta, PhotoMeta } from '../shared/media'"
|
|
)
|
|
c = c.replace(
|
|
" eventResolve: (id: string) => void",
|
|
" eventResolve: (id: string) => void\n getPhotos: () => Promise<PhotoMeta[]>\n capturePhoto: () => Promise<PhotoMeta[]>\n favPhoto: (id: string) => Promise<PhotoMeta[]>\n delPhoto: (id: string) => Promise<PhotoMeta[]>\n openPhoto: (id: string) => Promise<void>\n onPhotos: (cb: (list: PhotoMeta[]) => void) => () => void\n getFiles: () => Promise<FileMeta[]>\n delFile: (name: string) => Promise<FileMeta[]>\n onFiles: (cb: (list: FileMeta[]) => void) => () => void\n dropFile: (file: unknown) => void"
|
|
)
|
|
c = c.replace(
|
|
" eventResolve: (id: string) => ipcRenderer.send('pet:event:resolve', id),",
|
|
` eventResolve: (id: string) => ipcRenderer.send('pet:event:resolve', id),
|
|
getPhotos: () => ipcRenderer.invoke('pet:photos:list'),
|
|
capturePhoto: () => ipcRenderer.invoke('pet:photos:capture'),
|
|
favPhoto: (id: string) => ipcRenderer.invoke('pet:photos:fav', id),
|
|
delPhoto: (id: string) => ipcRenderer.invoke('pet:photos:del', id),
|
|
openPhoto: (id: string) => ipcRenderer.invoke('pet:photos:open', id),
|
|
onPhotos: (cb: (list: PhotoMeta[]) => void) => {
|
|
const l = (_e: unknown, list: PhotoMeta[]): void => cb(list)
|
|
ipcRenderer.on('pet:photos:update', l)
|
|
return () => ipcRenderer.removeListener('pet:photos:update', l)
|
|
},
|
|
getFiles: () => ipcRenderer.invoke('pet:files:list'),
|
|
delFile: (name: string) => ipcRenderer.invoke('pet:files:del', name),
|
|
onFiles: (cb: (list: FileMeta[]) => void) => {
|
|
const l = (_e: unknown, list: FileMeta[]): void => cb(list)
|
|
ipcRenderer.on('pet:files:update', l)
|
|
return () => ipcRenderer.removeListener('pet:files:update', l)
|
|
},
|
|
dropFile: (file: unknown) => {
|
|
const p = webUtils.getPathForFile(file as File)
|
|
ipcRenderer.send('pet:file:drop', p)
|
|
}`
|
|
)
|
|
fs.writeFileSync(p, c, 'utf8')
|
|
}
|
|
|
|
// ---- api.ts
|
|
{
|
|
const p = base + 'renderer/src/api.ts'
|
|
let c = fs.readFileSync(p, 'utf8')
|
|
c = c.replace(
|
|
"import type { LlmConfig } from '../../shared/llm'",
|
|
"import type { LlmConfig } from '../../shared/llm'\nimport type { FileMeta, PhotoMeta } from '../../shared/media'"
|
|
)
|
|
c = c.replace(
|
|
" eventResolve: (id: string) => void",
|
|
" eventResolve: (id: string) => void\n getPhotos: () => Promise<PhotoMeta[]>\n capturePhoto: () => Promise<PhotoMeta[]>\n favPhoto: (id: string) => Promise<PhotoMeta[]>\n delPhoto: (id: string) => Promise<PhotoMeta[]>\n openPhoto: (id: string) => Promise<void>\n onPhotos: (cb: (list: PhotoMeta[]) => void) => () => void\n getFiles: () => Promise<FileMeta[]>\n delFile: (name: string) => Promise<FileMeta[]>\n onFiles: (cb: (list: FileMeta[]) => void) => () => void\n dropFile: (file: unknown) => void"
|
|
)
|
|
fs.writeFileSync(p, c, 'utf8')
|
|
}
|
|
|
|
console.log('preload/api patched')
|