From 989935833f2df71aa32d32bf279d0c2c2ee76ff2 Mon Sep 17 00:00:00 2001 From: astar76 Date: Sat, 5 Dec 2026 00:40:10 -0600 Subject: [PATCH] Start in the tray waits for the desktop's tray at login Autostart ran Medlar before the shell's StatusNotifierWatcher was up, so the tray failed, the window opened and closing it quit. A --minimised start now spawns the tray with assume_sni_available, and the icon shows once the watcher appears. Co-Authored-By: Claude Opus 5.5 --- crates/app/src/app.rs | 2 +- crates/app/src/shell.rs | 6 ++++-- crates/app/src/tray.rs | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs index 7e278ad..1da8c32 100644 --- a/crates/app/src/app.rs +++ b/crates/app/src/app.rs @@ -564,7 +564,7 @@ fn open(engine: bool, show: fn(&mut App, &mut Ui), mut args: Vec) -> Exi } let opening = Opening { paths: paths.clone(), settings: app.settings.clone(), bus: Bus::System }; app.main.bridge = Bridge::open(opening, &ctx); - let shell = crate::shell::Shell::start(&ctx, &app.settings); + let shell = crate::shell::Shell::start(&ctx, &app.settings, minimised); window = !(minimised && shell.tray.is_some() && app.first.is_none()); app.shell = Some(shell); } diff --git a/crates/app/src/shell.rs b/crates/app/src/shell.rs index e2cffb5..d0fda98 100644 --- a/crates/app/src/shell.rs +++ b/crates/app/src/shell.rs @@ -45,9 +45,11 @@ pub struct Shell { } impl Shell { - pub fn start(ctx: &Context, settings: &Settings) -> Shell { + /// `minimised`: started in the tray, so a tray that is not up yet is waited for. + pub fn start(ctx: &Context, settings: &Settings, minimised: bool) -> Shell { let (tx, rx): (Sender, Receiver) = channel(); - let tray = settings.tray.then(|| Tray::start(tx.clone(), ctx.clone())).flatten(); + let start = if minimised { Tray::start_waiting } else { Tray::start }; + let tray = settings.tray.then(|| start(tx.clone(), ctx.clone())).flatten(); let notes = zbus::blocking::Connection::session().ok().map(|c| Notifier::start(c, tx, ctx.clone())); Shell { tray, diff --git a/crates/app/src/tray.rs b/crates/app/src/tray.rs index 20b90f4..779b78a 100644 --- a/crates/app/src/tray.rs +++ b/crates/app/src/tray.rs @@ -1,5 +1,6 @@ //! The tray icon (StatusNotifierItem): a progress ring around the app icon, the speed as tooltip and a menu. -//! Without a StatusNotifierWatcher on the bus `start` gives None, and the window closes as usual. +//! Without a StatusNotifierWatcher on the bus `start` gives None, and the window closes as usual; `start_waiting` +//! (a start in the tray) waits for one. use crate::shell::Do; use crate::ui::odometer::rate; @@ -149,8 +150,18 @@ pub struct Tray { impl Tray { /// None when the desktop has no tray host (or the bus is out of reach). pub fn start(tx: Sender, ctx: Context) -> Option { + Self::spawn(tx, ctx, false) + } + + /// Like `start`, but with no watcher yet the icon shows once one comes: at login Medlar can start before the + /// desktop's tray. + pub fn start_waiting(tx: Sender, ctx: Context) -> Option { + Self::spawn(tx, ctx, true) + } + + fn spawn(tx: Sender, ctx: Context, wait: bool) -> Option { let base = crate::icons::app_rgba(SIZE)?; - match (Item { tx, ctx, base, state: None }).spawn() { + match (Item { tx, ctx, base, state: None }).assume_sni_available(wait).spawn() { Ok(handle) => Some(Tray { handle }), Err(e) => { log::info!("tray: {e}");