fix(desktop): notification click prefers the focused/visible window
Fixes #78 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -149,11 +149,19 @@ self.addEventListener('notificationclick', (event: NotificationEvent) => {
|
|||||||
|
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
(async () => {
|
(async () => {
|
||||||
const windowClients = await self.clients.matchAll({
|
const windowClients = (
|
||||||
type: 'window',
|
await self.clients.matchAll({
|
||||||
includeUncontrolled: true,
|
type: 'window',
|
||||||
});
|
includeUncontrolled: true,
|
||||||
const client = windowClients.find((c): c is WindowClient => 'focus' in c);
|
})
|
||||||
|
).filter((c): c is WindowClient => 'focus' in c);
|
||||||
|
// #78 — prefer a client that's actually focused, then one that's merely
|
||||||
|
// visible, before falling back to whatever matchAll() returned first (its
|
||||||
|
// ordering is unspecified across browsers and not "most recently used").
|
||||||
|
const client =
|
||||||
|
windowClients.find((c) => c.focused) ??
|
||||||
|
windowClients.find((c) => c.visibilityState === 'visible') ??
|
||||||
|
windowClients[0];
|
||||||
if (client) {
|
if (client) {
|
||||||
await client.focus();
|
await client.focus();
|
||||||
if (path) client.postMessage({ type: 'notificationClick', path });
|
if (path) client.postMessage({ type: 'notificationClick', path });
|
||||||
|
|||||||
Reference in New Issue
Block a user