enh: electron window focus detect

This commit is contained in:
Timothy Jaeryang Baek 2025-01-13 19:47:24 -08:00
parent 84b7583982
commit 15e591f30d
2 changed files with 17 additions and 6 deletions

View File

@ -2,7 +2,7 @@
import Tooltip from '$lib/components/common/Tooltip.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte';
import Plus from '$lib/components/icons/Plus.svelte'; import Plus from '$lib/components/icons/Plus.svelte';
let selected = 'home'; let selected = '';
</script> </script>
<div class="min-w-[4.5rem] bg-gray-50 dark:bg-gray-950 flex gap-2.5 flex-col pt-10"> <div class="min-w-[4.5rem] bg-gray-50 dark:bg-gray-950 flex gap-2.5 flex-col pt-10">

View File

@ -103,10 +103,14 @@
const chatEventHandler = async (event) => { const chatEventHandler = async (event) => {
const chat = $page.url.pathname.includes(`/c/${event.chat_id}`); const chat = $page.url.pathname.includes(`/c/${event.chat_id}`);
if ( let isFocused = document.visibilityState !== 'visible';
(event.chat_id !== $chatId && !$temporaryChatEnabled) || if (window.electronAPI) {
document.visibilityState !== 'visible' isFocused = await window.electronAPI.send({
) { type: 'window:isFocused'
});
}
if ((event.chat_id !== $chatId && !$temporaryChatEnabled) || isFocused) {
await tick(); await tick();
const type = event?.data?.type ?? null; const type = event?.data?.type ?? null;
const data = event?.data?.data ?? null; const data = event?.data?.data ?? null;
@ -149,7 +153,14 @@
// check url path // check url path
const channel = $page.url.pathname.includes(`/channels/${event.channel_id}`); 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(); await tick();
const type = event?.data?.type ?? null; const type = event?.data?.type ?? null;
const data = event?.data?.data ?? null; const data = event?.data?.data ?? null;