mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
f95cc754e7
Route global hotkey/tray show paths through restoreWindowInputFocus, recover renderer focus on visibility/show, dismiss transient overlays before native hide, and cancel deferred focus callbacks on hide. Closes #1722
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import test from "node:test";
|
|
|
|
const root = fileURLToPath(new URL("../..", import.meta.url));
|
|
|
|
function readProjectFile(path: string): string {
|
|
return readFileSync(join(root, path), "utf8");
|
|
}
|
|
|
|
test("useMainWindowInputFocusRecovery listens for visibility and window focus", () => {
|
|
const source = readProjectFile("application/state/useMainWindowInputFocusRecovery.ts");
|
|
|
|
assert.match(source, /document\.visibilityState !== "visible"/);
|
|
assert.match(source, /scheduleWindowInputFocus\(\)/);
|
|
assert.match(source, /document\.addEventListener\("visibilitychange", onVisibilityChange\)/);
|
|
assert.match(source, /window\.addEventListener\("focus", recoverFocus\)/);
|
|
});
|
|
|
|
test("useMainWindowInputFocusRecovery dismisses transient UI when the page hides", () => {
|
|
const source = readProjectFile("application/state/useMainWindowInputFocusRecovery.ts");
|
|
|
|
assert.match(source, /document\.visibilityState === "hidden"/);
|
|
assert.match(source, /onPageHidden\?\.\(\)/);
|
|
assert.match(source, /onWindowShown/);
|
|
assert.match(source, /onWindowWillHide/);
|
|
assert.match(source, /cancelPendingFocusRecovery/);
|
|
});
|
|
|
|
test("scheduleWindowInputFocus skips deferred focus when the page is hidden", () => {
|
|
const source = readProjectFile("application/state/windowInputFocus.ts");
|
|
|
|
assert.match(source, /document\.visibilityState !== "visible"/);
|
|
assert.match(source, /cancelAnimationFrame/);
|
|
assert.match(source, /clearTimeout/);
|
|
});
|
|
|
|
test("AppView mounts main-window input focus recovery with overlay dismiss", () => {
|
|
const source = readProjectFile("application/app/AppView.tsx");
|
|
|
|
assert.match(source, /useMainWindowInputFocusRecovery\(\{ onPageHidden: dismissTransientOverlays \}\)/);
|
|
assert.match(source, /setIsQuickSwitcherOpen\(false\)/);
|
|
assert.match(source, /setProtocolSelectHost\(null\)/);
|
|
});
|
|
|
|
test("dropdown closes when the document becomes hidden", () => {
|
|
const source = readProjectFile("components/ui/dropdown.tsx");
|
|
|
|
assert.match(source, /document\.visibilityState === "hidden"/);
|
|
assert.match(source, /setOpen\(false\)/);
|
|
});
|