ignore backdrop click within 300ms of showing a modal

a click that focuses the window lands on the modal backdrop too, so
the update-available prompt after an unattended auto-check could get
dismissed by the very click that brought the window to front, before
it was ever seen
This commit is contained in:
Horizontal42 2026-07-16 01:14:52 +03:00
parent 6f6c3b439a
commit 087ee44f12

View file

@ -674,6 +674,7 @@ function askModal(msg: string, aLabel: string, bLabel: string): Promise<"a" | "b
b.textContent = bLabel; b.textContent = bLabel;
a.classList.add("primary"); a.classList.add("primary");
modal.classList.remove("hidden"); modal.classList.remove("hidden");
const shownAt = Date.now();
const done = (res: "a" | "b" | null) => { const done = (res: "a" | "b" | null) => {
modal.classList.add("hidden"); modal.classList.add("hidden");
a.onclick = b.onclick = modal.onclick = null; a.onclick = b.onclick = modal.onclick = null;
@ -682,7 +683,10 @@ function askModal(msg: string, aLabel: string, bLabel: string): Promise<"a" | "b
a.onclick = () => done("a"); a.onclick = () => done("a");
b.onclick = () => done("b"); b.onclick = () => done("b");
modal.onclick = (e) => { modal.onclick = (e) => {
if (e.target === modal) done(null); // a click that focuses the window (e.g. after an unattended auto-check
// shows this modal) lands on the backdrop too — ignore it right after
// showing so it can't dismiss a prompt the user hasn't actually seen yet
if (e.target === modal && Date.now() - shownAt > 300) done(null);
}; };
}); });
} }