diff --git a/Preses/AppPres.cs b/Preses/AppPres.cs deleted file mode 100644 index c482542..0000000 --- a/Preses/AppPres.cs +++ /dev/null @@ -1,18 +0,0 @@ -using CommunityToolkit.Mvvm.ComponentModel; -using MaterialDesignThemes.Wpf; - -namespace Sheas_Cealer.Preses; - -internal partial class AppPres : ObservableObject -{ - [ObservableProperty] - private bool? isLightTheme = null; - partial void OnIsLightThemeChanged(bool? value) - { - PaletteHelper paletteHelper = new(); - Theme newTheme = paletteHelper.GetTheme(); - - newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit); - paletteHelper.SetTheme(newTheme); - } -} \ No newline at end of file diff --git a/Preses/GlobalPres.cs b/Preses/GlobalPres.cs new file mode 100644 index 0000000..228186f --- /dev/null +++ b/Preses/GlobalPres.cs @@ -0,0 +1,26 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging.Messages; +using MaterialDesignThemes.Wpf; + +namespace Sheas_Cealer.Preses; + +internal partial class GlobalPres : ObservableRecipient, IRecipient> +{ + internal GlobalPres() => IsActive = true; + + [ObservableProperty, NotifyPropertyChangedRecipients] + private bool? isLightTheme = null; + partial void OnIsLightThemeChanged(bool? value) + { + PaletteHelper paletteHelper = new(); + Theme newTheme = paletteHelper.GetTheme(); + + newTheme.SetBaseTheme(value.HasValue ? value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark : BaseTheme.Inherit); + paletteHelper.SetTheme(newTheme); + } + + protected override void Broadcast(T oldValue, T newValue, string? propertyName) => Messenger.Send(new PropertyChangedMessage(this, propertyName, oldValue!, newValue!)); + + public void Receive(PropertyChangedMessage message) => GetType().GetProperty(message.PropertyName!)!.SetValue(this, message.NewValue); +} \ No newline at end of file diff --git a/Preses/MainPres.cs b/Preses/MainPres.cs index e84b03e..99048c6 100644 --- a/Preses/MainPres.cs +++ b/Preses/MainPres.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using System.IO; using CommunityToolkit.Mvvm.ComponentModel; -using MaterialDesignThemes.Wpf; using Microsoft.Win32; using Sheas_Cealer.Consts; using Sheas_Cealer.Props; @@ -10,7 +9,7 @@ using File = System.IO.File; namespace Sheas_Cealer.Preses; -internal partial class MainPres : AppPres +internal partial class MainPres : GlobalPres { internal MainPres(string[] args) {