110 lines
2.6 KiB
JavaScript
110 lines
2.6 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', [
|
|
[
|
|
`function createChatBar(): void {`,
|
|
`let chatExpanded = false
|
|
|
|
function createChatBar(): void {`
|
|
],
|
|
[
|
|
` x: Math.round(b.x + b.width / 2 - 210),
|
|
y: Math.max(0, b.y - 118),
|
|
width: 420,
|
|
height: 54,`,
|
|
` x: Math.round(b.x + b.width / 2 - 210),
|
|
y: Math.max(0, b.y - 118) + 54 - (chatExpanded ? 250 : 54),
|
|
width: 420,
|
|
height: chatExpanded ? 250 : 54,`
|
|
],
|
|
[
|
|
` ipcMain.on('pet:menu:toggle', () => toggleMenu())`,
|
|
` ipcMain.on('pet:menu:toggle', () => toggleMenu())
|
|
ipcMain.on('pet:chat:expand', (_e, open: boolean) => {
|
|
chatExpanded = Boolean(open)
|
|
positionChatBar()
|
|
})`
|
|
]
|
|
])
|
|
|
|
// preload / api
|
|
patch('preload/index.ts', [
|
|
[
|
|
" openDetail: () => void",
|
|
" openDetail: () => void\n setChatExpanded: (open: boolean) => void"
|
|
],
|
|
[
|
|
" openDetail: () => ipcRenderer.send('pet:detail:open'),",
|
|
" openDetail: () => ipcRenderer.send('pet:detail:open'),\n setChatExpanded: (open: boolean) => ipcRenderer.send('pet:chat:expand', open),"
|
|
]
|
|
])
|
|
patch('renderer/src/api.ts', [
|
|
[
|
|
" openDetail: () => void",
|
|
" openDetail: () => void\n setChatExpanded: (open: boolean) => void"
|
|
]
|
|
])
|
|
|
|
// ChatBar:切换展开
|
|
patch('renderer/src/chat/ChatBar.tsx', [
|
|
[
|
|
` <button className="chat-more" onClick={() => setOpen((v) => !v)} title="预设话题">`,
|
|
` <button
|
|
className="chat-more"
|
|
onClick={() => {
|
|
const next = !open
|
|
setOpen(next)
|
|
api()?.setChatExpanded(next)
|
|
}}
|
|
title="预设话题"
|
|
>`
|
|
]
|
|
])
|
|
|
|
// CSS:对话条固定在底部,预设面板在它上方
|
|
patch('renderer/src/chat/chat.css', [
|
|
[
|
|
`.chat-bar {
|
|
position: absolute;
|
|
inset: 4px;
|
|
display: flex;`,
|
|
`.chat-bar {
|
|
position: absolute;
|
|
left: 4px;
|
|
right: 4px;
|
|
bottom: 4px;
|
|
height: 46px;
|
|
display: flex;`
|
|
],
|
|
[
|
|
`.chat-suggest {
|
|
position: absolute;
|
|
left: 8px;
|
|
right: 8px;
|
|
bottom: 48px;`,
|
|
`.chat-suggest {
|
|
position: absolute;
|
|
left: 8px;
|
|
right: 8px;
|
|
bottom: 58px;
|
|
max-height: 184px;
|
|
overflow-y: auto;`
|
|
]
|
|
])
|
|
|
|
console.log('chat expand patched')
|