From 01c5d0be93c38bb52a3ad0ab89ddf30c4d333439 Mon Sep 17 00:00:00 2001 From: Prozilla Date: Sat, 30 Dec 2023 09:42:27 +0100 Subject: [PATCH] Updated dynamic viewport title and icon --- src/components/windows/WindowView.jsx | 15 ++++++++++++--- src/components/windows/WindowsView.jsx | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/windows/WindowView.jsx b/src/components/windows/WindowView.jsx index 52f54d9..05f358b 100644 --- a/src/components/windows/WindowView.jsx +++ b/src/components/windows/WindowView.jsx @@ -86,11 +86,20 @@ export const WindowView = memo(({ id, app, size, position, onInteract, options, }, [position, size, screenHeight, screenWidth]); useEffect(() => { - if (active) { + const setViewportTitleAndIcon = () => { setViewportTitle(`${title} | ${NAME}`); setViewportIcon(iconUrl); - } - }, [active, iconUrl, title]); + }; + + if (active && !minimized) + setViewportTitleAndIcon(); + + window.addEventListener("focus", setViewportTitleAndIcon); + + return () => { + window.removeEventListener("focus", setViewportTitleAndIcon); + }; + }, [active, minimized, iconUrl, title]); const close = (event) => { event?.preventDefault(); diff --git a/src/components/windows/WindowsView.jsx b/src/components/windows/WindowsView.jsx index 8e1bbb5..f8cc95c 100644 --- a/src/components/windows/WindowsView.jsx +++ b/src/components/windows/WindowsView.jsx @@ -18,12 +18,23 @@ export const WindowsView = memo(() => { setSortedWindows([...windows].sort((windowA, windowB) => windowA.lastInteraction - windowB.lastInteraction )); + }, [windows]); - if (windows.length === 0) { + useEffect(() => { + const resetViewportTitleAndIcon = () => { setViewportTitle(`${NAME} | ${TAG_LINE}`); setViewportIcon(`${process.env.PUBLIC_URL}/favicon.ico`); - } - }, [windows]); + }; + + if (sortedWindows.length === 0 || sortedWindows[sortedWindows.length - 1].minimized) + resetViewportTitleAndIcon(); + + window.addEventListener("blur", resetViewportTitleAndIcon); + + return () => { + window.removeEventListener("blur", resetViewportTitleAndIcon); + }; + }, [sortedWindows]); // Launch startup apps useEffect(() => {