feat: SodiumPet 小钠桌宠 v0.1.0(Live2D 桌宠 / 经济任务 / 音乐 / 成就 / 编辑器 / MOD)
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
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', [
|
||||
[
|
||||
` menuWindow.on('blur', () => {
|
||||
setTimeout(() => {
|
||||
if (menuWindow && !menuWindow.isFocused()) menuWindow.hide()
|
||||
}, 250)
|
||||
})`,
|
||||
` menuWindow.on('blur', () => {
|
||||
setTimeout(() => {
|
||||
if (menuWindow && !menuWindow.isFocused()) hideMenu()
|
||||
}, 250)
|
||||
})`
|
||||
],
|
||||
[
|
||||
`function showMenu(): void {`,
|
||||
`function toggleMenu(): void {
|
||||
if (menuWindow?.isVisible()) hideMenu()
|
||||
else showMenu()
|
||||
}
|
||||
|
||||
function showMenu(): void {`
|
||||
],
|
||||
[
|
||||
` ipcMain.on('pet:menu:show', () => showMenu())`,
|
||||
` ipcMain.on('pet:menu:show', () => showMenu())
|
||||
ipcMain.on('pet:menu:toggle', () => toggleMenu())`
|
||||
],
|
||||
[
|
||||
` ipcMain.handle('pet:photos:capture', async () => {`,
|
||||
` ipcMain.handle('pet:photos:import', async () => {
|
||||
const res = await dialog.showOpenDialog({
|
||||
title: '导入照片',
|
||||
properties: ['openFile', 'multiSelections'],
|
||||
filters: [{ name: '图片', extensions: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'] }]
|
||||
})
|
||||
if (res.canceled) return media.photos
|
||||
for (const src of res.filePaths) {
|
||||
try {
|
||||
const ext = path.extname(src) || '.png'
|
||||
const name = \`import-\${Date.now()}-\${Math.floor(Math.random() * 10000)}\${ext}\`
|
||||
fs.copyFileSync(src, path.join(media.photoDir, name))
|
||||
media.addPhoto(name)
|
||||
} catch (err) {
|
||||
console.error('[photo] 导入失败', src, err)
|
||||
}
|
||||
}
|
||||
broadcastMedia()
|
||||
return media.photos
|
||||
})
|
||||
ipcMain.handle('pet:photos:capture', async () => {`
|
||||
]
|
||||
])
|
||||
|
||||
// ---- preload / api
|
||||
patch('preload/index.ts', [
|
||||
[
|
||||
" openPanelAt: (tab: string, arg?: string) => void",
|
||||
" openPanelAt: (tab: string, arg?: string) => void\n toggleMenu: () => void\n importPhotos: () => Promise<PhotoMeta[]>"
|
||||
],
|
||||
[
|
||||
" openPanelAt: (tab: string, arg?: string) => ipcRenderer.send('pet:panel:open', tab, arg),",
|
||||
" openPanelAt: (tab: string, arg?: string) => ipcRenderer.send('pet:panel:open', tab, arg),\n toggleMenu: () => ipcRenderer.send('pet:menu:toggle'),\n importPhotos: () => ipcRenderer.invoke('pet:photos:import'),"
|
||||
]
|
||||
])
|
||||
patch('renderer/src/api.ts', [
|
||||
[
|
||||
" openPanelAt: (tab: string, arg?: string) => void",
|
||||
" openPanelAt: (tab: string, arg?: string) => void\n toggleMenu: () => void\n importPhotos: () => Promise<PhotoMeta[]>"
|
||||
]
|
||||
])
|
||||
|
||||
// ---- App:右键改为切换
|
||||
patch('renderer/src/App.tsx', [
|
||||
[
|
||||
" onContextMenu={(e) => {\n e.preventDefault()\n api()?.showMenu()\n }}",
|
||||
" onContextMenu={(e) => {\n e.preventDefault()\n api()?.toggleMenu()\n }}"
|
||||
]
|
||||
])
|
||||
|
||||
// ---- Panel:导入按钮
|
||||
patch('renderer/src/panel/Panel.tsx', [
|
||||
[
|
||||
` <button className="mini" onClick={() => void api()?.capturePhoto()}>
|
||||
拍照
|
||||
</button>`,
|
||||
` <div className="detail-actions">
|
||||
<button className="mini" onClick={() => void api()?.capturePhoto()}>
|
||||
拍照
|
||||
</button>
|
||||
<button className="mini" onClick={() => void api()?.importPhotos()}>
|
||||
导入照片
|
||||
</button>
|
||||
</div>`
|
||||
]
|
||||
])
|
||||
|
||||
console.log('toggle/import patched')
|
||||
Reference in New Issue
Block a user