Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/openecraft-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions crates/openecraft-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,4 +19,5 @@ pub mod logos;
pub mod nav;
pub mod part_editor;
pub mod portal;
pub mod theme;
pub mod view_cube;
97 changes: 97 additions & 0 deletions crates/openecraft-ui/src/theme.rs
Original file line number Diff line number Diff line change
@@ -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<u32>, 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<Proxy<'static>> {
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<u32> {
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<u32> {
match value {
Value::U32(n) => Some(*n),
Value::Value(inner) => scheme(inner),
_ => None,
}
}
}

#[cfg(test)]
mod tests;
42 changes: 42 additions & 0 deletions crates/openecraft-ui/src/theme/tests.rs
Original file line number Diff line number Diff line change
@@ -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);
}
10 changes: 7 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bash installer/linux/build.sh flatpak snap # sandboxed packages
| --- | --- | --- | --- |
| Debian, Ubuntu | `openecraft_<version>_amd64.deb` | `sudo apt install ./openecraft_*.deb` | `dpkg-dev` |
| Fedora, RHEL, openSUSE | `openecraft-<version>-1.x86_64.rpm` | `sudo dnf install ./openecraft-*.rpm` | `rpmbuild` |
| Any distribution | `OpenECraft-<version>-x86_64.AppImage` | `chmod +x`, start it | Debian or Ubuntu, `patchelf`, `appimagetool` and its runtime (downloaded, checksums verified) |
| Any distribution | `OpenECraft-<version>-x86_64.AppImage` | `chmod +x`, start it | Debian or Ubuntu, `patchelf`, `zsync`, `appimagetool` and its runtime (downloaded, checksums verified) |
| Any distribution | `OpenECraft-<version>-x86_64.flatpak` | `flatpak install --user OpenECraft-*.flatpak` | `flatpak-builder` |
| Any distribution | `openecraft_<version>_amd64.snap` | `sudo snap install --dangerous openecraft_*.snap` | `snapcraft` |
| Any distribution | `OpenECraft-<version>-linux-x86_64.tar.gz` | `./install.sh` (to `~/.local`) | `tar` |
Expand All @@ -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-<version>-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 `<release>` in the metainfo file.

Expand Down Expand Up @@ -118,7 +122,7 @@ it carries on without a message. A newer release is downloaded, checked against
| Installation | Update |
| --- | --- |
| Windows setup | `OpenECraft-<version>-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 |

Expand Down
7 changes: 5 additions & 2 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ date), and the versions of the tools are pinned. Raise them together:
| File | Built by |
| --- | --- |
| `OpenECraft-<version>-setup.exe` | `installer/windows/build.ps1` |
| `openecraft_<version>_amd64.deb`, `openecraft-<version>-1.x86_64.rpm`, `OpenECraft-<version>-x86_64.AppImage`, `OpenECraft-<version>-linux-x86_64.tar.gz` | `installer/linux/build.sh` |
| `openecraft_<version>_amd64.deb`, `openecraft-<version>-1.x86_64.rpm`, `OpenECraft-<version>-x86_64.AppImage` (and its `.zsync`), `OpenECraft-<version>-linux-x86_64.tar.gz` | `installer/linux/build.sh` |
| `OpenECraft-<version>-x86_64.flatpak`, `openecraft_<version>_amd64.snap` | `installer/linux/build.sh flatpak snap` |
| `OpenECraft-<version>-macos.dmg` | `installer/macos/build.sh` |
| `OpenECraft-<version>-web.zip`, `OpenECraft-Parts-Manager-<version>-web.zip` | `trunk build --release` |
Expand All @@ -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|<owner>|<repo>|latest|OpenECraft-*-x86_64.AppImage.zsync`, set by
`build_appimage`), so the AppImage keeps its name pattern and its `.zsync` file.

## Licenses

Expand Down
21 changes: 17 additions & 4 deletions installer/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
# rpm rpmbuild (dnf install rpm-build, apt install rpm)
# appimage Debian or Ubuntu (dpkg-query), patchelf, appimagetool (APPIMAGETOOL=<path>,
# 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=<string> 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)
#
Expand Down Expand Up @@ -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.
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions openecraft/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ impl App {
break;
}
}
openecraft_ui::theme::follow_system(&cc.egui_ctx);
let mut prj: Option<Project> = None;
let mut file_name = None;
let mut parts_db: Option<PartsDb> = None;
Expand Down
1 change: 1 addition & 0 deletions parts-manager/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl ManagerApp {
let mut client = ServerClient::default();
openecraft_i18n::init(cc.storage.and_then(|s| eframe::get_value::<String>(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::<String>(s, URL_KEY)) {
client.url = url;
}
Expand Down