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 <[email protected]>
This commit is contained in:
astar76 2026-12-05 00:40:10 -06:00
commit 989935833f
3 changed files with 18 additions and 5 deletions

View file

@ -564,7 +564,7 @@ fn open(engine: bool, show: fn(&mut App, &mut Ui), mut args: Vec<String>) -> 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);
}

View file

@ -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<Do>, Receiver<Do>) = 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,

View file

@ -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<Do>, ctx: Context) -> Option<Tray> {
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<Do>, ctx: Context) -> Option<Tray> {
Self::spawn(tx, ctx, true)
}
fn spawn(tx: Sender<Do>, ctx: Context, wait: bool) -> Option<Tray> {
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}");