Skip to content

Commit 58aec32

Browse files
committed
fix: stabilize desktop lens for v0.1.1
1 parent 83d0bab commit 58aec32

11 files changed

Lines changed: 997 additions & 181 deletions

electron/main.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ let isQuitting = false;
105105
let shutdownComplete = false;
106106
let shutdownPromise: Promise<void> | undefined;
107107
let visibleUpdateCheckTimer: NodeJS.Timeout | undefined;
108+
let mainWindowRecoveryTimer: NodeJS.Timeout | undefined;
108109
let lastVisibleUpdateCheckAt = 0;
109110
const store = new AppStore();
110111
let migrationService: MigrationService;
@@ -126,7 +127,7 @@ function syncSearchBackgroundMode(): void {
126127
searchService?.setBackgroundMode(!hasVisibleWindow);
127128
}
128129

129-
function trackWindowActivity(window: BrowserWindow): void {
130+
function trackWindowActivity(window: BrowserWindow, role: "main" | "quick"): void {
130131
const sync = () => setImmediate(syncSearchBackgroundMode);
131132
window.on("show", sync);
132133
window.on("hide", sync);
@@ -145,6 +146,22 @@ function trackWindowActivity(window: BrowserWindow): void {
145146
reason: details.reason,
146147
exitCode: details.exitCode
147148
});
149+
if (
150+
role === "main" &&
151+
!isQuitting &&
152+
window.isVisible() &&
153+
details.reason !== "clean-exit"
154+
) {
155+
if (mainWindowRecoveryTimer) clearTimeout(mainWindowRecoveryTimer);
156+
mainWindowRecoveryTimer = setTimeout(() => {
157+
mainWindowRecoveryTimer = undefined;
158+
if (isQuitting || mainWindow !== window) return;
159+
logger.warn("renderer.recovering", { reason: details.reason });
160+
if (!window.isDestroyed()) window.destroy();
161+
mainWindow = createWindow();
162+
}, 250);
163+
mainWindowRecoveryTimer.unref();
164+
}
148165
});
149166
}
150167

@@ -407,7 +424,7 @@ function createWindow(): BrowserWindow {
407424

408425
initializeUiScale(window, settings.uiScale);
409426
window.setMenuBarVisibility(false);
410-
trackWindowActivity(window);
427+
trackWindowActivity(window, "main");
411428
window.on("restore", () => triggerVisibleUpdateCheck("main-window-restored"));
412429
trackWindowBounds(window, "mainWindowBounds");
413430
window.on("close", (event) => {
@@ -594,7 +611,7 @@ function createQuickSearchWindow(): BrowserWindow {
594611
quickSearchWindow = window;
595612
initializeUiScale(window, settings.uiScale);
596613
window.setMenuBarVisibility(false);
597-
trackWindowActivity(window);
614+
trackWindowActivity(window, "quick");
598615
trackWindowBounds(window, "quickSearchWindowBounds");
599616
window.once("ready-to-show", () => {
600617
if (restored?.maximized) window.maximize();
@@ -1225,9 +1242,9 @@ function registerIpc(): void {
12251242
message: "Windows 局部放大镜尚未启动"
12261243
}
12271244
);
1228-
ipcMain.handle("shortcut:magnifier-capture", (_event, active: unknown) =>
1229-
searchService?.setMagnifierCapture(active === true) ?? false
1230-
);
1245+
ipcMain.handle("shortcut:magnifier-capture", async (_event, active: unknown) => {
1246+
return (await searchService?.setMagnifierCapture(active === true)) ?? false;
1247+
});
12311248

12321249
ipcMain.handle("app:navigate", (_event, raw: unknown) => {
12331250
if (!raw || typeof raw !== "object") throw new Error("导航请求无效");

native/indexer/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ regex = "1.11.1"
1515
[target.'cfg(windows)'.dependencies]
1616
windows-sys = { version = "0.52.0", features = [
1717
"Win32_Foundation",
18+
"Win32_Graphics_Dwm",
1819
"Win32_Graphics_Gdi",
1920
"Win32_Security",
2021
"Win32_Storage_FileSystem",
@@ -24,6 +25,7 @@ windows-sys = { version = "0.52.0", features = [
2425
"Win32_System_Threading",
2526
"Win32_UI_Input",
2627
"Win32_UI_Input_KeyboardAndMouse",
28+
"Win32_UI_HiDpi",
2729
"Win32_UI_Magnification",
2830
"Win32_UI_WindowsAndMessaging"
2931
] }

0 commit comments

Comments
 (0)