Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Linux: start without a tray when libayatana is missing, ship it again in the AppImage (GH #204)

purple2be1049149cc
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index fc1d191e..ec867034 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -937,6 +937,16 @@ jobs:
[ -e "$link" ] || { echo "FAIL: $(basename "$link") -> $target does not resolve inside the AppImage (GH #191)" >&2; exit 1; }
done
echo "OK: .DirIcon and the .desktop link are relative and resolve (GH #191)"
+ # GH #204: 3.0.8 shipped without the tray library, and on a system
+ # without it the app aborted at start. @tauri-apps/cli adds it only
+ # when it sees `tray-icon` on the FIRST `tauri` entry of Cargo.toml,
+ # and since 3.0.8 that sits in the desktop target block, so
+ # tauri.linux.conf.json now names it. It has to be here, and so do
+ # the libraries it needs that linuxdeploy pulls in after it.
+ for lib in libayatana-appindicator3.so.1 libayatana-indicator3.so.7 libayatana-ido3-0.4.so.0 libdbusmenu-glib.so.4 libdbusmenu-gtk3.so.4; do
+ [ -e "$workdir/squashfs-root/usr/lib/$lib" ] || { echo "FAIL: usr/lib/$lib is missing from the built AppImage; without it the tray cannot be built (GH #204)" >&2; exit 1; }
+ done
+ echo "OK: the AppImage carries libayatana-appindicator3 and what it needs (GH #204)"
# SKEPTIKER-LINUX-WEB-K1.md: the AppImage check above proves nothing
# about the .deb, a completely different bundler (dpkg-deb, not
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 83f5d4ed..fccef721 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -50,6 +50,7 @@ mod shown_path;
mod e2e_remote;
mod runtime_root;
mod storage_move;
+mod system_tray;
mod state;
// Test-only OS helpers (a shell, a sleeper, "is this pid alive"), shared by
// the process tests in state.rs, commands/engine.rs and commands/bg_tasks.rs
@@ -1344,50 +1345,56 @@ pub fn run() {
#[cfg(desktop)]
let menu = Menu::with_items(app, &[&show, &quit])?;
- #[cfg(desktop)]
- let tray_icon = Image::from_path("icons/icon.png")
- .or_else(|_| Image::from_path("icons/32x32.png"))
- .unwrap_or_else(|_| Image::from_bytes(include_bytes!("../icons/32x32.png")).expect("embedded icon"));
-
- // On a Mac the menu bar gets a template image (see
- // `menu_bar_template_rgba`), built from the embedded icon so it
- // does not depend on the working directory of a bundled app.
- #[cfg(target_os = "macos")]
- let tray_icon = {
- let source = Image::from_bytes(include_bytes!("../icons/128x128.png")).expect("embedded icon");
- let _ = tray_icon;
- Image::new_owned(menu_bar_template_rgba(source.rgba()), source.width(), source.height())
- };
- #[cfg(desktop)]
- let tray = TrayIconBuilder::new()
- .icon(tray_icon)
- .tooltip("LU");
- #[cfg(target_os = "macos")]
- let tray = tray.icon_as_template(true);
- #[cfg(desktop)]
- tray
- .menu(&menu)
- .on_menu_event(|app, event| {
- match event.id().as_ref() {
- "show" => onboarding_window::bring_to_front(app),
- "quit" => {
- // Tauri's AppState Drop doesn't fire reliably on
- // Windows after `app.exit(0)` — run the explicit
- // subprocess shutdown here so tray Quit doesn't
- // leak Ollama / ComfyUI (a user V/b, v2.4.9).
- let state = app.state::<AppState>();
- state.shutdown_subprocesses();
- app.exit(0);
+ // GH #204: on Linux the tray needs libayatana-appindicator, and
+ // building it without that library aborts the whole app. Without
+ // it LU starts with no tray, and the close button quits.
+ #[cfg(desktop)]
+ let tray_present = system_tray::system_tray_available();
+
+ #[cfg(desktop)]
+ if tray_present {
+ let tray_icon = Image::from_path("icons/icon.png")
+ .or_else(|_| Image::from_path("icons/32x32.png"))
+ .unwrap_or_else(|_| Image::from_bytes(include_bytes!("../icons/32x32.png")).expect("embedded icon"));
+
+ // On a Mac the menu bar gets a template image (see
+ // `menu_bar_template_rgba`), built from the embedded icon so it
+ // does not depend on the working directory of a bundled app.
+ #[cfg(target_os = "macos")]
+ let tray_icon = {
+ let source = Image::from_bytes(include_bytes!("../icons/128x128.png")).expect("embedded icon");
+ let _ = tray_icon;
+ Image::new_owned(menu_bar_template_rgba(source.rgba()), source.width(), source.height())
+ };
+ let tray = TrayIconBuilder::new()
+ .icon(tray_icon)
+ .tooltip("LU");
+ #[cfg(target_os = "macos")]
+ let tray = tray.icon_as_template(true);
+ tray
+ .menu(&menu)
+ .on_menu_event(|app, event| {
+ match event.id().as_ref() {
+ "show" => onboarding_window::bring_to_front(app),
+ "quit" => {
+ // Tauri's AppState Drop doesn't fire reliably on
+ // Windows after `app.exit(0)` — run the explicit
+ // subprocess shutdown here so tray Quit doesn't
+ // leak Ollama / ComfyUI (a user V/b, v2.4.9).
+ let state = app.state::<AppState>();
+ state.shutdown_subprocesses();
+ app.exit(0);
+ }
+ _ => {}
}
- _ => {}
- }
- })
- .on_tray_icon_event(|tray, event| {
- if let tauri::tray::TrayIconEvent::DoubleClick { .. } = event {
- onboarding_window::bring_to_front(tray.app_handle());
- }
- })
- .build(app)?;
+ })
+ .on_tray_icon_event(|tray, event| {
+ if let tauri::tray::TrayIconEvent::DoubleClick { .. } = event {
+ onboarding_window::bring_to_front(tray.app_handle());
+ }
+ })
+ .build(app)?;
+ }
// ─── Close → hide to tray instead of quit ───
#[cfg(desktop)]
@@ -1397,6 +1404,14 @@ pub fn run() {
window.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
api.prevent_close();
+ // No tray (GH #204): a hidden window could never come
+ // back, so the close button is the Quit item.
+ if !system_tray::close_hides_to_tray(tray_present) {
+ let app = w.app_handle();
+ app.state::<AppState>().shutdown_subprocesses();
+ app.exit(0);
+ return;
+ }
// The hidden webview stays fully alive — read-aloud
// would keep talking and a running dictation would
// keep the mic hot behind a window the user believes
@@ -1764,6 +1779,33 @@ mod tests {
);
}
+ #[test]
+ fn the_tray_is_only_built_when_its_library_loads() {
+ // GH #204: 3.0.8 built the tray unconditionally, and on a Linux
+ // without libayatana-appindicator that aborted the app at start. The
+ // probe in `system_tray` is worth nothing unless the build sits
+ // behind it and the close button knows there may be no tray.
+ let src = include_str!("lib.rs");
+ let builder = src
+ .find("let tray = TrayIconBuilder::new()")
+ .expect("tray builder should exist");
+ let gate = src[..builder]
+ .rfind("if tray_present {")
+ .expect("the tray build must sit inside `if tray_present`");
+ let probe = src[..gate]
+ .rfind("system_tray::system_tray_available()")
+ .expect("tray_present must come from the library probe");
+ assert!(probe < gate && gate < builder);
+ let close = src
+ .find("if let tauri::WindowEvent::CloseRequested { api, .. } = event {")
+ .expect("close handler should exist");
+ let hide = src.find("let _ = w.hide();").expect("hide call should exist");
+ assert!(
+ src[close..hide].contains("system_tray::close_hides_to_tray(tray_present)"),
+ "without a tray the close button must not hide the window"
+ );
+ }
+
#[test]
fn hidden_offload_grace_is_a_real_wait_and_not_a_coffee_break() {
// A zero grace would unload on every stray hide, and a very long one
diff --git a/src-tauri/src/system_tray.rs b/src-tauri/src/system_tray.rs
new file mode 100644
index 00000000..ba5c0975
--- /dev/null
+++ b/src-tauri/src/system_tray.rs
@@ -0,0 +1,126 @@
+// Is there a system tray this process can build, and what does the close
+// button do when there is none?
+//
+// GH #204 (3.0.8, CachyOS): the AppImage aborted at start with
+// "Failed to load ayatana-appindicator3 or appindicator3 dynamic library".
+// On Linux the tray is an AppIndicator, and `libappindicator-sys` 0.9 loads
+// that library with `dlopen` inside a lazy static and `panic!`s when neither
+// name loads. The release profile has `panic = "abort"`, so no catch_unwind
+// can stop it: the only way to start without a tray is to not build one.
+// This module asks the dynamic loader the same question first.
+
+/// The names `libappindicator-sys` 0.9.0 tries, in its order (src/lib.rs, the
+/// `LIB` static; the `.so` fallbacks sit behind its `backcompat` feature,
+/// which `tray-icon` 0.21 does not turn on). If none of these loads here, the
+/// crate panics when the tray is built.
+pub(crate) const APPINDICATOR_LIBS: &[&str] =
+ &["libayatana-appindicator3.so.1", "libappindicator3.so.1"];
+
+/// The line a user reads in the terminal when LU started without a tray.
+pub(crate) const NO_TRAY_LOG: &str = "[Tray] No system tray: neither libayatana-appindicator3.so.1 \
+ nor libappindicator3.so.1 could be loaded. LU runs without a tray icon, and closing the \
+ window quits LU. Install libayatana-appindicator (Arch: libayatana-appindicator, \
+ Debian/Ubuntu: libayatana-appindicator3-1, Fedora: libayatana-appindicator-gtk3) to get it back.";
+
+/// Can the tray be built? `loads` answers whether one library name loads,
+/// injected so every branch runs on a Mac too.
+pub(crate) fn tray_available(linux: bool, loads: impl Fn(&str) -> bool) -> bool {
+ !linux || APPINDICATOR_LIBS.iter().any(|name| loads(name))
+}
+
+/// Does the close button hide the window to the tray? Only when there is a
+/// tray to bring it back from. Without one a hidden window could never be
+/// shown again and the process would sit there with the GPU still full, so
+/// the button quits instead, through the same shutdown as the tray's Quit.
+pub(crate) fn close_hides_to_tray(tray_present: bool) -> bool {
+ tray_present
+}
+
+/// The real loader, the same call `libloading` makes for the crate (dlopen
+/// with RTLD_NOW). The handle is closed again; the crate opens its own.
+#[cfg(target_os = "linux")]
+pub(crate) fn dlopen_loads(name: &str) -> bool {
+ let Ok(c) = std::ffi::CString::new(name) else {
+ return false;
+ };
+ // SAFETY: a plain dlopen/dlclose pair on a NUL-terminated name. The
+ // library's constructors run, which the tray build would do anyway.
+ unsafe {
+ let handle = libc::dlopen(c.as_ptr(), libc::RTLD_NOW | libc::RTLD_LOCAL);
+ if handle.is_null() {
+ return false;
+ }
+ libc::dlclose(handle);
+ }
+ true
+}
+
+/// The answer for this process.
+#[cfg(desktop)]
+pub(crate) fn system_tray_available() -> bool {
+ #[cfg(target_os = "linux")]
+ let available = tray_available(true, dlopen_loads);
+ #[cfg(not(target_os = "linux"))]
+ let available = tray_available(false, |_| true);
+ if !available {
+ // println! as well as tracing, like the Wayland lines: a user who
+ // starts the AppImage from a terminal must see why there is no icon.
+ println!("{NO_TRAY_LOG}");
+ tracing::warn!(target: "tray", "{NO_TRAY_LOG}");
+ }
+ available
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn no_appindicator_library_means_no_tray_on_linux() {
+ assert!(!tray_available(true, |_| false));
+ }
+
+ #[test]
+ fn either_appindicator_name_is_enough() {
+ assert!(tray_available(true, |n| n == "libayatana-appindicator3.so.1"));
+ assert!(tray_available(true, |n| n == "libappindicator3.so.1"));
+ }
+
+ #[test]
+ fn the_probe_asks_for_exactly_the_names_the_crate_loads() {
+ // A `.so` without the ABI suffix would make the probe say yes while
+ // libappindicator-sys (no backcompat feature) still panics.
+ assert!(!tray_available(true, |n| n == "libayatana-appindicator3.so"));
+ assert!(!tray_available(true, |n| n == "libappindicator3.so"));
+ }
+
+ #[test]
+ fn mac_and_windows_always_have_a_tray() {
+ assert!(tray_available(false, |_| false));
+ }
+
+ #[test]
+ fn without_a_tray_the_close_button_quits() {
+ assert!(!close_hides_to_tray(false));
+ assert!(close_hides_to_tray(true));
+ }
+
+ #[cfg(target_os = "linux")]
+ #[test]
+ fn the_real_loader_says_no_to_a_library_that_does_not_exist() {
+ assert!(!dlopen_loads("liblu-p10-does-not-exist.so.1"));
+ assert!(dlopen_loads("libc.so.6"));
+ }
+
+ #[test]
+ fn the_name_list_matches_the_locked_libappindicator_sys() {
+ // The list above is copied from libappindicator-sys 0.9.0. A bump of
+ // that crate can change the names; this makes the bump look here.
+ let lock = include_str!("../Cargo.lock");
+ let pos = lock
+ .find("name = \"libappindicator-sys\"\nversion = \"")
+ .expect("libappindicator-sys in Cargo.lock");
+ let version = &lock[pos..].lines().nth(1).unwrap();
+ assert_eq!(*version, "version = \"0.9.0\"", "check APPINDICATOR_LIBS against the new crate");
+ }
+}
diff --git a/src-tauri/tauri.linux.conf.json b/src-tauri/tauri.linux.conf.json
index 5d0b6a17..0380a6e5 100644
--- a/src-tauri/tauri.linux.conf.json
+++ b/src-tauri/tauri.linux.conf.json
@@ -17,6 +17,13 @@
]
},
"bundle": {
+ "linux": {
+ "appimage": {
+ "files": {
+ "/usr/lib/libayatana-appindicator3.so.1": "/usr/lib/x86_64-linux-gnu/libayatana-appindicator3.so.1"
+ }
+ }
+ },
"resources": {
"resources/whisper_server.py": "resources/whisper_server.py",
"resources/voice_loop/lu_voice_loop/*.py": "resources/voice_loop/lu_voice_loop/",
diff --git a/src/lib/__tests__/linux-appimage-traegt-tray-bibliothek.test.ts b/src/lib/__tests__/linux-appimage-traegt-tray-bibliothek.test.ts
new file mode 100644
index 00000000..7c05ee7d
--- /dev/null
+++ b/src/lib/__tests__/linux-appimage-traegt-tray-bibliothek.test.ts
@@ -0,0 +1,66 @@
+/**
+ * Die AppImage muss libayatana-appindicator3 mitbringen (GH #204).
+ *
+ * 3.0.8 startete auf CachyOS nicht: "Failed to load ayatana-appindicator3 or
+ * appindicator3 dynamic library". 3.0.7 brachte die Bibliothek mit, 3.0.8
+ * nicht. Ursache: @tauri-apps/cli packt sie nur ein, wenn es `tray-icon` am
+ * ERSTEN `tauri`-Eintrag der Cargo.toml findet (find_dependency in
+ * crates/tauri-cli/src/interface/rust/manifest.rs kehrt beim ersten Treffer
+ * zurueck). Seit 3.0.8 steht dort `[dependencies] tauri` nur mit image-png,
+ * `tray-icon` im Desktop-Target-Block, also sah die CLI kein Tray.
+ *
+ * Darum nennt tauri.linux.conf.json die Datei selbst, mit genau dem Schluessel,
+ * den die CLI auch nimmt (dann fuegt eine reparierte CLI sie nicht doppelt
+ * ein), und release.yml prueft die fertige AppImage.
+ *
+ * Gegenprobe: ohne den appimage.files-Eintrag ist der erste Fall rot.
+ *
+ * Lauf: npx vitest run src/lib/__tests__/linux-appimage-traegt-tray-bibliothek.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+
+const ROOT = resolve(__dirname, '../../..')
+const read = (rel: string) => readFileSync(resolve(ROOT, rel), 'utf8')
+const conf = (name: string) => JSON.parse(read(`src-tauri/${name}`))
+
+describe('Linux-Pakete bringen die Tray-Bibliothek mit oder verlangen sie', () => {
+ it('die AppImage nimmt libayatana-appindicator3.so.1 vom Bau-Rechner mit', () => {
+ const files = conf('tauri.linux.conf.json').bundle?.linux?.appimage?.files ?? {}
+ expect(files['/usr/lib/libayatana-appindicator3.so.1']).toBe(
+ '/usr/lib/x86_64-linux-gnu/libayatana-appindicator3.so.1',
+ )
+ })
+
+ it('das Overlay ueberschreibt die AppImage-Einstellung der Basis nicht', () => {
+ // Tauri merged die Overlays als JSON Merge Patch: bundleMediaFramework
+ // aus tauri.conf.json bleibt, solange das Overlay es nicht nennt.
+ expect(conf('tauri.linux.conf.json').bundle.linux.appimage.bundleMediaFramework).toBeUndefined()
+ expect(conf('tauri.conf.json').bundle.linux.appimage.bundleMediaFramework).toBe(true)
+ })
+
+ it('.deb und .rpm verlangen die Bibliothek als Abhaengigkeit', () => {
+ const linux = conf('tauri.conf.json').bundle.linux
+ expect(linux.deb.depends).toContain('libayatana-appindicator3-1')
+ expect(linux.rpm.depends).toContain('libappindicator-gtk3')
+ })
+
+ it('der Release-Bau prueft die fertige AppImage auf die Bibliothek und ihre Abhaengigkeiten', () => {
+ const yml = read('.github/workflows/release.yml')
+ for (const lib of [
+ 'libayatana-appindicator3.so.1',
+ 'libayatana-indicator3.so.7',
+ 'libayatana-ido3-0.4.so.0',
+ 'libdbusmenu-glib.so.4',
+ 'libdbusmenu-gtk3.so.4',
+ ]) {
+ expect(yml, lib).toContain(lib)
+ }
+ expect(yml).toContain('(GH #204)')
+ })
+
+ it('die Bau-Maschine hat das Paket installiert, aus dem die Datei kommt', () => {
+ expect(read('.github/workflows/release.yml')).toContain('libayatana-appindicator3-dev')
+ })
+})