From 292c3d00f182a3e749fa9490e5520dc0874f5f79 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sun, 19 Jul 2026 22:20:04 +0200 Subject: [PATCH] fix(desktop): bundle appindicator for CEF tray and guard when missing --- scripts/cef-package.sh | 32 ++++++++++++++++++++++++++++++-- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/src/desktop/tray.rs | 25 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/scripts/cef-package.sh b/scripts/cef-package.sh index 6f4aee710..f68f68ee5 100755 --- a/scripts/cef-package.sh +++ b/scripts/cef-package.sh @@ -38,6 +38,30 @@ stage_runtime() { bash scripts/cef-copy-libs.sh release "$dest" } +# Bundle the system-tray libraries (Tauri's linuxdeploy path normally does this, +# which the CEF build bypasses). Bundle libayatana-appindicator3 plus its +# ayatana/dbusmenu/indicator dependency closure; host libs (gtk, glib, X11, …) +# are left to the system, matching linuxdeploy-plugin-appindicator. +stage_appindicator() { + local dest="$1" main dep + mkdir -p "$dest" + # awk reads to EOF (no early exit) so ldconfig never gets SIGPIPE under pipefail. + main="$(ldconfig -p 2>/dev/null | awk '$1=="libayatana-appindicator3.so.1"{v=$NF} END{print v}')" + [ -n "$main" ] || main="$(find /usr/lib /usr/lib64 /lib -name libayatana-appindicator3.so.1 2>/dev/null | sort | tail -n1)" + if [ -z "$main" ] || [ ! -e "$main" ]; then + echo "warning: libayatana-appindicator3.so.1 not found; tray disabled in the AppImage" >&2 + return 0 + fi + { + echo "$main" + ldd "$main" 2>/dev/null | awk '/=>/ {print $3}' | grep -iE 'ayatana|dbusmenu|indicator|ido' || true + } | sort -u | while read -r dep; do + if [ -e "$dep" ]; then + cp -Lf "$dep" "$dest/$(basename "$dep")" + fi + done +} + write_desktop() { cat > "$1" <<'EOF' [Desktop Entry] @@ -73,13 +97,15 @@ EOF # Stable-named deps only; version-suffixed names break install across releases. DEB_DEPS=(--depends libwebkit2gtk-4.1-0 --depends libgtk-3-0 --depends libnss3 --depends libnspr4 --depends libgbm1 - --depends libdrm2 --depends libxkbcommon0 --depends xdg-utils) + --depends libdrm2 --depends libxkbcommon0 --depends xdg-utils + --depends libayatana-appindicator3-1) (cd "$OUT/deb" && fpm "${COMMON[@]}" -v "$DEB_VERSION" --iteration 1 \ -t deb -a amd64 "${DEB_DEPS[@]}" -C "$PKGROOT" .) RPM_DEPS=(--depends webkit2gtk4.1 --depends gtk3 --depends nss --depends nspr --depends mesa-libgbm --depends libdrm - --depends libxkbcommon --depends xdg-utils) + --depends libxkbcommon --depends xdg-utils + --depends 'libayatana-appindicator3.so.1()(64bit)') (cd "$OUT/rpm" && fpm "${COMMON[@]}" -v "$RPM_VERSION" --iteration "$RPM_ITERATION" \ -t rpm -a x86_64 "${RPM_DEPS[@]}" -C "$PKGROOT" .) else @@ -88,6 +114,7 @@ fi APPDIR="$WORK/Sable.AppDir" stage_runtime "$APPDIR/usr/bin" +stage_appindicator "$APPDIR/usr/bin" # nosuid AppImage mount: drop setuid chrome-sandbox, use the namespace sandbox. rm -f "$APPDIR/usr/bin/chrome-sandbox" write_desktop "$APPDIR/sable.desktop" @@ -95,6 +122,7 @@ cp src-tauri/icons/128x128.png "$APPDIR/sable.png" cat > "$APPDIR/AppRun" <<'EOF' #!/bin/sh HERE="$(dirname "$(readlink -f "$0")")" +export LD_LIBRARY_PATH="$HERE/usr/bin${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" exec "$HERE/usr/bin/sable" "$@" EOF chmod 755 "$APPDIR/AppRun" diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e76927f9b..20f90b9ab 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -5222,6 +5222,7 @@ dependencies = [ "enigo", "gtk", "jni 0.21.1", + "libloading 0.8.9", "log", "objc2", "percent-encoding", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ecfce6067..21ebe5f30 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -85,6 +85,7 @@ gtk = "0.18" [target.'cfg(target_os = "linux")'.dependencies] tauri-runtime-cef = { git = "https://github.com/byeongsu-hong/tauri-runtime-cef", rev = "c215d6e52dd507956d9b8cc868906d690dc477c2", optional = true } cef = { version = "=148.0.0", optional = true } +libloading = "0.8" [target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies] tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "95c1574cf4c2be0f3e7c1d7b8102b2f7b59bcb68", features = [ diff --git a/src-tauri/src/desktop/tray.rs b/src-tauri/src/desktop/tray.rs index 23c097dfb..68a7bcb03 100644 --- a/src-tauri/src/desktop/tray.rs +++ b/src-tauri/src/desktop/tray.rs @@ -246,7 +246,32 @@ fn configure_tray_icon_interactions( builder } +// libappindicator panics (rather than returning an error) when the appindicator +// library is missing, which would crash the whole app. Probe for it first and +// treat its absence as a recoverable tray failure. +#[cfg(target_os = "linux")] +fn appindicator_available() -> bool { + const CANDIDATES: [&str; 4] = [ + "libayatana-appindicator3.so.1", + "libappindicator3.so.1", + "libayatana-appindicator3.so", + "libappindicator3.so", + ]; + CANDIDATES + .iter() + .any(|name| unsafe { libloading::Library::new(name) }.is_ok()) +} + pub fn create_system_tray(app: &AppHandle) -> tauri::Result<()> { + #[cfg(target_os = "linux")] + if !appindicator_available() { + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "appindicator library not found; skipping system tray", + ) + .into()); + } + let show_item = MenuItem::with_id(app, TRAY_MENU_SHOW_ID, "Show", true, None::<&str>)?; let quit_item = MenuItem::with_id(app, TRAY_MENU_QUIT_ID, "Quit", true, None::<&str>)?; let tray_menu = Menu::with_items(app, &[&show_item, &quit_item])?;