Updated dynamic viewport title and icon

This commit is contained in:
Prozilla 2023-12-30 09:42:27 +01:00
parent a57e680024
commit 01c5d0be93
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE
2 changed files with 26 additions and 6 deletions

View file

@ -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();

View file

@ -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(() => {