feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
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, 80).replace(/\n/g, '\\n'))
|
||||
return
|
||||
}
|
||||
c = c.replace(from, to)
|
||||
}
|
||||
|
||||
rep(
|
||||
"import { StateStore } from './stateStore'",
|
||||
"import { StateStore } from './stateStore'\nimport { MediaStore } from './mediaStore'\nimport { shell } from 'electron'"
|
||||
)
|
||||
|
||||
rep(
|
||||
"const store = new StateStore(path.join(HOME, 'data'))",
|
||||
"const store = new StateStore(path.join(HOME, 'data'))\nconst media = new MediaStore(path.join(HOME, 'data'))"
|
||||
)
|
||||
|
||||
// 协议:pet://photos/<file>
|
||||
rep(
|
||||
` let abs: string
|
||||
if (url.host === 'skins') abs = path.join(userSkins(), rel)
|
||||
else if (url.host === 'lib') abs = path.join(libRoot(), rel)
|
||||
else return new Response('not found', { status: 404 })
|
||||
|
||||
const root = url.host === 'skins' ? userSkins() : libRoot()`,
|
||||
` let abs: string
|
||||
let root: string
|
||||
if (url.host === 'skins') {
|
||||
abs = path.join(userSkins(), rel)
|
||||
root = userSkins()
|
||||
} else if (url.host === 'lib') {
|
||||
abs = path.join(libRoot(), rel)
|
||||
root = libRoot()
|
||||
} else if (url.host === 'photos') {
|
||||
abs = path.join(media.photoDir, rel)
|
||||
root = media.photoDir
|
||||
} else {
|
||||
return new Response('not found', { status: 404 })
|
||||
}`
|
||||
)
|
||||
|
||||
// 拍照与文件袋函数(放在气泡区域之前)
|
||||
rep(
|
||||
`let nextBarkAt = Date.now() + 25_000`,
|
||||
`async function capturePhoto(): Promise<void> {
|
||||
try {
|
||||
const img = await mainWindow!.webContents.capturePage()
|
||||
const name = \`photo-\${Date.now()}.png\`
|
||||
fs.writeFileSync(path.join(media.photoDir, name), img.toPNG())
|
||||
media.addPhoto(name)
|
||||
broadcastMedia()
|
||||
say('(摆了个姿势)拍好了! (๑•̀ㅂ•́)و✧', 5000)
|
||||
} catch (err) {
|
||||
console.error('[photo] 拍照失败', err)
|
||||
}
|
||||
}
|
||||
|
||||
function broadcastMedia(): void {
|
||||
for (const w of BrowserWindow.getAllWindows()) {
|
||||
if (w.isDestroyed()) continue
|
||||
w.webContents.send('pet:photos:update', media.photos)
|
||||
w.webContents.send('pet:files:update', media.files)
|
||||
}
|
||||
}
|
||||
|
||||
let nextBarkAt = Date.now() + 25_000`
|
||||
)
|
||||
|
||||
// IPC:图库 / 文件袋 / 知识库与联网占位
|
||||
rep(
|
||||
` ipcMain.on('pet:event:resolve', (_e, id: string) => {`,
|
||||
` ipcMain.handle('pet:photos:list', () => media.photos)
|
||||
ipcMain.handle('pet:photos:capture', async () => {
|
||||
await capturePhoto()
|
||||
return media.photos
|
||||
})
|
||||
ipcMain.handle('pet:photos:fav', (_e, id: string) => {
|
||||
media.toggleFavorite(String(id))
|
||||
broadcastMedia()
|
||||
return media.photos
|
||||
})
|
||||
ipcMain.handle('pet:photos:del', (_e, id: string) => {
|
||||
media.removePhoto(String(id))
|
||||
broadcastMedia()
|
||||
return media.photos
|
||||
})
|
||||
ipcMain.handle('pet:photos:open', (_e, id: string) => {
|
||||
const p = media.photos.find((x) => x.id === String(id))
|
||||
if (p) shell.showItemInFolder(path.join(media.photoDir, p.file))
|
||||
})
|
||||
ipcMain.handle('pet:files:list', () => media.files)
|
||||
ipcMain.handle('pet:files:del', (_e, name: string) => {
|
||||
media.removeFile(String(name))
|
||||
broadcastMedia()
|
||||
return media.files
|
||||
})
|
||||
ipcMain.handle('pet:kb:query', () => ({ ok: false, message: '知识库将在后续版本接入' }))
|
||||
ipcMain.handle('pet:web:search', () => ({ ok: false, message: '联网搜索将在后续版本接入' }))
|
||||
|
||||
ipcMain.on('pet:file:drop', (_e, src: string) => {
|
||||
try {
|
||||
if (!src || !fs.existsSync(src)) return
|
||||
const base = path.basename(src)
|
||||
const stored = \`\${Date.now()}-\${base}\`
|
||||
fs.copyFileSync(src, path.join(media.fileDir, stored))
|
||||
media.addFile(stored, src)
|
||||
broadcastMedia()
|
||||
say('(把东西收进抽屉)放好了,要用的时候跟我说~ ( ̄▽ ̄)', 5000)
|
||||
} catch (err) {
|
||||
console.error('[file] 收纳失败', err)
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('pet:event:resolve', (_e, id: string) => {`
|
||||
)
|
||||
|
||||
fs.writeFileSync(p, c, 'utf8')
|
||||
console.log('main media patched')
|
||||
Reference in New Issue
Block a user