Skip to content

fix(browser): persist theme setting by checking system theme before reset#647

Open
Vaidik Bajpai (vaidik-bajpai) wants to merge 1 commit intobrowseros-ai:mainfrom
vaidik-bajpai:fix/theme-persistence
Open

fix(browser): persist theme setting by checking system theme before reset#647
Vaidik Bajpai (vaidik-bajpai) wants to merge 1 commit intobrowseros-ai:mainfrom
vaidik-bajpai:fix/theme-persistence

Conversation

@vaidik-bajpai
Copy link
Copy Markdown

This PR fixes this issue where the user's theme selection (specifically "Use GTK" on Linux) would not persist after restarting the browser.

The Problem: The SyncDefaultTheme function was executing on every startup and overwriting the theme with the "BrowserOS Blue" tonal spot if it found the kUserColor preference at its default value. When using GTK, kUserColor is indeed default, causing the reset.

The Fix: Added a guard clause to SyncDefaultTheme in browseros_prefs.cc that check if ::prefs::kUsesSystemTheme is enabled. If true, the function returns early, preserving the user's system theme selection.

…eset

Checks ::prefs::kUsesSystemTheme in SyncDefaultTheme to avoid
overwriting custom/system themes (like GTK on Linux) on browser
startup. This fixes an issue where the theme would reset to
BrowserOS default after relaunch.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 4, 2026

All contributors have signed the CLA. Thank you!
Posted by the CLA Assistant Lite bot.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 4, 2026

Greptile Summary

This PR fixes a theme persistence bug where selecting "Use GTK" (system theme) on Linux would be reset to the BrowserOS default theme on every browser restart. The fix adds a guard clause to SyncDefaultTheme in browseros_prefs.cc that checks ::prefs::kUsesSystemTheme and returns early if the user has a system theme active.

  • Root cause correctly identified: When kUserColor is at its default value (which it is when using GTK), SyncDefaultTheme was unconditionally overwriting it with the BrowserOS blue tonal spot.
  • Fix is logically correct for Linux: The guard clause correctly short-circuits the function when the system theme preference is set.
  • Platform safety concern: ::prefs::kUsesSystemTheme is a Linux-only Chromium preference. Calling pref_service->GetBoolean() on an unregistered pref is a CHECK failure in debug builds on non-Linux platforms (macOS/Windows). The guard should be wrapped in #if BUILDFLAG(IS_LINUX) or use the safer FindPreference pattern already present in the same function.

Confidence Score: 3/5

Safe to merge on Linux-only builds; potential CHECK failure on non-Linux platforms where kUsesSystemTheme is not registered.

The fix correctly solves the reported GTK theme persistence bug, but the unchecked call to GetBoolean on a potentially unregistered pref (kUsesSystemTheme is Linux-specific) poses a real risk of debug-build crashes or undefined behavior on macOS/Windows if SyncDefaultTheme is called cross-platform.

packages/browseros/chromium_patches/chrome/browser/browseros/core/browseros_prefs.cc — specifically the new guard clause at line 68.

Important Files Changed

Filename Overview
packages/browseros/chromium_patches/chrome/browser/browseros/core/browseros_prefs.cc Adds an early-return guard to SyncDefaultTheme to preserve the GTK/system theme on Linux; guard may crash on non-Linux platforms where kUsesSystemTheme is not registered.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Browser Startup] --> B[SyncDefaultTheme called]
    B --> C{kUsesSystemTheme == true?}
    C -- Yes NEW GUARD --> D[Return early
System theme preserved]
    C -- No --> E{kUserColor at
default value?}
    E -- No --> F[Return
User custom color preserved]
    E -- Yes --> G[Set BrowserOS default theme
SkColor gray + kNeutral variant]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/browseros/chromium_patches/chrome/browser/browseros/core/browseros_prefs.cc
Line: 68-70

Comment:
**Potential crash on non-Linux platforms**

