From a00ff3df462622ff4a4f60372993cffd9db16a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sat, 4 Oct 2025 14:44:51 +0200 Subject: [PATCH] Fix settings navigation and fix flicker on personalizaton nav. --- .../PersonalizationPageViewModel.cs | 31 +++++-------------- Wino.Core.WinUI/Services/NewThemeService.cs | 28 ++++++++++++----- .../Views/ManageAccountsPage.xaml.cs | 16 ++++++++++ Wino.Core.WinUI/Views/SettingsPage.xaml.cs | 11 +++++++ 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/Wino.Core.ViewModels/PersonalizationPageViewModel.cs b/Wino.Core.ViewModels/PersonalizationPageViewModel.cs index b68ec62a..e136bf4d 100644 --- a/Wino.Core.ViewModels/PersonalizationPageViewModel.cs +++ b/Wino.Core.ViewModels/PersonalizationPageViewModel.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; @@ -127,14 +126,6 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel [ObservableProperty] public partial BackdropTypeWrapper SelectedBackdropType { get; set; } - partial void OnSelectedBackdropTypeChanged(BackdropTypeWrapper value) - { - if (!isPropChangeDisabled && value != null) - { - _newThemeService.CurrentBackdropType = value.BackdropType; - } - } - #endregion [RelayCommand] @@ -218,12 +209,9 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel var currentThemeId = _newThemeService.CurrentApplicationThemeId; SelectedAppTheme = currentThemeId.HasValue ? AppThemes.Find(a => a.Id == currentThemeId.Value) : null; - // Set the current backdrop, default to Mica if theme selected, None if custom theme - var targetBackdropType = SelectedAppTheme != null && SelectedAppTheme.AppThemeType != AppThemeType.Custom - ? _newThemeService.CurrentBackdropType - : WindowBackdropType.None; - - SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == targetBackdropType); + // Set the current backdrop from service - backdrop should be independent of theme selection + var currentBackdropType = _newThemeService.CurrentBackdropType; + SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == currentBackdropType); } public override async void OnNavigatedTo(NavigationMode mode, object parameters) @@ -310,14 +298,11 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel // Set the theme ID, can be null if no theme is selected _newThemeService.CurrentApplicationThemeId = SelectedAppTheme?.Id; - // When a custom/predefined theme is selected, set backdrop to None - // When no theme is selected (system theme), keep current backdrop - if (SelectedAppTheme != null) - { - isPropChangeDisabled = true; - SelectedBackdropType = AvailableBackdropTypes?.FirstOrDefault(x => x.BackdropType == WindowBackdropType.None); - isPropChangeDisabled = false; - } + // Theme selection should not affect backdrop - they are independent settings + } + else if (e.PropertyName == nameof(SelectedBackdropType) && SelectedBackdropType != null) + { + _newThemeService.CurrentBackdropType = SelectedBackdropType.BackdropType; } else { diff --git a/Wino.Core.WinUI/Services/NewThemeService.cs b/Wino.Core.WinUI/Services/NewThemeService.cs index f430b3e6..340a61f3 100644 --- a/Wino.Core.WinUI/Services/NewThemeService.cs +++ b/Wino.Core.WinUI/Services/NewThemeService.cs @@ -146,6 +146,9 @@ public class NewThemeService : INewThemeService get { return currentBackdropType; } set { + // Only update if the backdrop type has actually changed + if (currentBackdropType == value) return; + currentBackdropType = value; _configurationService.Set(WindowBackdropTypeKey, (int)value); @@ -222,11 +225,14 @@ public class NewThemeService : INewThemeService _ => new MicaBackdrop() { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base } }; - windowEx.SystemBackdrop = backdrop; + if (windowEx.SystemBackdrop != backdrop) + { + windowEx.SystemBackdrop = backdrop; - BackdropChanged?.Invoke(this, backdropType); + BackdropChanged?.Invoke(this, backdropType); - Debug.WriteLine($"Applied backdrop: {backdropType}"); + Debug.WriteLine($"Applied backdrop: {backdropType}"); + } } catch (Exception ex) { @@ -284,11 +290,9 @@ public class NewThemeService : INewThemeService bool isDarkTheme = _underlyingThemeService.IsUnderlyingThemeDark(); // Set button colors based on theme - // Background is always transparent for all buttons + // Normal and inactive backgrounds are transparent, but hover/pressed have subtle backgrounds titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent - titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent - titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent if (isDarkTheme) { @@ -296,7 +300,11 @@ public class NewThemeService : INewThemeService titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White - titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white + titleBar.ButtonPressedForegroundColor = Color.FromArgb(255, 255, 255, 255); // White + + // Subtle hover and pressed backgrounds for dark theme + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(20, 255, 255, 255); // Very subtle white overlay + titleBar.ButtonPressedBackgroundColor = Color.FromArgb(40, 255, 255, 255); // Slightly more visible white overlay } else { @@ -304,7 +312,11 @@ public class NewThemeService : INewThemeService titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black - titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black + titleBar.ButtonPressedForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black + + // Subtle hover and pressed backgrounds for light theme + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(20, 0, 0, 0); // Very subtle black overlay + titleBar.ButtonPressedBackgroundColor = Color.FromArgb(40, 0, 0, 0); // Slightly more visible black overlay } Debug.WriteLine($"Updated title bar button colors for {(isDarkTheme ? "dark" : "light")} theme"); diff --git a/Wino.Core.WinUI/Views/ManageAccountsPage.xaml.cs b/Wino.Core.WinUI/Views/ManageAccountsPage.xaml.cs index 09f40e7e..6de98c2b 100644 --- a/Wino.Core.WinUI/Views/ManageAccountsPage.xaml.cs +++ b/Wino.Core.WinUI/Views/ManageAccountsPage.xaml.cs @@ -32,6 +32,12 @@ public sealed partial class ManageAccountsPage : ManageAccountsPageAbstract, { base.OnNavigatedTo(e); + // Re-register message handlers after base.OnNavigatedTo unregisters all handlers + WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); + var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuManageAccounts, WinoPage.AccountManagementPage); PageHistory.Add(new BreadcrumbNavigationItemViewModel(initialRequest, true)); @@ -40,6 +46,16 @@ public sealed partial class ManageAccountsPage : ManageAccountsPageAbstract, AccountPagesFrame.Navigate(accountManagementPageType, null, new SuppressNavigationTransitionInfo()); } + protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) + { + // Explicitly unregister our message handlers before base.OnNavigatingFrom calls UnregisterAll + WeakReferenceMessenger.Default.Unregister(this); + WeakReferenceMessenger.Default.Unregister(this); + WeakReferenceMessenger.Default.Unregister(this); + WeakReferenceMessenger.Default.Unregister(this); + + base.OnNavigatingFrom(e); + } void IRecipient.Receive(BreadcrumbNavigationRequested message) { diff --git a/Wino.Core.WinUI/Views/SettingsPage.xaml.cs b/Wino.Core.WinUI/Views/SettingsPage.xaml.cs index 266e1191..e498a02a 100644 --- a/Wino.Core.WinUI/Views/SettingsPage.xaml.cs +++ b/Wino.Core.WinUI/Views/SettingsPage.xaml.cs @@ -26,6 +26,9 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient(this); + SettingsFrame.Navigate(typeof(SettingOptionsPage), null, new SuppressNavigationTransitionInfo()); var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuSettings, WinoPage.SettingOptionsPage); @@ -58,6 +61,14 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient(this); + + base.OnNavigatingFrom(e); + } + void IRecipient.Receive(BreadcrumbNavigationRequested message) { var pageType = ViewModel.NavigationService.GetPageType(message.PageType);