feat(v0.1.1): 周期表五大分区 / 分区与单格改色 / 全屏视线跟随 / 窗口图标 / 跨平台打包

This commit is contained in:
TianXiaRi
2026-12-02 10:27:25 +08:00
parent a9adcd0088
commit 1faee09484
37 changed files with 2477 additions and 127 deletions
+93
View File
@@ -0,0 +1,93 @@
const fs = require('fs')
const p = 'E:/SodiumPet/WorkPlace/v0.1.1/src/main/index.ts'
let c = fs.readFileSync(p, 'utf8')
function rep(from, to, label) {
if (!c.includes(from)) {
console.log('MISS:', label)
return
}
c = c.replace(from, to)
console.log('ok:', label)
}
// 1) 数据目录:平台自适应
rep(
` const candidates = [
process.env.SODIUM_PET_HOME,
'E:\\\\SodiumPet',
path.dirname(app.getPath('exe')),
path.join(app.getPath('appData'), 'SodiumPet'),
path.join(app.getAppPath(), '.devdata')
].filter(Boolean) as string[]`,
` const isWin = process.platform === 'win32'
const candidates = [
process.env.SODIUM_PET_HOME,
// Windows 上沿用之前的固定目录;其他平台用系统标准数据目录
isWin ? 'E:\\\\SodiumPet' : '',
path.join(app.getPath('appData'), 'SodiumPet'),
isWin ? path.dirname(app.getPath('exe')) : '',
path.join(app.getAppPath(), '.devdata')
].filter(Boolean) as string[]`,
'resolveHome platform'
)
// 2) 点击穿透:forward 仅 Windows / macOS 支持
rep(
" mainWindow.setIgnoreMouseEvents(cfg.clickThrough, { forward: true })",
" mainWindow.setIgnoreMouseEvents(\n cfg.clickThrough,\n process.platform === 'linux' ? undefined : { forward: true }\n )",
'clickThrough forward'
)
// 3) 全屏视线跟随:33ms,窗口不可见也照常计算(多屏 / 其他窗口上方同样生效)
rep(
` // 全屏视线跟随:主进程按 50ms 轮询光标位置,发给宠物窗口
setInterval(() => {
const cfgNow = store.getConfig()
if (!cfgNow.eyeFollow || !mainWindow || !mainWindow.isVisible()) return
const p = screen.getCursorScreenPoint()
const b = mainWindow.getBounds()
mainWindow.webContents.send('pet:look', {
x: p.x - b.x + cfgNow.cropLeft,
y: p.y - b.y + cfgNow.cropTop
})
}, 50)`,
` // 全屏视线跟随:主进程按 33ms 轮询光标(屏幕坐标,跨窗口 / 跨显示器都有效)
setInterval(() => {
const cfgNow = store.getConfig()
if (!cfgNow.eyeFollow || !mainWindow || mainWindow.isDestroyed()) return
if (mainWindow.isMinimized()) return
const p = screen.getCursorScreenPoint()
const b = mainWindow.getBounds()
mainWindow.webContents.send('pet:look', {
x: p.x - b.x + cfgNow.cropLeft,
y: p.y - b.y + cfgNow.cropTop,
// 光标是否在窗口内(渲染层可用于复位/弱化)
inside: p.x >= b.x && p.x <= b.x + b.width && p.y >= b.y && p.y <= b.y + b.height
})
}, 33)`,
'global cursor polling'
)
// 4) 窗口截图探针(调试用,设置 PET_CAPTURE_PET 才生效)
rep(
` // 调试:把窗口内容截一张(不受窗口是否被遮挡影响)
if (process.env.PET_CAPTURE_ONCE) {`,
` if (process.env.PET_CAPTURE_PET) {
setTimeout(() => {
void mainWindow?.webContents.capturePage().then((img) => {
try {
fs.writeFileSync(process.env.PET_CAPTURE_PET as string, img.toPNG())
} catch {
/* 忽略 */
}
})
}, 7000)
}
// 调试:把窗口内容截一张(不受窗口是否被遮挡影响)
if (process.env.PET_CAPTURE_ONCE) {`,
'pet capture probe'
)
fs.writeFileSync(p, c, 'utf8')