From 15e591f30d5932fb0619d157e6a8ac7df36a239e Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 13 Jan 2025 19:47:24 -0800 Subject: [PATCH] enh: electron window focus detect --- src/lib/components/app/AppControls.svelte | 2 +- src/routes/+layout.svelte | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/components/app/AppControls.svelte b/src/lib/components/app/AppControls.svelte index 331da192b..ea84be6c3 100644 --- a/src/lib/components/app/AppControls.svelte +++ b/src/lib/components/app/AppControls.svelte @@ -2,7 +2,7 @@ import Tooltip from '$lib/components/common/Tooltip.svelte'; import Plus from '$lib/components/icons/Plus.svelte'; - let selected = 'home'; + let selected = '';
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index bf67394f7..a9b698065 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -103,10 +103,14 @@ const chatEventHandler = async (event) => { const chat = $page.url.pathname.includes(`/c/${event.chat_id}`); - if ( - (event.chat_id !== $chatId && !$temporaryChatEnabled) || - document.visibilityState !== 'visible' - ) { + let isFocused = document.visibilityState !== 'visible'; + if (window.electronAPI) { + isFocused = await window.electronAPI.send({ + type: 'window:isFocused' + }); + } + + if ((event.chat_id !== $chatId && !$temporaryChatEnabled) || isFocused) { await tick(); const type = event?.data?.type ?? null; const data = event?.data?.data ?? null; @@ -149,7 +153,14 @@ // check url path const channel = $page.url.pathname.includes(`/channels/${event.channel_id}`); - if ((!channel || document.visibilityState !== 'visible') && event?.user?.id !== $user?.id) { + let isFocused = document.visibilityState !== 'visible'; + if (window.electronAPI) { + isFocused = await window.electronAPI.send({ + type: 'window:isFocused' + }); + } + + if ((!channel || isFocused) && event?.user?.id !== $user?.id) { await tick(); const type = event?.data?.type ?? null; const data = event?.data?.data ?? null;