From 14bada8dc9b225931681841641a3896265505618 Mon Sep 17 00:00:00 2001 From: Tasso Date: Thu, 11 Sep 2025 01:33:23 -0300 Subject: [PATCH 1/4] Add fake module for `/app/settings/client/index.ts` --- apps/meteor/client/main.ts | 2 +- .../meteor/client/startup/desktopInjection.ts | 32 +++++++++++++++++++ .../meteor/client/startup/fakeUserPresence.ts | 18 ----------- 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 apps/meteor/client/startup/desktopInjection.ts delete mode 100644 apps/meteor/client/startup/fakeUserPresence.ts diff --git a/apps/meteor/client/main.ts b/apps/meteor/client/main.ts index c19ffe0b59b58..7edd934d5264d 100644 --- a/apps/meteor/client/main.ts +++ b/apps/meteor/client/main.ts @@ -1,6 +1,6 @@ import './serviceWorker'; import './startup/accounts'; -import './startup/fakeUserPresence'; +import './startup/desktopInjection'; import('@rocket.chat/fuselage-polyfills') .then(() => import('./meteor/overrides')) diff --git a/apps/meteor/client/startup/desktopInjection.ts b/apps/meteor/client/startup/desktopInjection.ts new file mode 100644 index 0000000000000..f3d20b525e92f --- /dev/null +++ b/apps/meteor/client/startup/desktopInjection.ts @@ -0,0 +1,32 @@ +import { watch } from '../meteor/watch'; +import { PublicSettings } from '../stores'; + +if (window.RocketChatDesktop) { + // backport of rocketchat:user-presence for the desktop app + const fakeUserPresenceModule = { + UserPresence: { + awayTime: undefined, + start: () => undefined, + }, + }; + + // backport of settings module for the desktop app + const fakeSettingsModule = { + settings: { + get: (settingId: string) => watch(PublicSettings.use, (state) => state.get(settingId)?.value), + }, + }; + + window.require = ((fn) => + Object.assign((id: string) => { + if (id === 'meteor/rocketchat:user-presence') { + return fakeUserPresenceModule; + } + + if (id === '/app/settings/client/index.ts') { + return fakeSettingsModule; + } + + return fn(id); + }, fn))(window.require); +} diff --git a/apps/meteor/client/startup/fakeUserPresence.ts b/apps/meteor/client/startup/fakeUserPresence.ts deleted file mode 100644 index 3bda53c5055fd..0000000000000 --- a/apps/meteor/client/startup/fakeUserPresence.ts +++ /dev/null @@ -1,18 +0,0 @@ -// backport of rocketchat:user-presence for the desktop app - -if (window.RocketChatDesktop) { - const fakeUserPresenceModule = { - UserPresence: { - awayTime: undefined, - start: () => undefined, - }, - }; - - window.require = ((fn) => - Object.assign((id: string) => { - if (id === 'meteor/rocketchat:user-presence') { - return fakeUserPresenceModule; - } - return fn(id); - }, fn))(window.require); -} From 736f0e43a3075dce9eff1b106a59d4a98e5e44ba Mon Sep 17 00:00:00 2001 From: Tasso Date: Thu, 11 Sep 2025 02:01:32 -0300 Subject: [PATCH 2/4] Handle some desktop app calls based on server settings --- apps/meteor/client/views/root/AppLayout.tsx | 4 ++++ .../client/views/root/hooks/useDesktopFavicon.ts | 13 +++++++++++++ .../client/views/root/hooks/useDesktopTitle.ts | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 apps/meteor/client/views/root/hooks/useDesktopFavicon.ts create mode 100644 apps/meteor/client/views/root/hooks/useDesktopTitle.ts diff --git a/apps/meteor/client/views/root/AppLayout.tsx b/apps/meteor/client/views/root/AppLayout.tsx index cb671e3fea60a..198616b40c9ce 100644 --- a/apps/meteor/client/views/root/AppLayout.tsx +++ b/apps/meteor/client/views/root/AppLayout.tsx @@ -12,6 +12,8 @@ import { useNextcloudOAuth } from './hooks/customOAuth/useNextcloudOAuth'; import { useTokenpassOAuth } from './hooks/customOAuth/useTokenpassOAuth'; import { useWordPressOAuth } from './hooks/customOAuth/useWordPressOAuth'; import { useCodeHighlight } from './hooks/useCodeHighlight'; +import { useDesktopFavicon } from './hooks/useDesktopFavicon'; +import { useDesktopTitle } from './hooks/useDesktopTitle'; import { useEscapeKeyStroke } from './hooks/useEscapeKeyStroke'; import { useGoogleTagManager } from './hooks/useGoogleTagManager'; import { useLoadMissedMessages } from './hooks/useLoadMissedMessages'; @@ -65,6 +67,8 @@ const AppLayout = () => { useCodeHighlight(); useLoginViaQuery(); useLoadMissedMessages(); + useDesktopFavicon(); + useDesktopTitle(); const layout = useSyncExternalStore(appLayout.subscribe, appLayout.getSnapshot); diff --git a/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts new file mode 100644 index 0000000000000..3994750fa2cd3 --- /dev/null +++ b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts @@ -0,0 +1,13 @@ +import { useAssetPath } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +const { RocketChatDesktop } = window; + +export const useDesktopFavicon = () => { + const faviconUrl = useAssetPath('favicon'); + + useEffect(() => { + if (!faviconUrl) return; + RocketChatDesktop?.setFavicon(faviconUrl); + }, [faviconUrl]); +}; diff --git a/apps/meteor/client/views/root/hooks/useDesktopTitle.ts b/apps/meteor/client/views/root/hooks/useDesktopTitle.ts new file mode 100644 index 0000000000000..9083d16a58d6d --- /dev/null +++ b/apps/meteor/client/views/root/hooks/useDesktopTitle.ts @@ -0,0 +1,13 @@ +import { useSetting } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +const { RocketChatDesktop } = window; + +export const useDesktopTitle = () => { + const title = useSetting('Site_Name', 'Rocket.Chat'); + + useEffect(() => { + if (!title) return; + RocketChatDesktop?.setTitle(title); + }, [title]); +}; From e9c68c72003407ef71b190598e11184a15a987bd Mon Sep 17 00:00:00 2001 From: Tasso Date: Mon, 15 Sep 2025 13:33:48 -0300 Subject: [PATCH 3/4] Ensure the url resolver is set --- apps/meteor/client/views/root/hooks/useDesktopFavicon.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts index 3994750fa2cd3..7dc6c23397b38 100644 --- a/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts +++ b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts @@ -1,9 +1,15 @@ -import { useAssetPath } from '@rocket.chat/ui-contexts'; +import { useAbsoluteUrl, useAssetPath } from '@rocket.chat/ui-contexts'; import { useEffect } from 'react'; const { RocketChatDesktop } = window; export const useDesktopFavicon = () => { + const absoluteUrl = useAbsoluteUrl(); + + useEffect(() => { + RocketChatDesktop?.setUrlResolver((relativePath?: string) => absoluteUrl(relativePath ?? '/')); + }, [absoluteUrl]); + const faviconUrl = useAssetPath('favicon'); useEffect(() => { From 4cd768a755c6af82332b5ff5bb99fbb01f1d9d55 Mon Sep 17 00:00:00 2001 From: Tasso Date: Mon, 15 Sep 2025 13:37:32 -0300 Subject: [PATCH 4/4] Accept CoderRabbit suggestion --- apps/meteor/client/views/root/hooks/useDesktopFavicon.ts | 8 ++++---- apps/meteor/client/views/root/hooks/useDesktopTitle.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts index 7dc6c23397b38..0c4fccca28006 100644 --- a/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts +++ b/apps/meteor/client/views/root/hooks/useDesktopFavicon.ts @@ -1,19 +1,19 @@ import { useAbsoluteUrl, useAssetPath } from '@rocket.chat/ui-contexts'; import { useEffect } from 'react'; -const { RocketChatDesktop } = window; - export const useDesktopFavicon = () => { const absoluteUrl = useAbsoluteUrl(); useEffect(() => { - RocketChatDesktop?.setUrlResolver((relativePath?: string) => absoluteUrl(relativePath ?? '/')); + if (typeof window === 'undefined') return; + window.RocketChatDesktop?.setUrlResolver((relativePath?: string) => absoluteUrl(relativePath ?? '/')); }, [absoluteUrl]); const faviconUrl = useAssetPath('favicon'); useEffect(() => { + if (typeof window === 'undefined') return; if (!faviconUrl) return; - RocketChatDesktop?.setFavicon(faviconUrl); + window.RocketChatDesktop?.setFavicon(faviconUrl); }, [faviconUrl]); }; diff --git a/apps/meteor/client/views/root/hooks/useDesktopTitle.ts b/apps/meteor/client/views/root/hooks/useDesktopTitle.ts index 9083d16a58d6d..25129bce0e91c 100644 --- a/apps/meteor/client/views/root/hooks/useDesktopTitle.ts +++ b/apps/meteor/client/views/root/hooks/useDesktopTitle.ts @@ -1,13 +1,12 @@ import { useSetting } from '@rocket.chat/ui-contexts'; import { useEffect } from 'react'; -const { RocketChatDesktop } = window; - export const useDesktopTitle = () => { const title = useSetting('Site_Name', 'Rocket.Chat'); useEffect(() => { + if (typeof window === 'undefined') return; if (!title) return; - RocketChatDesktop?.setTitle(title); + window.RocketChatDesktop?.setTitle(title); }, [title]); };