diff --git a/src/DesktopMagic/BuiltInPlugins/DatePlugin.cs b/src/DesktopMagic/BuiltInPlugins/DatePlugin.cs
index 9a6ad36..f622fd3 100644
--- a/src/DesktopMagic/BuiltInPlugins/DatePlugin.cs
+++ b/src/DesktopMagic/BuiltInPlugins/DatePlugin.cs
@@ -13,22 +13,28 @@ internal class DatePlugin : Plugin
private readonly CheckBox shortDateCheckBox = new CheckBox(true);
private DateTime oldDateTime = DateTime.MinValue;
- private Color oldColor = Color.White;
- private string oldFont = string.Empty;
- private bool oldShortDateCheckBoxValue;
+ private bool themeChanged = false;
+
public override int UpdateInterval => 1000;
+ public override void Start()
+ {
+ Application.ThemeChanged += (_, _) =>
+ {
+ themeChanged = true;
+ Application.UpdateWindow();
+ themeChanged = false;
+ };
+ }
+
public override Bitmap? Main()
{
- if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font && oldShortDateCheckBoxValue == shortDateCheckBox.Value)
+ if (oldDateTime.Date == DateTime.Now.Date && !themeChanged)
{
return null;
}
oldDateTime = DateTime.Now;
- oldColor = Application.Theme.PrimaryColor;
- oldFont = Application.Theme.Font;
- oldShortDateCheckBoxValue = shortDateCheckBox.Value;
string date = shortDateCheckBox.Value ? DateTime.Now.ToShortDateString() : DateTime.Now.ToLongDateString();
diff --git a/src/DesktopMagic/BuiltInPlugins/TimePlugin.cs b/src/DesktopMagic/BuiltInPlugins/TimePlugin.cs
index f56d699..8497124 100644
--- a/src/DesktopMagic/BuiltInPlugins/TimePlugin.cs
+++ b/src/DesktopMagic/BuiltInPlugins/TimePlugin.cs
@@ -13,24 +13,32 @@ internal class TimePlugin : Plugin
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
private string oldTime = string.Empty;
- private Color oldColor = Color.White;
- private string oldFont = string.Empty;
- private bool oldDisplaySecondsCheckBoxValue;
+ private bool themeChanged;
public override int UpdateInterval => 1000;
+ public override void Start()
+ {
+ Application.ThemeChanged += (_, _) => ThemeChanged();
+ displaySecondsCheckBox.OnValueChanged += ThemeChanged;
+
+ void ThemeChanged()
+ {
+ themeChanged = true;
+ Application.UpdateWindow();
+ themeChanged = false;
+ }
+ }
+
public override Bitmap? Main()
{
string time = displaySecondsCheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
- if (oldTime == time && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font && oldDisplaySecondsCheckBoxValue == displaySecondsCheckBox.Value)
+ if (oldTime == time && !themeChanged)
{
return null;
}
oldTime = time;
- oldColor = Application.Theme.PrimaryColor;
- oldFont = Application.Theme.Font;
- oldDisplaySecondsCheckBoxValue = displaySecondsCheckBox.Value;
Font font = new Font(Application.Theme.Font, 200);
diff --git a/src/DesktopMagic/Plugins/PluginData.cs b/src/DesktopMagic/Plugins/PluginData.cs
index 6a39238..5ba54ef 100644
--- a/src/DesktopMagic/Plugins/PluginData.cs
+++ b/src/DesktopMagic/Plugins/PluginData.cs
@@ -1,6 +1,7 @@
using DesktopMagic.Api;
using DesktopMagic.Settings;
+using System;
using System.Drawing;
namespace DesktopMagic.Plugins;
@@ -9,6 +10,8 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) :
{
private readonly PluginWindow window = window;
+ public event EventHandler? ThemeChanged;
+
public ITheme Theme => pluginSettings.Theme;
public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
@@ -23,4 +26,9 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) :
{
window.UpdatePluginWindow();
}
+
+ internal void NotifyThemeChanged()
+ {
+ ThemeChanged?.Invoke(this, EventArgs.Empty);
+ }
}
\ No newline at end of file
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index 9909c77..8e478e5 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -104,7 +104,6 @@ public partial class PluginWindow : Window, IPluginWindow
public void UpdatePluginWindow()
{
- Dispatcher.Invoke(ThemeChanged);
UpdateTimer_Elapsed(updateTimer, null);
}
@@ -209,6 +208,8 @@ public partial class PluginWindow : Window, IPluginWindow
viewBox.Margin = new Thickness(settings.Theme.Margin);
border.Background = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(settings.Theme.BackgroundColor));
border.CornerRadius = new CornerRadius(settings.Theme.CornerRadius);
+
+ (pluginClassInstance?.Application as PluginData)?.NotifyThemeChanged();
}
private void ExecuteSource()
@@ -267,6 +268,7 @@ public partial class PluginWindow : Window, IPluginWindow
pluginClassInstance.Start();
UpdatePluginWindow();
+ Dispatcher.Invoke(ThemeChanged);
if (pluginClassInstance.UpdateInterval > 0)
{
diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs
index 3f0aaca..5a42904 100644
--- a/src/DesktopMagicPluginAPI/IPluginData.cs
+++ b/src/DesktopMagicPluginAPI/IPluginData.cs
@@ -1,4 +1,5 @@
-using System.Drawing;
+using System;
+using System.Drawing;
namespace DesktopMagic.Api;
@@ -7,6 +8,14 @@ namespace DesktopMagic.Api;
///
public interface IPluginData
{
+ ///
+ /// Occurs when the application's theme has changed.
+ ///
+ /// Subscribe to this event to be notified when the theme changes, allowing UI elements or
+ /// components to update their appearance accordingly. The event is raised after the theme change has been
+ /// applied.
+ event EventHandler? ThemeChanged;
+
///
/// Gets the current theme setting of the main application.
///