From eaa9b3a8da07ac730b41b2b3e3cfa23012617e53 Mon Sep 17 00:00:00 2001 From: endercodezz Date: Sun, 22 Nov 2026 04:13:33 +0200 Subject: [PATCH] Select the current profile item from the tray The tray server submenu is rebuilt only when ids or names change, but editing a profile replaces its item. The menu command captured the old item, so choosing it connected with pre-edit settings. Resolve the item by id when the command runs, and cover it in the mock desktop check. Closes #513 --- src/Bydlo.App/Services/DesktopIntegration.cs | 13 ++++++++++++- tools/Bydlo.Screenshots/DesktopVerification.cs | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Bydlo.App/Services/DesktopIntegration.cs b/src/Bydlo.App/Services/DesktopIntegration.cs index ff11f69e..fe0e9ad3 100644 --- a/src/Bydlo.App/Services/DesktopIntegration.cs +++ b/src/Bydlo.App/Services/DesktopIntegration.cs @@ -197,7 +197,9 @@ private void Refresh() _servers.Items.Add(new NativeMenuItem { Header = profile.Name, ToggleType = NativeMenuItemToggleType.Radio, - Command = new RelayCommand(() => _shell.SelectedProfile = profile), + // Resolve by id on click: editing a profile replaces its item without renaming it, + // so a captured item would connect with the pre-edit settings. + Command = new RelayCommand(() => SelectProfile(profile.Id)), }); } _profilesState = profilesState; @@ -210,6 +212,15 @@ private void Refresh() _menuState = state; } + /// Selects the current item for ; a profile deleted meanwhile is ignored. + internal void SelectProfile(Guid id) + { + if (_shell.Profiles.FirstOrDefault(p => p.Id == id) is { } current) + { + _shell.SelectedProfile = current; + } + } + private ConnectionStatus? _iconStatus; private void UpdateIcon() { diff --git a/tools/Bydlo.Screenshots/DesktopVerification.cs b/tools/Bydlo.Screenshots/DesktopVerification.cs index 30d128a4..99450930 100644 --- a/tools/Bydlo.Screenshots/DesktopVerification.cs +++ b/tools/Bydlo.Screenshots/DesktopVerification.cs @@ -66,6 +66,14 @@ public static void Run(MainViewModel shell, AppServices services, string output) Pump(50); if (!select.IsChecked || ((NativeMenuItem)servers.Items[0]).IsChecked) { throw new InvalidOperationException("Tray radio selection did not refresh."); } + // Editing a profile replaces its item without renaming it; the tray must select the current item, + // not the one captured when the submenu was built, or it connects with pre-edit settings. + shell.ReloadProfiles(); + Pump(50); + ((NativeMenuItem)servers.Items[0]).Command!.Execute(null); + Pump(50); + if (!ReferenceEquals(shell.SelectedProfile, shell.Profiles[0])) + { throw new InvalidOperationException("Tray selected a stale profile item after a reload."); } // Registration must remain blocked in developer sessions without touching the OS. shell.Settings.StartWithSystem = true;