fix(gui): avoid RefCell panic when applying theme on OS appearance change#337
Conversation
…ange `apply_from_settings` queried `cx.window_appearance()`, which on Linux routes through the platform client's `RefCell` (`with_common`). It is called from the window-appearance observer, and gpui fires that observer from inside its xdg-desktop-portal handler while that same `RefCell` is already mutably borrowed. Re-entering it there panics with "RefCell already borrowed" on the wayland (and x11) backend, crashing the GUI on launch when the portal reports the initial colour scheme. Read the OS appearance from the `Window` already in hand instead — a borrow-free field access (`Window::appearance()`) — and only fall back to the platform query when no window is available (a settings edit, which never runs inside the portal borrow). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR changes how the GUI reads OS appearance while applying themes.
Confidence Score: 5/5This looks safe to merge after checking the System theme fallback behavior.
crates/openlogi-gui/src/theme.rs Important Files Changed
Reviews (1): Last reviewed commit: "fix(gui): avoid RefCell panic when apply..." | Re-trigger Greptile |
| let os_appearance = window | ||
| .as_ref() | ||
| .map_or_else(|| cx.window_appearance(), |w| w.appearance()); |
There was a problem hiding this comment.
Window Appearance May Be Stale
When an existing window is passed while the user preference is System, this now resolves the theme from w.appearance() instead of the platform appearance. If that window value is a cached or forced per-window appearance after switching from Light or Dark back to System, the System branch can keep applying the old mode instead of following the OS.
|
Thanks for the review! On the P2 "Window Appearance May Be Stale" — I believe it's a false positive: the
Net: no path resolves |
Problem
openlogi-guipanics on launch on Linux (both Wayland and X11) with:(equivalently
x11/client.rs:1529on the X11 backend). The CLI is unaffected — only the GUI crashes, immediately, on essentially every launch. Reproduced against the shippedv0.6.18build (gpui reveb2223c).Root cause
theme::apply_from_settingsreads the OS appearance viacx.window_appearance(). On Linux that routes through the platform client'sRefCell:apply_from_settingsis invoked from the window-appearance observer wired up inopen_main_window(main.rs). gpui fires that observer from inside its xdg-desktop-portal handler, which holds the platform client'sRefCellmutably borrowed across the dispatch:So when the portal reports the initial colour scheme at startup, the observer re-enters the platform via
cx.window_appearance()while the sameRefCellis already borrowed → panic. (Deferring the work doesn't help: gpui flushes the deferred effect before that borrow is released.)This almost certainly never surfaced on macOS, where appearance dispatch doesn't hold a
RefCellacross the callback.Fix
Read the OS appearance from the
Windowalready in hand — a borrow-free field access (Window::appearance()) — instead of querying the platform. The platform query (cx.window_appearance()) is kept only for the no-window case (a live settings edit), which never runs inside the portal borrow.Verification
v0.6.18gpui reveb2223c) compiles clean;cargo clippy -p openlogi-guiis clean.🤖 Generated with Claude Code