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
+68 -18
View File
@@ -35,11 +35,13 @@ import { chatEffect, suggestions } from '../shared/dialogue'
// 默认把「软件主体」放到 E:\SodiumPet,只有 Windows 临时/GPU 缓存留在 C 盘。
// 沙箱里写不进去时,逐级回退,保证开发时也能跑。
function resolveHome(): string {
const isWin = process.platform === 'win32'
const candidates = [
process.env.SODIUM_PET_HOME,
'E:\\SodiumPet',
path.dirname(app.getPath('exe')),
// 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[]
@@ -317,6 +319,16 @@ function buildTrayIcon(): NativeImage {
}
// ---------------------------------------------------------------- 主窗口
function stickerIcon(name: string, size = 64): NativeImage | undefined {
try {
const p = path.join(bundledDir('stickers'), name)
if (fs.existsSync(p)) return nativeImage.createFromPath(p).resize({ width: size, height: size })
} catch {
/* 忽略 */
}
return undefined
}
function appIcon(): NativeImage | undefined {
try {
const p = path.join(bundledDir('stickers'), '1.0.png')
@@ -332,7 +344,7 @@ function createWindow(): void {
const width = 190
const height = 450
mainWindow = new BrowserWindow({
mainWindow = new BrowserWindow({ icon: stickerIcon('1.0.png'),
width,
height,
x: Math.round(workArea.x + workArea.width - width - 24),
@@ -379,6 +391,18 @@ function createWindow(): void {
mainWindow.setAlwaysOnTop(true, 'screen-saver')
}, 15000)
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) {
setTimeout(() => {
@@ -493,8 +517,12 @@ function createWindow(): void {
setTimeout(() => {
void (async () => {
if (!editorWindow) return
const tabLabels = await editorWindow.webContents.executeJavaScript(
"JSON.stringify([...document.querySelectorAll('.detail-tabs .set-tab')].map(b => b.textContent.trim()))"
)
fs.writeFileSync(path.join(HOME, 'data', 'editor-tabs.txt'), String(tabLabels))
await editorWindow.webContents.executeJavaScript(
"[...document.querySelectorAll('.detail-tabs .set-tab')].find(b => b.textContent === '界面')?.click()"
"(() => { const bs = [...document.querySelectorAll('.detail-tabs .set-tab')]; const t = bs.find(b => b.textContent.trim() === '等级') || bs[2]; t && t.click(); return !!t })()"
)
await new Promise((r) => setTimeout(r, 400))
const txt = await editorWindow.webContents.executeJavaScript(
@@ -505,6 +533,12 @@ function createWindow(): void {
"document.querySelectorAll('.sticker-cell').length"
)
fs.writeFileSync(path.join(HOME, 'data', 'stickers.txt'), String(stickerCount))
const catCount = await editorWindow.webContents.executeJavaScript(
"JSON.stringify({ cells: document.querySelectorAll('.ped-cell').length, zones: document.querySelectorAll('.color-row').length, colors: [0,4,25,28,56,117].map(i => getComputedStyle(document.querySelectorAll('.ped-cell')[i]).backgroundColor) })"
)
fs.writeFileSync(path.join(HOME, 'data', 'ped-stats.txt'), String(catCount))
const shot = await editorWindow.webContents.capturePage()
fs.writeFileSync(path.join(HOME, 'data', 'editor.png'), shot.toPNG())
})()
}, 9000)
setTimeout(() => {
@@ -521,6 +555,15 @@ function createWindow(): void {
await detailWindow.webContents.executeJavaScript(
"[...document.querySelectorAll('.level-mode .set-tab')].find(b => b.textContent.includes('化学'))?.click()"
)
await new Promise((r) => setTimeout(r, 300))
{
const shot = await detailWindow.webContents.capturePage()
fs.writeFileSync(path.join(HOME, 'data', 'detail.png'), shot.toPNG())
const leg = await detailWindow.webContents.executeJavaScript(
"JSON.stringify([...document.querySelectorAll('.legend-item')].map(x => x.innerText.trim()))"
)
fs.writeFileSync(path.join(HOME, 'data', 'legend.txt'), String(leg))
}
await new Promise((r) => setTimeout(r, 400))
const online = await detailWindow.webContents.executeJavaScript(
@@ -677,7 +720,10 @@ function applyConfig(cfg: PetConfig): void {
})
console.log('[config] bounds', mainWindow.getBounds(), 'dpr', screen.getPrimaryDisplay().scaleFactor)
mainWindow.setAlwaysOnTop(cfg.topmost, 'screen-saver')
mainWindow.setIgnoreMouseEvents(cfg.clickThrough, { forward: true })
mainWindow.setIgnoreMouseEvents(
cfg.clickThrough,
process.platform === 'linux' ? undefined : { forward: true }
)
for (const w of BrowserWindow.getAllWindows()) {
if (!w.isDestroyed()) w.webContents.send('pet:config:update', cfg)
}
@@ -693,7 +739,7 @@ let currentBubble: { text: string; duration: number; at: number } | null = null
function createBubbleWindow(): void {
if (bubbleWindow && !bubbleWindow.isDestroyed()) return
bubbleWindow = new BrowserWindow({
bubbleWindow = new BrowserWindow({ icon: stickerIcon('2.0.png'),
width: 440,
height: 96,
show: false,
@@ -1042,7 +1088,7 @@ let lyricWindow: BrowserWindow | null = null
function createMenuWindow(): void {
if (menuWindow && !menuWindow.isDestroyed()) return
menuWindow = new BrowserWindow({
menuWindow = new BrowserWindow({ icon: stickerIcon('3.0.png'),
width: 400,
height: 380,
show: false,
@@ -1191,7 +1237,7 @@ function createMusicWindow(): void {
musicWindow.focus()
return
}
musicWindow = new BrowserWindow({
musicWindow = new BrowserWindow({ icon: stickerIcon('20.0.png'),
width: 880,
height: 600,
minWidth: 700,
@@ -1219,7 +1265,7 @@ function createMusicWindow(): void {
function createLyricWindow(): void {
if (lyricWindow && !lyricWindow.isDestroyed()) return
lyricWindow = new BrowserWindow({
lyricWindow = new BrowserWindow({ icon: stickerIcon('9.0.png'),
width: 560,
height: 110,
show: true,
@@ -1252,7 +1298,7 @@ function createEditorWindow(): void {
editorWindow.focus()
return
}
editorWindow = new BrowserWindow({
editorWindow = new BrowserWindow({ icon: stickerIcon('23.1.png'),
width: 780,
height: 560,
minWidth: 640,
@@ -1283,7 +1329,7 @@ function createDetailWindow(): void {
detailWindow.focus()
return
}
detailWindow = new BrowserWindow({
detailWindow = new BrowserWindow({ icon: stickerIcon('4.0.png'),
width: 720,
height: 520,
minWidth: 520,
@@ -1314,7 +1360,7 @@ function createStorageWindow(): void {
storageWindow.focus()
return
}
storageWindow = new BrowserWindow({
storageWindow = new BrowserWindow({ icon: stickerIcon('16.0.png'),
width: 780,
height: 660,
minWidth: 560,
@@ -1508,7 +1554,7 @@ let chatExpanded = false
function createChatBar(): void {
if (chatBar && !chatBar.isDestroyed()) return
chatBar = new BrowserWindow({
chatBar = new BrowserWindow({ icon: stickerIcon('8.0.png'),
width: 420,
height: 54,
show: false,
@@ -1565,7 +1611,7 @@ function createPanel(tab?: string, arg?: string): void {
return
}
panelWindow = new BrowserWindow({
panelWindow = new BrowserWindow({ icon: stickerIcon('5.0.png'),
width: 640,
height: 430,
show: false,
@@ -2334,17 +2380,21 @@ if (!gotLock) {
}
}, 3000)
// 全屏视线跟随:主进程按 50ms 轮询光标位置,发给宠物窗口
// 全屏视线跟随:主进程按 33ms 轮询光标(屏幕坐标,跨窗口 / 跨显示器都有效)
setInterval(() => {
const cfgNow = store.getConfig()
if (!cfgNow.eyeFollow || !mainWindow || !mainWindow.isVisible()) return
const forceLook = !!process.env.PET_FORCE_EYE_FOLLOW
if (!(cfgNow.eyeFollow || forceLook) || !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
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
})
}, 50)
}, 33)
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()