`::prefs::kUsesSystemTheme` is a Linux-specific preference in Chromium. On macOS and Windows, this preference is typically not registered. Calling `pref_service->GetBoolean()` on an unregistered preference is a `CHECK` failure in debug builds and undefined behavior in release builds.

Since `SyncDefaultTheme` appears to be called cross-platform, this guard should be wrapped in a Linux build flag, or a safer `FindPreference` pattern (matching the existing pattern used for `kUserColor` below) should be used:

```suggestion
  // BrowserOS: If the user is using a system theme (GTK on Linux), do not
  // overwrite it with the default BrowserOS value.
#if BUILDFLAG(IS_LINUX)
  if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
    return;
  }
#endif

```

Alternatively, mirror the safer pattern already used in this function:

```cpp
  const PrefService::Preference* system_theme_pref =
      pref_service->FindPreference(::prefs::kUsesSystemTheme);
  if (system_theme_pref && system_theme_pref->GetValue()->GetBool()) {
    return;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(browser): persist theme setting by c..." | Re-trigger Greptile

Comment on lines +68 to +70
+ if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
+ return;
+ }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Potential crash on non-Linux platforms

::prefs::kUsesSystemTheme is a Linux-specific preference in Chromium. On macOS and Windows, this preference is typically not registered. Calling pref_service->GetBoolean() on an unregistered preference is a CHECK failure in debug builds and undefined behavior in release builds.

Since SyncDefaultTheme appears to be called cross-platform, this guard should be wrapped in a Linux build flag, or a safer FindPreference pattern (matching the existing pattern used for kUserColor below) should be used:

Suggested change
+ if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
+ return;
+ }
// BrowserOS: If the user is using a system theme (GTK on Linux), do not
// overwrite it with the default BrowserOS value.
#if BUILDFLAG(IS_LINUX)
if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
return;
}
#endif

Alternatively, mirror the safer pattern already used in this function:

  const PrefService::Preference* system_theme_pref =
      pref_service->FindPreference(::prefs::kUsesSystemTheme);
  if (system_theme_pref && system_theme_pref->GetValue()->GetBool()) {
    return;
  }
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browseros/chromium_patches/chrome/browser/browseros/core/browseros_prefs.cc
Line: 68-70

Comment:
**Potential crash on non-Linux platforms**

`::prefs::kUsesSystemTheme` is a Linux-specific preference in Chromium. On macOS and Windows, this preference is typically not registered. Calling `pref_service->GetBoolean()` on an unregistered preference is a `CHECK` failure in debug builds and undefined behavior in release builds.

Since `SyncDefaultTheme` appears to be called cross-platform, this guard should be wrapped in a Linux build flag, or a safer `FindPreference` pattern (matching the existing pattern used for `kUserColor` below) should be used:

```suggestion
  // BrowserOS: If the user is using a system theme (GTK on Linux), do not
  // overwrite it with the default BrowserOS value.
#if BUILDFLAG(IS_LINUX)
  if (pref_service->GetBoolean(::prefs::kUsesSystemTheme)) {
    return;
  }
#endif

```

Alternatively, mirror the safer pattern already used in this function:

```cpp
  const PrefService::Preference* system_theme_pref =
      pref_service->FindPreference(::prefs::kUsesSystemTheme);
  if (system_theme_pref && system_theme_pref->GetValue()->GetBool()) {
    return;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

@vaidik-bajpai
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@vaidik-bajpai Vaidik Bajpai (vaidik-bajpai) changed the title fix(browser): persist theme setting by checking system theme before r… fix(browser): persist theme setting by checking system theme before reset Apr 4, 2026
@DenysMb
Copy link
Copy Markdown

Vaidik Bajpai (@vaidik-bajpai) Thank you for opening this PR about the issue I opened. Could you please have a look on the comment and fix proposal about the potential crash on non-Linux platforms?
After that, we probably just wait. But, this being a simple fix and a small PR, I don't think it will take long for it to get reviewed after resolving the AI fix proposal comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants