mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Add ThemeChanged event to IPluginData
This commit is contained in:
@@ -13,22 +13,28 @@ internal class DatePlugin : Plugin
|
|||||||
private readonly CheckBox shortDateCheckBox = new CheckBox(true);
|
private readonly CheckBox shortDateCheckBox = new CheckBox(true);
|
||||||
|
|
||||||
private DateTime oldDateTime = DateTime.MinValue;
|
private DateTime oldDateTime = DateTime.MinValue;
|
||||||
private Color oldColor = Color.White;
|
private bool themeChanged = false;
|
||||||
private string oldFont = string.Empty;
|
|
||||||
private bool oldShortDateCheckBoxValue;
|
|
||||||
public override int UpdateInterval => 1000;
|
public override int UpdateInterval => 1000;
|
||||||
|
|
||||||
|
public override void Start()
|
||||||
|
{
|
||||||
|
Application.ThemeChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
themeChanged = true;
|
||||||
|
Application.UpdateWindow();
|
||||||
|
themeChanged = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public override Bitmap? Main()
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldDateTime = DateTime.Now;
|
oldDateTime = DateTime.Now;
|
||||||
oldColor = Application.Theme.PrimaryColor;
|
|
||||||
oldFont = Application.Theme.Font;
|
|
||||||
oldShortDateCheckBoxValue = shortDateCheckBox.Value;
|
|
||||||
|
|
||||||
string date = shortDateCheckBox.Value ? DateTime.Now.ToShortDateString() : DateTime.Now.ToLongDateString();
|
string date = shortDateCheckBox.Value ? DateTime.Now.ToShortDateString() : DateTime.Now.ToLongDateString();
|
||||||
|
|
||||||
|
|||||||
@@ -13,24 +13,32 @@ internal class TimePlugin : Plugin
|
|||||||
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
private readonly CheckBox displaySecondsCheckBox = new CheckBox(true);
|
||||||
|
|
||||||
private string oldTime = string.Empty;
|
private string oldTime = string.Empty;
|
||||||
private Color oldColor = Color.White;
|
private bool themeChanged;
|
||||||
private string oldFont = string.Empty;
|
|
||||||
private bool oldDisplaySecondsCheckBoxValue;
|
|
||||||
public override int UpdateInterval => 1000;
|
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()
|
public override Bitmap? Main()
|
||||||
{
|
{
|
||||||
string time = displaySecondsCheckBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldTime = time;
|
oldTime = time;
|
||||||
oldColor = Application.Theme.PrimaryColor;
|
|
||||||
oldFont = Application.Theme.Font;
|
|
||||||
oldDisplaySecondsCheckBoxValue = displaySecondsCheckBox.Value;
|
|
||||||
|
|
||||||
Font font = new Font(Application.Theme.Font, 200);
|
Font font = new Font(Application.Theme.Font, 200);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using DesktopMagic.Api;
|
using DesktopMagic.Api;
|
||||||
using DesktopMagic.Settings;
|
using DesktopMagic.Settings;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
namespace DesktopMagic.Plugins;
|
namespace DesktopMagic.Plugins;
|
||||||
@@ -9,6 +10,8 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) :
|
|||||||
{
|
{
|
||||||
private readonly PluginWindow window = window;
|
private readonly PluginWindow window = window;
|
||||||
|
|
||||||
|
public event EventHandler? ThemeChanged;
|
||||||
|
|
||||||
public ITheme Theme => pluginSettings.Theme;
|
public ITheme Theme => pluginSettings.Theme;
|
||||||
|
|
||||||
public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
|
public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
|
||||||
@@ -23,4 +26,9 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) :
|
|||||||
{
|
{
|
||||||
window.UpdatePluginWindow();
|
window.UpdatePluginWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void NotifyThemeChanged()
|
||||||
|
{
|
||||||
|
ThemeChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,6 @@ public partial class PluginWindow : Window, IPluginWindow
|
|||||||
|
|
||||||
public void UpdatePluginWindow()
|
public void UpdatePluginWindow()
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(ThemeChanged);
|
|
||||||
UpdateTimer_Elapsed(updateTimer, null);
|
UpdateTimer_Elapsed(updateTimer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +208,8 @@ public partial class PluginWindow : Window, IPluginWindow
|
|||||||
viewBox.Margin = new Thickness(settings.Theme.Margin);
|
viewBox.Margin = new Thickness(settings.Theme.Margin);
|
||||||
border.Background = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(settings.Theme.BackgroundColor));
|
border.Background = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(settings.Theme.BackgroundColor));
|
||||||
border.CornerRadius = new CornerRadius(settings.Theme.CornerRadius);
|
border.CornerRadius = new CornerRadius(settings.Theme.CornerRadius);
|
||||||
|
|
||||||
|
(pluginClassInstance?.Application as PluginData)?.NotifyThemeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteSource()
|
private void ExecuteSource()
|
||||||
@@ -267,6 +268,7 @@ public partial class PluginWindow : Window, IPluginWindow
|
|||||||
|
|
||||||
pluginClassInstance.Start();
|
pluginClassInstance.Start();
|
||||||
UpdatePluginWindow();
|
UpdatePluginWindow();
|
||||||
|
Dispatcher.Invoke(ThemeChanged);
|
||||||
|
|
||||||
if (pluginClassInstance.UpdateInterval > 0)
|
if (pluginClassInstance.UpdateInterval > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace DesktopMagic.Api;
|
namespace DesktopMagic.Api;
|
||||||
|
|
||||||
@@ -7,6 +8,14 @@ namespace DesktopMagic.Api;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPluginData
|
public interface IPluginData
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the application's theme has changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>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.</remarks>
|
||||||
|
event EventHandler? ThemeChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current theme setting of the main application.
|
/// Gets the current theme setting of the main application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user