From e6ce5d824c5c2f69d24a723a2b1fefa13209679c Mon Sep 17 00:00:00 2001 From: Nils Schlemminger Date: Sun, 15 Nov 2026 14:23:07 +0100 Subject: [PATCH] Follow the desktop theme on Linux; add AppImage update information The AppImage catalog review found the editor dark on a light desktop and the AppImage without update information. - openecraft-ui `theme`: light fallback for the theme "System"; on Linux, where winit reports no theme, the colour scheme of the settings portal (or a dark GTK_THEME) chooses and changes are followed while running - Editor and parts manager use it at start - build.sh embeds gh-releases-zsync update information and writes the .zsync file next to the AppImage (APPIMAGE_UPDATE_INFO overrides) - CI installs zsync and uploads the .zsync with the Linux packages - Changelog, installation and release docs Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 3 +- CHANGELOG.md | 13 ++++ Cargo.lock | 1 + crates/openecraft-ui/Cargo.toml | 4 + crates/openecraft-ui/src/lib.rs | 2 + crates/openecraft-ui/src/theme.rs | 97 +++++++++++++++++++++++++ crates/openecraft-ui/src/theme/tests.rs | 42 +++++++++++ docs/installation.md | 10 ++- docs/releasing.md | 7 +- installer/linux/build.sh | 21 +++++- openecraft/src/app.rs | 1 + parts-manager/src/app.rs | 1 + 12 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 crates/openecraft-ui/src/theme.rs create mode 100644 crates/openecraft-ui/src/theme/tests.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bad4f06d..a10d0b5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: apt-get update apt-get install -y --no-install-recommends ca-certificates curl git build-essential pkg-config file dpkg-dev rpm \ libxkbcommon-dev libgtk-3-dev libwayland-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev \ - patchelf libxkbcommon-x11-0 libxcursor1 libxi6 + patchelf zsync libxkbcommon-x11-0 libxcursor1 libxi6 - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.97.0 - uses: taiki-e/install-action@v2 @@ -101,6 +101,7 @@ jobs: target/installer/*.deb target/installer/*.rpm target/installer/*.AppImage + target/installer/*.AppImage.zsync target/installer/THIRD-PARTY-LICENSES.html flatpak: diff --git a/CHANGELOG.md b/CHANGELOG.md index d3689920..ddc23ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,19 @@ The notable changes of each OpenECraft release. The section of a version is the text of its GitHub release ([docs/releasing.md](docs/releasing.md)). +## [0.1.3] - unreleased + +- **Light theme on Linux:** with the theme *System* the editor and the parts manager + started dark on Linux, where the window system does not report the desktop's theme. + They now take the colour scheme of the desktop from the settings portal (GNOME, KDE + and others, also in Flatpak and snap) or a dark GTK theme (`GTK_THEME`), follow a + change of it while running and are light without either. A theme chosen in the + settings stays as it is. +- **AppImage updates with AppImageUpdate:** the AppImage carries update information + (`gh-releases-zsync`) and each release has its `.zsync` file, so AppImageUpdate, + Gear Lever and similar tools update it from the latest release, downloading only the + changed parts. The editor's own update keeps working. + ## [0.1.2] - 2026-11-15 - **Website with live demos:** `website/` is a page that presents the project and diff --git a/Cargo.lock b/Cargo.lock index bd38218a..41c10d43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3789,6 +3789,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "zbus", ] [[package]] diff --git a/crates/openecraft-ui/Cargo.toml b/crates/openecraft-ui/Cargo.toml index e9dc1afb..fb81001e 100644 --- a/crates/openecraft-ui/Cargo.toml +++ b/crates/openecraft-ui/Cargo.toml @@ -22,6 +22,10 @@ image = { version = "0.25", default-features = false, features = ["png", "jpeg", # Catalog logos are SVG; text is drawn with egui's own font (no system fonts, also in the browser). resvg = { version = "0.45", default-features = false, features = ["text", "raster-images"] } +# The colour scheme of the desktop (settings portal), see `theme`; also used by egui's accessibility. +[target.'cfg(target_os = "linux")'.dependencies] +zbus = { version = "5.19", default-features = false, features = ["async-io", "blocking-api"] } + [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" diff --git a/crates/openecraft-ui/src/lib.rs b/crates/openecraft-ui/src/lib.rs index ee94be16..fdbc7e04 100644 --- a/crates/openecraft-ui/src/lib.rs +++ b/crates/openecraft-ui/src/lib.rs @@ -7,6 +7,7 @@ //! - [`io`] – file dialogs on desktop, file picker and downloads in the browser //! - [`language`] – language menu (UI texts are translated with `openecraft-i18n`) //! - [`nav`] – zoom and pan of the views by mouse wheel, trackpad and touch screen +//! - [`theme`] – light or dark theme of the desktop where the window system does not report it pub mod client; pub mod faces; @@ -18,4 +19,5 @@ pub mod logos; pub mod nav; pub mod part_editor; pub mod portal; +pub mod theme; pub mod view_cube; diff --git a/crates/openecraft-ui/src/theme.rs b/crates/openecraft-ui/src/theme.rs new file mode 100644 index 00000000..b1e3028d --- /dev/null +++ b/crates/openecraft-ui/src/theme.rs @@ -0,0 +1,97 @@ +//! The light or dark theme of the desktop for the theme setting "System". +//! +//! Windows, macOS and the browser report their theme to egui. On Linux winit reports none +//! (X11, Wayland) and egui would use its fallback, dark. There the colour scheme of the +//! desktop chooses: the setting `org.freedesktop.appearance color-scheme` of the settings +//! portal (GNOME, KDE and others, also in Flatpak and snap), otherwise a GTK theme named +//! dark (`GTK_THEME`). A change of the setting while the program runs is followed. +//! Without either the theme is light. + +/// Makes the theme setting "System" light unless the desktop is set to dark. +pub fn follow_system(ctx: &egui::Context) { + set(ctx, egui::Theme::Light); + #[cfg(target_os = "linux")] + linux::follow(ctx); +} + +fn set(ctx: &egui::Context, theme: egui::Theme) { + if ctx.options(|o| o.fallback_theme) != theme { + ctx.options_mut(|o| o.fallback_theme = theme); + ctx.request_repaint(); + } +} + +/// The theme of the portal's colour scheme (0 no preference, 1 dark, 2 light) or, without +/// a preference, of the GTK theme name (`Adwaita:dark`, `Breeze-Dark`). +pub fn desktop_theme(color_scheme: Option, gtk_theme: Option<&str>) -> egui::Theme { + match color_scheme { + Some(1) => egui::Theme::Dark, + Some(2) => egui::Theme::Light, + _ if gtk_theme.is_some_and(|t| t.to_lowercase().contains("dark")) => egui::Theme::Dark, + _ => egui::Theme::Light, + } +} + +#[cfg(target_os = "linux")] +mod linux { + use std::sync::mpsc; + use std::time::Duration; + use zbus::blocking::{Connection, Proxy}; + use zbus::zvariant::{OwnedValue, Value}; + + const NAMESPACE: &str = "org.freedesktop.appearance"; + const KEY: &str = "color-scheme"; + /// How long the start waits for the portal, so that the first frame has the theme. + const FIRST_ANSWER: Duration = Duration::from_millis(300); + + /// Reads and follows the setting in a thread; a slow portal changes the theme later. + pub fn follow(ctx: &egui::Context) { + let (answered, first) = mpsc::channel(); + let ctx = ctx.clone(); + let spawned = std::thread::Builder::new().name("system theme".into()).spawn(move || { + let gtk_theme = std::env::var("GTK_THEME").ok(); + let theme = |scheme| super::desktop_theme(scheme, gtk_theme.as_deref()); + let portal = portal(); + // Subscribed before reading, so that no change gets lost in between. + let changes = portal.as_ref().and_then(|p| p.receive_signal("SettingChanged").ok()); + super::set(&ctx, theme(portal.as_ref().and_then(read))); + answered.send(()).ok(); + for msg in changes.into_iter().flatten() { + if let Ok((namespace, key, value)) = msg.body().deserialize::<(String, String, OwnedValue)>() { + if namespace == NAMESPACE && key == KEY { + super::set(&ctx, theme(scheme(&value))); + } + } + } + }); + if spawned.is_ok() { + first.recv_timeout(FIRST_ANSWER).ok(); + } + } + + fn portal() -> Option> { + let conn = Connection::session().ok()?; + Proxy::new(&conn, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.Settings").ok() + } + + /// The colour scheme; `Read` for portals older than `ReadOne` (version 2). + fn read(portal: &Proxy<'_>) -> Option { + portal + .call::<_, _, OwnedValue>("ReadOne", &(NAMESPACE, KEY)) + .or_else(|_| portal.call::<_, _, OwnedValue>("Read", &(NAMESPACE, KEY))) + .ok() + .and_then(|v| scheme(&v)) + } + + /// The number in the answer, also inside the extra variant of `Read`. + pub(super) fn scheme(value: &Value<'_>) -> Option { + match value { + Value::U32(n) => Some(*n), + Value::Value(inner) => scheme(inner), + _ => None, + } + } +} + +#[cfg(test)] +mod tests; diff --git a/crates/openecraft-ui/src/theme/tests.rs b/crates/openecraft-ui/src/theme/tests.rs new file mode 100644 index 00000000..c2027d92 --- /dev/null +++ b/crates/openecraft-ui/src/theme/tests.rs @@ -0,0 +1,42 @@ +use super::*; +use egui::Theme::{Dark, Light}; + +#[test] +fn the_portal_setting_chooses() { + assert_eq!(desktop_theme(Some(1), None), Dark); + assert_eq!(desktop_theme(Some(2), None), Light); + // An explicit light scheme wins over a dark GTK theme. + assert_eq!(desktop_theme(Some(2), Some("Adwaita:dark")), Light); +} + +#[test] +fn without_a_preference_the_gtk_theme_chooses() { + assert_eq!(desktop_theme(Some(0), Some("Adwaita:dark")), Dark); + assert_eq!(desktop_theme(None, Some("Breeze-Dark")), Dark); + assert_eq!(desktop_theme(None, Some("Adwaita")), Light); +} + +#[test] +fn light_without_any_setting() { + // The test systems of the AppImage catalog have neither: egui would choose dark. + assert_eq!(desktop_theme(None, None), Light); + assert_eq!(desktop_theme(Some(7), None), Light); +} + +#[test] +fn system_falls_back_to_light() { + let ctx = egui::Context::default(); + assert_eq!(ctx.options(|o| o.fallback_theme), Dark); + set(&ctx, Light); + assert_eq!(ctx.options(|o| o.fallback_theme), Light); + assert_eq!(ctx.theme(), Light); +} + +#[cfg(target_os = "linux")] +#[test] +fn reads_the_scheme_also_inside_a_variant() { + use zbus::zvariant::Value; + assert_eq!(linux::scheme(&Value::U32(1)), Some(1)); + assert_eq!(linux::scheme(&Value::Value(Box::new(Value::U32(2)))), Some(2)); + assert_eq!(linux::scheme(&Value::Str("dark".into())), None); +} diff --git a/docs/installation.md b/docs/installation.md index 6463b678..a14eefc0 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -69,7 +69,7 @@ bash installer/linux/build.sh flatpak snap # sandboxed packages | --- | --- | --- | --- | | Debian, Ubuntu | `openecraft__amd64.deb` | `sudo apt install ./openecraft_*.deb` | `dpkg-dev` | | Fedora, RHEL, openSUSE | `openecraft--1.x86_64.rpm` | `sudo dnf install ./openecraft-*.rpm` | `rpmbuild` | -| Any distribution | `OpenECraft--x86_64.AppImage` | `chmod +x`, start it | Debian or Ubuntu, `patchelf`, `appimagetool` and its runtime (downloaded, checksums verified) | +| Any distribution | `OpenECraft--x86_64.AppImage` | `chmod +x`, start it | Debian or Ubuntu, `patchelf`, `zsync`, `appimagetool` and its runtime (downloaded, checksums verified) | | Any distribution | `OpenECraft--x86_64.flatpak` | `flatpak install --user OpenECraft-*.flatpak` | `flatpak-builder` | | Any distribution | `openecraft__amd64.snap` | `sudo snap install --dangerous openecraft_*.snap` | `snapcraft` | | Any distribution | `OpenECraft--linux-x86_64.tar.gz` | `./install.sh` (to `~/.local`) | `tar` | @@ -83,7 +83,11 @@ push (artifacts `openecraft-linux-packages`, `openecraft-flatpak`, `openecraft-s deb, rpm, AppImage and tar.gz are built on Debian 12 and run with glibc 2.36 or newer. The AppImage carries the window libraries that are not on every system (xkbcommon, Xcursor, Xi: `appimage_libs` in `installer/linux/build.sh`); the build refuses one that -needs another library or a newer glibc than the programs. +needs another library or a newer glibc than the programs. It also carries update +information for AppImageUpdate and similar tools: the latest GitHub release of the +repository that built it (`GITHUB_REPOSITORY`, otherwise `nilres/OpenECraft`), whose +`OpenECraft--x86_64.AppImage.zsync` the build writes next to the AppImage +(`APPIMAGE_UPDATE_INFO` sets other update information, an empty value none). The desktop entries, MIME types and AppStream data (`io.github.nilres.OpenECraft`) are in `installer/linux/`; a new version needs a `` in the metainfo file. @@ -118,7 +122,7 @@ it carries on without a message. A newer release is downloaded, checked against | Installation | Update | | --- | --- | | Windows setup | `OpenECraft--setup.exe` runs silently (`/SILENT`) when the editor is closed, in the folder and with the components of the installation; *Restart and update* starts the editor again afterwards | -| AppImage | the AppImage file is replaced at once; the new version starts next time | +| AppImage | the AppImage file is replaced at once; the new version starts next time (AppImageUpdate and similar tools update it too) | | macOS app | `OpenECraft.app` (and `OpenECraft Parts Manager.app` next to it) are replaced from the disk image at once | | deb, rpm, Flatpak, Snap, tar.gz, own build | the status bar only tells of the new version and links its release page | diff --git a/docs/releasing.md b/docs/releasing.md index b5f70469..0948b807 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -52,7 +52,7 @@ date), and the versions of the tools are pinned. Raise them together: | File | Built by | | --- | --- | | `OpenECraft--setup.exe` | `installer/windows/build.ps1` | -| `openecraft__amd64.deb`, `openecraft--1.x86_64.rpm`, `OpenECraft--x86_64.AppImage`, `OpenECraft--linux-x86_64.tar.gz` | `installer/linux/build.sh` | +| `openecraft__amd64.deb`, `openecraft--1.x86_64.rpm`, `OpenECraft--x86_64.AppImage` (and its `.zsync`), `OpenECraft--linux-x86_64.tar.gz` | `installer/linux/build.sh` | | `OpenECraft--x86_64.flatpak`, `openecraft__amd64.snap` | `installer/linux/build.sh flatpak snap` | | `OpenECraft--macos.dmg` | `installer/macos/build.sh` | | `OpenECraft--web.zip`, `OpenECraft-Parts-Manager--web.zip` | `trunk build --release` | @@ -61,7 +61,10 @@ date), and the versions of the tools are pinned. Raise them together: The editor updates itself from the latest published release (no drafts, no pre-releases): it needs `SHA256SUMS` and the file names above, so keep them when -changing the packages (`openecraft_client::update::Package`). +changing the packages (`openecraft_client::update::Package`). AppImageUpdate and +similar tools do the same with the update information in the AppImage +(`gh-releases-zsync|||latest|OpenECraft-*-x86_64.AppImage.zsync`, set by +`build_appimage`), so the AppImage keeps its name pattern and its `.zsync` file. ## Licenses diff --git a/installer/linux/build.sh b/installer/linux/build.sh index 177e7acf..de35dd86 100755 --- a/installer/linux/build.sh +++ b/installer/linux/build.sh @@ -11,7 +11,11 @@ # rpm rpmbuild (dnf install rpm-build, apt install rpm) # appimage Debian or Ubuntu (dpkg-query), patchelf, appimagetool (APPIMAGETOOL=, # otherwise release 1.9.1 is downloaded) and the AppImage runtime (release -# 20251108, downloaded; both checksums verified) +# 20251108, downloaded; both checksums verified), zsyncmake (apt install zsync) +# for the update information: AppImageUpdate and similar tools update the +# AppImage from the latest GitHub release of GITHUB_REPOSITORY (set in CI, +# otherwise nilres/OpenECraft) with the .zsync file built next to it; +# APPIMAGE_UPDATE_INFO= embeds other update information, an empty one none # flatpak flatpak, flatpak-builder (the runtime is installed from Flathub) # snap snapcraft (SNAPCRAFT="sudo snapcraft" SNAPCRAFT_ARGS=--destructive-mode in CI) # @@ -218,8 +222,12 @@ glibc_needed() { } build_appimage() { - local dir="$work/OpenECraft.AppDir" tool="${APPIMAGETOOL:-}" runtime + local dir="$work/OpenECraft.AppDir" tool="${APPIMAGETOOL:-}" runtime repo="${GITHUB_REPOSITORY:-nilres/OpenECraft}" + local file="$out/OpenECraft-$version-$arch.AppImage" + local update="${APPIMAGE_UPDATE_INFO-gh-releases-zsync|${repo%%/*}|${repo#*/}|latest|OpenECraft-*-$arch.AppImage.zsync}" [ -n "${runtime_sha256[$arch]:-}" ] || die "no AppImage runtime for $arch" + # appimagetool writes the .zsync file only with zsyncmake. + [ -z "$update" ] || need zsyncmake "the update information of the AppImage (apt install zsync)" stage "$dir/usr" bundle_libs "$dir" # The AppImage catalog and appimagetool look for AppStream data by its older name. @@ -235,11 +243,16 @@ build_appimage() { "$tool" "${appimagetool_sha256[$arch]}" chmod +x "$tool" fi + # A relative APPIMAGETOOL path, appimagetool runs in $out. + [[ "$tool" != */* ]] || tool="$(readlink -f "$tool")" runtime="$work/runtime-$runtime_version-$arch" download "https://github.com/AppImage/type2-runtime/releases/download/$runtime_version/runtime-$arch" \ "$runtime" "${runtime_sha256[$arch]}" - # Extract-and-run works without FUSE (containers, CI). - ARCH="$arch" APPIMAGE_EXTRACT_AND_RUN=1 "$tool" --runtime-file "$runtime" "$dir" "$out/OpenECraft-$version-$arch.AppImage" + rm -f "$file" "$file.zsync" + # Extract-and-run works without FUSE (containers, CI). The .zsync file is written to + # the current folder. + (cd "$out" && ARCH="$arch" APPIMAGE_EXTRACT_AND_RUN=1 "$tool" --runtime-file "$runtime" ${update:+-u "$update"} "$dir" "$file") + [ -z "$update" ] || [ -f "$file.zsync" ] || die "appimagetool wrote no $file.zsync" } build_flatpak() { diff --git a/openecraft/src/app.rs b/openecraft/src/app.rs index aa185735..0dbe7f12 100644 --- a/openecraft/src/app.rs +++ b/openecraft/src/app.rs @@ -424,6 +424,7 @@ impl App { break; } } + openecraft_ui::theme::follow_system(&cc.egui_ctx); let mut prj: Option = None; let mut file_name = None; let mut parts_db: Option = None; diff --git a/parts-manager/src/app.rs b/parts-manager/src/app.rs index c66a850c..816c24f9 100644 --- a/parts-manager/src/app.rs +++ b/parts-manager/src/app.rs @@ -90,6 +90,7 @@ impl ManagerApp { let mut client = ServerClient::default(); openecraft_i18n::init(cc.storage.and_then(|s| eframe::get_value::(s, openecraft_ui::language::STORAGE_KEY)).as_deref()); openecraft_ui::fonts::install_system_fallbacks(&cc.egui_ctx); + openecraft_ui::theme::follow_system(&cc.egui_ctx); if let Some(url) = cc.storage.and_then(|s| eframe::get_value::(s, URL_KEY)) { client.url = url; }