加入滑鼠事件紀錄與鎖定/解鎖處理,追查解鎖後點不到寵物
根本原因: 使用者回報登出/鎖定螢幕再回來後就不能拖曳、不能右鍵。現場量測顯示 OS 這一層正常(點穿位元會切、WindowFromPoint 打到寵物視窗),但事件紀錄裡 完全沒有拖曳或選單的痕跡,代表問題在 renderer 有沒有收到滑鼠事件這一層, 而這一層目前沒有任何可觀測資料,無法判斷。 影響: 解鎖後偶發點不到寵物,且發生時查不出卡在哪裡。 修法: 1. renderer 把 mousedown/mouseup(含按鍵與座標、當時的 pressed/drag)與 hover 進出寫進事件紀錄;pet:state 帶 rendererMouse(pressed/drag/hovered /overlay),/state 可直接查。 2. 主程序監聽 powerMonitor 的 lock-screen/unlock-screen/suspend/resume: 記錄到事件紀錄與 /state.mouse.sessionEvents,解鎖或喚醒後重新套用目前的 點穿狀態、showInactive 並重宣告置頂。 版號 2.0.12。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
const { app, BrowserWindow, Tray, Menu, screen, ipcMain, nativeImage, shell, dialog } = require("electron");
|
||||
const { app, BrowserWindow, Tray, Menu, screen, ipcMain, nativeImage, shell, dialog, powerMonitor } = require("electron");
|
||||
const http = require("node:http");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
@@ -69,6 +69,7 @@ const mouseDiag = {
|
||||
toggles: 0, lastToggleAt: null, polls: 0, lastPollAt: null,
|
||||
rel: null, inBox: false, inBubble: false,
|
||||
rendererErrors: 0, lastRendererError: null, dragEnds: [],
|
||||
sessionEvents: [], // 鎖定/解鎖/睡眠/喚醒
|
||||
};
|
||||
let currentState = { anim: "idle", base: "idle", sessions: 0 };
|
||||
|
||||
@@ -374,6 +375,25 @@ function reassertTopmost() {
|
||||
} catch { /* 視窗正在關閉就算了 */ }
|
||||
}
|
||||
|
||||
// 鎖定/解鎖與睡眠喚醒:session 切換後 Windows 可能把視窗的輸入或 z-order 狀態弄掉,
|
||||
// 記下來並把目前的點穿狀態與置頂重新套用一次
|
||||
function watchSessionChanges() {
|
||||
for (const ev of ["lock-screen", "unlock-screen", "suspend", "resume"]) {
|
||||
powerMonitor.on(ev, () => {
|
||||
appendLog(`power: ${ev}`);
|
||||
mouseDiag.sessionEvents.push({ at: Date.now(), ev });
|
||||
if (mouseDiag.sessionEvents.length > 10) mouseDiag.sessionEvents.shift();
|
||||
if (ev !== "unlock-screen" && ev !== "resume") return;
|
||||
if (!win || win.isDestroyed()) return;
|
||||
try {
|
||||
win.setIgnoreMouseEvents(ignoring, { forward: true });
|
||||
win.showInactive();
|
||||
} catch { /* 視窗正在關閉 */ }
|
||||
reassertTopmost();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function startTopmostGuard() {
|
||||
topmostTimer = setInterval(reassertTopmost, TOPMOST_REASSERT_MS);
|
||||
// 螢幕配置變動最容易觸發降級,變動後立刻補一次
|
||||
@@ -735,6 +755,7 @@ if (!app.requestSingleInstanceLock()) {
|
||||
startServer();
|
||||
startCursorPolling();
|
||||
startTopmostGuard();
|
||||
watchSessionChanges();
|
||||
appendLog(`started pet=${activePet()?.id || "none"} scale=${config.scale} port=${config.port}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user