mirror of
https://github.com/tobi/disktree.git
synced 2026-11-28 16:00:45 +00:00
app: follow the system's light or dark setting on Windows, GNOME and KDE
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a64a58060d
commit
41328cdc67
@@ -280,8 +280,8 @@ The same program, with Windows' answers to the questions above:
|
||||
them.
|
||||
- **Hidden** still means a name starting with a dot; the hidden attribute is
|
||||
not consulted, so `-H` does not drop `AppData`.
|
||||
- **The theme** is gpui-omarchy's default, since there is no Omarchy theme
|
||||
to follow.
|
||||
- **The theme** follows Windows' light or dark setting, since there is no
|
||||
Omarchy theme to follow. It does on macOS too, and on GNOME and KDE.
|
||||
|
||||
## What it refuses to do
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Light or dark when there is no Omarchy theme to follow.
|
||||
//!
|
||||
//! On Omarchy, gpui-omarchy follows the desktop's theme files. A Mac has none,
|
||||
//! and gpui-omarchy would then stay on its dark default whatever the system
|
||||
//! is set to; there the app follows the system appearance instead, with the
|
||||
//! crate's own dark and light palettes, and switches when it does.
|
||||
//! On Omarchy, gpui-omarchy follows the desktop's theme files. Elsewhere there
|
||||
//! are none, and gpui-omarchy would then stay on its dark default whatever
|
||||
//! the system is set to; there the app follows the system appearance instead,
|
||||
//! with the crate's own dark and light palettes, and switches when it does.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
@@ -11,9 +11,11 @@ use gpui_kit::{App, Window, WindowAppearance};
|
||||
use gpui_omarchy::Theme;
|
||||
|
||||
/// Whether the system appearance, rather than an Omarchy theme, decides the
|
||||
/// colours: on macOS, unless an Omarchy theme is installed there anyway.
|
||||
/// colours: unless an Omarchy theme is installed, on macOS and Windows, and
|
||||
/// on a Linux desktop that states a preference.
|
||||
pub fn follows_system(home: Option<&Path>) -> bool {
|
||||
cfg!(target_os = "macos")
|
||||
let desktop = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default();
|
||||
states_a_preference(&desktop)
|
||||
&& !home.is_some_and(|home| {
|
||||
[".local/state/omarchy/current", ".config/omarchy/current"]
|
||||
.iter()
|
||||
@@ -21,6 +23,18 @@ pub fn follows_system(home: Option<&Path>) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the system has a light or dark setting to follow. macOS and
|
||||
/// Windows always do. On Linux GPUI asks the desktop portal, which reads "no
|
||||
/// preference" as light: a window manager that never sets one would turn
|
||||
/// the app light, so only GNOME and KDE, whose settings do, are followed.
|
||||
fn states_a_preference(desktop: &str) -> bool {
|
||||
cfg!(any(target_os = "macos", windows))
|
||||
|| desktop.split(':').any(|name| {
|
||||
["gnome", "kde", "ubuntu", "unity", "pantheon", "cinnamon"]
|
||||
.contains(&name.to_ascii_lowercase().as_str())
|
||||
})
|
||||
}
|
||||
|
||||
/// Apply the palette for `appearance`. Applying an explicit theme also stops
|
||||
/// gpui-omarchy watching for theme files that are not there.
|
||||
pub fn apply(appearance: WindowAppearance, cx: &mut App) {
|
||||
@@ -41,3 +55,17 @@ pub fn follow(window: &Window) {
|
||||
.observe_window_appearance(|window, cx| apply(window.appearance(), cx))
|
||||
.detach();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_linux_desktop_is_followed_only_if_it_states_a_preference() {
|
||||
let native = cfg!(any(target_os = "macos", windows));
|
||||
assert!(states_a_preference("ubuntu:GNOME"));
|
||||
assert!(states_a_preference("KDE"));
|
||||
assert_eq!(states_a_preference("Hyprland"), native);
|
||||
assert_eq!(states_a_preference(""), native);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user