From 33434bcbe33cb5f12b139cef83b159d620e44370 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Tue, 20 Oct 2026 13:11:12 +1100 Subject: [PATCH] fix: don't show the tray window at startup with --minimized --- App.Avalonia/App.axaml.cs | 8 ++++---- App.Avalonia/Services/AvaloniaClipboardService.cs | 2 +- App.Avalonia/Services/AvaloniaWindowService.cs | 5 +++-- App.Avalonia/Views/TrayWindow.axaml.cs | 13 ------------- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/App.Avalonia/App.axaml.cs b/App.Avalonia/App.axaml.cs index 607ba98..564c73e 100644 --- a/App.Avalonia/App.axaml.cs +++ b/App.Avalonia/App.axaml.cs @@ -113,22 +113,22 @@ public override void OnFrameworkInitializationCompleted() } } + // Not desktop.MainWindow: the lifetime always shows that at startup. + // Hiding it again right away races the X11 window manager, which can + // leave an empty window on screen. _trayWindow = _services.GetRequiredService(); - // Make TrayWindow the MainWindow so dialogs can use it as an owner. - desktop.MainWindow = _trayWindow; - // If launched with --minimized (e.g. XDG autostart), keep startup // behavior as tray-first. Otherwise, show the tray window so manual // launches are visible even when tray icon integration is missing. if (startMinimized) { AppBootstrapLogger.Info("Startup mode: minimized to tray (--minimized)"); - _trayWindow.RequestHideOnFirstOpen(); } else { AppBootstrapLogger.Info("Startup mode: showing tray window"); + _trayWindow.Show(); } _trayIconViewModel = new TrayIconViewModel(ToggleTrayWindow, () => desktop.Shutdown()); diff --git a/App.Avalonia/Services/AvaloniaClipboardService.cs b/App.Avalonia/Services/AvaloniaClipboardService.cs index 7e30226..7d2dbca 100644 --- a/App.Avalonia/Services/AvaloniaClipboardService.cs +++ b/App.Avalonia/Services/AvaloniaClipboardService.cs @@ -11,7 +11,7 @@ public async Task SetTextAsync(string text) { if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - var clipboard = desktop.MainWindow?.Clipboard; + var clipboard = desktop.Windows.FirstOrDefault()?.Clipboard; if (clipboard != null) await clipboard.SetTextAsync(text); } diff --git a/App.Avalonia/Services/AvaloniaWindowService.cs b/App.Avalonia/Services/AvaloniaWindowService.cs index d42c149..1544d92 100644 --- a/App.Avalonia/Services/AvaloniaWindowService.cs +++ b/App.Avalonia/Services/AvaloniaWindowService.cs @@ -86,10 +86,11 @@ private static void ShowWindow(Window window, bool useOwner) { var desktop = Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime; - if (desktop?.MainWindow is TrayWindow trayWindow && trayWindow != window && trayWindow.IsVisible) + var trayWindow = desktop?.Windows.OfType().FirstOrDefault(); + if (trayWindow != null && trayWindow != window && trayWindow.IsVisible) trayWindow.Hide(); - var owner = useOwner ? desktop?.MainWindow : null; + var owner = useOwner ? trayWindow : null; if (owner != null && owner != window && owner.IsVisible) window.Show(owner); else diff --git a/App.Avalonia/Views/TrayWindow.axaml.cs b/App.Avalonia/Views/TrayWindow.axaml.cs index bb27a09..51cd281 100644 --- a/App.Avalonia/Views/TrayWindow.axaml.cs +++ b/App.Avalonia/Views/TrayWindow.axaml.cs @@ -24,7 +24,6 @@ public partial class TrayWindow : Window private TrayWindowLoginRequiredPage _loginRequiredPage; private TrayWindowMainPage _mainPage; - private bool _hideOnFirstOpen; private DateTime _suppressAutoHideUntilUtc; private bool _positionUpdateQueued; private int _sizeChangedCount; @@ -63,13 +62,6 @@ public TrayWindow() Opened += (_, _) => { AppBootstrapLogger.Info("Tray window opened"); - if (_hideOnFirstOpen) - { - _hideOnFirstOpen = false; - Hide(); - return; - } - PositionInBottomRight(); }; @@ -127,11 +119,6 @@ public TrayWindow( SetPageByState(_rpcController.GetState(), _credentialManager.GetCachedCredentials()); } - public void RequestHideOnFirstOpen() - { - _hideOnFirstOpen = true; - } - public void ShowNearSystemTray() { // Show() must be called before Activate() will do anything.