Skip to content

Conversation

@tassoevan
Copy link
Contributor

@tassoevan tassoevan commented Sep 11, 2025

Proposed changes (including videos or screenshots)

It introduces a fake module mimicking /app/settings/client/index.ts since the desktop app references it directly. Moreover, it handles some desktop's observation of server settings (if available) by itself instead of relying on unsafe injected code.

Issue(s)

ARCH-1806
Caused by #36844

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • New Features

    • Desktop app syncs window title with site name.
    • Desktop app updates favicon to match server branding.
    • Desktop window resolves app asset URLs for correct resource loading.
  • Refactor

    • Consolidated desktop startup injection into a single runtime entry point, replacing the previous runtime patching approach for desktop-specific behavior.

@tassoevan tassoevan added this to the 7.11.0 milestone Sep 11, 2025
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 11, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Sep 11, 2025

⚠️ No Changeset found

Latest commit: ee9395a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

Replaces the Desktop startup stub: removes fakeUserPresence, adds desktopInjection to patch window.require for desktop-only modules, and adds two React hooks wired into AppLayout to sync favicon and window title with Rocket.Chat Desktop (when present).

Changes

Cohort / File(s) Summary
Startup entry
apps/meteor/client/main.ts
Swap startup import to ./startup/desktopInjection (replaces previous fakeUserPresence import).
Desktop require interception
apps/meteor/client/startup/desktopInjection.ts
New desktop-only startup script that wraps window.require to return stubs for meteor/rocketchat:user-presence and /app/settings/client/index.ts, using PublicSettings.use for settings access; active only when window.RocketChatDesktop is present.
Removed legacy stub
apps/meteor/client/startup/fakeUserPresence.ts
Deleted former Desktop-only user-presence stub and its window.require monkey-patch.
AppLayout wiring
apps/meteor/client/views/root/AppLayout.tsx
Import and invoke useDesktopFavicon() and useDesktopTitle() within AppLayout lifecycle.
New desktop hooks
apps/meteor/client/views/root/hooks/*
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts, apps/meteor/client/views/root/hooks/useDesktopTitle.ts
useDesktopFavicon: registers URL resolver and sets favicon via RocketChatDesktop.setFavicon; useDesktopTitle: reads Site_Name and calls RocketChatDesktop.setTitle when available.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Win as window
  participant DI as desktopInjection
  participant Req as window.require (wrapped)
  participant Orig as Original require

  rect rgba(200,220,255,0.18)
  note over Win,DI: Desktop context only
  Win->>DI: load desktopInjection
  DI->>Win: save original require
  DI->>Win: replace window.require with wrapper
  end

  Win->>Req: require('meteor/rocketchat:user-presence')
  alt id matches stub
    Req-->>Win: return fakeUserPresenceModule
  else other id
    Req->>Orig: delegate to original require
    Orig-->>Req: module
    Req-->>Win: module
  end
Loading
sequenceDiagram
  autonumber
  participant App as AppLayout
  participant F as useDesktopFavicon
  participant T as useDesktopTitle
  participant RCD as RocketChatDesktop

  App->>F: invoke hook
  F->>F: resolve absolute favicon URL
  alt Desktop present
    F->>RCD: setFavicon(url)
  end

  App->>T: invoke hook
  T->>T: read Site_Name setting
  alt Desktop present and title set
    T->>RCD: setTitle(title)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • aleksandernsilva
  • MartinSchoeler

Poem

I tap my paws on desktop glass,
Stubbing modules as they pass.
A title gleams, a favicon bright —
Small hops keep windows looking right.
Hooray for tidy startup light! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "regression(desktop-app): Moved settings module" is concise, highlights the regression and desktop context, and references the settings-module change described in the PR objectives (introducing a settings-related change for the desktop app). The verb "Moved" is slightly imprecise because the changes add a shim/fake settings module rather than physically relocating code, but the title still communicates the primary intent and is adequate for history scanning.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch regression/settings-desktop

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9c68c7 and 4cd768a.

📒 Files selected for processing (2)
  • apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1 hunks)
  • apps/meteor/client/views/root/hooks/useDesktopTitle.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/meteor/client/views/root/hooks/useDesktopTitle.ts
  • apps/meteor/client/views/root/hooks/useDesktopFavicon.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: Builds matrix rust bindings against alpine

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 40.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.59%. Comparing base (1c6ee55) to head (ee9395a).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36914      +/-   ##
===========================================
+ Coverage    66.58%   66.59%   +0.01%     
===========================================
  Files         3344     3346       +2     
  Lines       114639   114661      +22     
  Branches     21092    21103      +11     
===========================================
+ Hits         76329    76356      +27     
+ Misses       35623    35619       -4     
+ Partials      2687     2686       -1     
Flag Coverage Δ
e2e 57.79% <40.00%> (+<0.01%) ⬆️
unit 71.27% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tassoevan tassoevan force-pushed the regression/settings-desktop branch from c88b6cc to 79240f3 Compare September 11, 2025 05:58
@tassoevan tassoevan marked this pull request as ready for review September 11, 2025 14:44
@tassoevan tassoevan requested a review from a team as a code owner September 11, 2025 14:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
apps/meteor/client/startup/desktopInjection.ts (2)

20-31: Preserve require signature, add guard, and keep compatibility with variant IDs.

Wrap with a typeof guard, forward all args, and accept common path variants for the settings module.

-	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);
+	if (typeof window.require === 'function') {
+		const originalRequire = window.require;
+		window.require = Object.assign(
+			(id: string, ...args: unknown[]) => {
+				if (id === 'meteor/rocketchat:user-presence') {
+					return fakeUserPresenceModule;
+				}
+				if (
+					id === '/app/settings/client/index.ts' ||
+					id === '/app/settings/client/index.js' ||
+					id === '/app/settings/client'
+				) {
+					return fakeSettingsModule;
+				}
+				// @ts-expect-error forward extra args if present
+				return originalRequire(id, ...args);
+			},
+			originalRequire,
+		);
+	}

6-18: Make stubs immutable to avoid accidental mutation by consumers.

Freeze the stub objects; safer in case downstream code tries to mutate them.

-	const fakeUserPresenceModule = {
+	const fakeUserPresenceModule = Object.freeze({
 		UserPresence: {
 			awayTime: undefined,
 			start: () => undefined,
 		},
-	};
+	});
@@
-	const fakeSettingsModule = {
+	const fakeSettingsModule = Object.freeze({
 		settings: {
 			get: (settingId: string) => watch(PublicSettings.use, (state) => state.get(settingId)?.value),
 		},
-	};
+	});
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1)

4-12: Same: move window access into the hook to avoid module-scope globals.

Keeps it import-safe and consistent with useDesktopTitle.

-const { RocketChatDesktop } = window;
-
 export const useDesktopFavicon = () => {
 	const faviconUrl = useAssetPath('favicon');

 	useEffect(() => {
 		if (!faviconUrl) return;
-		RocketChatDesktop?.setFavicon(faviconUrl);
+		(window as any).RocketChatDesktop?.setFavicon(faviconUrl);
 	}, [faviconUrl]);
 };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e82cfaa and 79240f3.

📒 Files selected for processing (6)
  • apps/meteor/client/main.ts (1 hunks)
  • apps/meteor/client/startup/desktopInjection.ts (1 hunks)
  • apps/meteor/client/startup/fakeUserPresence.ts (0 hunks)
  • apps/meteor/client/views/root/AppLayout.tsx (2 hunks)
  • apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1 hunks)
  • apps/meteor/client/views/root/hooks/useDesktopTitle.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/meteor/client/startup/fakeUserPresence.ts
🧰 Additional context used
🧬 Code graph analysis (3)
apps/meteor/client/views/root/hooks/useDesktopTitle.ts (1)
packages/ui-contexts/src/index.ts (1)
  • useSetting (69-69)
apps/meteor/client/views/root/AppLayout.tsx (2)
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1)
  • useDesktopFavicon (6-13)
apps/meteor/client/views/root/hooks/useDesktopTitle.ts (1)
  • useDesktopTitle (6-13)
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1)
packages/ui-contexts/src/index.ts (1)
  • useAssetPath (22-22)
🔇 Additional comments (4)
apps/meteor/client/startup/desktopInjection.ts (2)

4-4: Scope guard looks good.

Patching only when window.RocketChatDesktop exists keeps web builds untouched.


14-18: Confirm Desktop settings.get contract — manual verification required

Automated search returned only server-side uses of settings.get and no Desktop/client consumers; cannot confirm whether Desktop expects a reactive accessor, an observable/subscribe API, or a plain value — verify the Desktop/Electron callers of settings.get and confirm the exact return shape they use (callable getter vs. immediate value vs. subscription).
Location: apps/meteor/client/startup/desktopInjection.ts (fakeSettingsModule.settings.get uses watch(PublicSettings.use, state => state.get(settingId)?.value)).

apps/meteor/client/main.ts (1)

3-3: Switch to new desktop startup is correct and early enough.

Importing ./startup/desktopInjection before the dynamic chain ensures the require hook is in place.

apps/meteor/client/views/root/AppLayout.tsx (1)

15-16: Desktop hooks integration looks safe.

Hooks are side-effect only and no-ops when Desktop API is absent.

Also applies to: 70-71

jeanfbrito
jeanfbrito previously approved these changes Sep 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1)

9-11: Consider cleanup for setUrlResolver (HMR/unmount hygiene).

If the Desktop API supports resetting/restoring the resolver, add a cleanup to avoid leaking a stale resolver across hot reloads or unmounts.

Can you confirm whether setUrlResolver returns the previous resolver or accepts undefined/null to clear? If yes, we can add a cleanup in this effect.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79240f3 and e9c68c7.

📒 Files selected for processing (6)
  • apps/meteor/client/main.ts (1 hunks)
  • apps/meteor/client/startup/desktopInjection.ts (1 hunks)
  • apps/meteor/client/startup/fakeUserPresence.ts (0 hunks)
  • apps/meteor/client/views/root/AppLayout.tsx (2 hunks)
  • apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1 hunks)
  • apps/meteor/client/views/root/hooks/useDesktopTitle.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/meteor/client/startup/fakeUserPresence.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/meteor/client/views/root/hooks/useDesktopTitle.ts
  • apps/meteor/client/main.ts
  • apps/meteor/client/startup/desktopInjection.ts
  • apps/meteor/client/views/root/AppLayout.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (1)
packages/ui-contexts/src/index.ts (2)
  • useAbsoluteUrl (20-20)
  • useAssetPath (22-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: Builds matrix rust bindings against alpine
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (2)
apps/meteor/client/views/root/hooks/useDesktopFavicon.ts (2)

9-18: Good effect ordering.

Registering the URL resolver before setting the favicon ensures resolver availability on mount. Nice.


1-2: No action required — RocketChatDesktop already declared

Ambient declaration exists at apps/meteor/client/definitions/global.d.ts (imports IRocketChatDesktop from @rocket.chat/desktop-api); do not add a new types file.

Copy link
Contributor

@jeanfbrito jeanfbrito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Sep 15, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 15, 2025
@kodiakhq kodiakhq bot merged commit a09691d into develop Sep 16, 2025
86 of 88 checks passed
@kodiakhq kodiakhq bot deleted the regression/settings-desktop branch September 16, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants