diff --git a/Flow.Launcher.Plugin/EventHandler.cs b/Flow.Launcher.Plugin/EventHandler.cs
index 893b0ba8047..47ab24757cd 100644
--- a/Flow.Launcher.Plugin/EventHandler.cs
+++ b/Flow.Launcher.Plugin/EventHandler.cs
@@ -39,7 +39,14 @@ namespace Flow.Launcher.Plugin
///
///
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
-
+
+ ///
+ /// A delegate for when the actual application theme is changed
+ ///
+ ///
+ ///
+ public delegate void ActualApplicationThemeChangedEventHandler(object sender, ActualApplicationThemeChangedEventArgs args);
+
///
/// The event args for
///
@@ -77,4 +84,15 @@ public class FlowLauncherQueryEventArgs
///
public Query Query { get; set; }
}
+
+ ///
+ /// The event args for
+ ///
+ public class ActualApplicationThemeChangedEventArgs : EventArgs
+ {
+ ///
+ /// if the application has changed actual theme
+ ///
+ public bool IsDark { get; init; }
+ }
}
diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
index f47ee5e11c8..1827354d0ba 100644
--- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
+++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
@@ -595,5 +595,16 @@ public interface IPublicAPI
///
/// The time taken to execute the method in milliseconds
public Task StopwatchLogInfoAsync(string className, string message, Func action, [CallerMemberName] string methodName = "");
+
+ ///
+ /// Representing whether the application is using a dark theme
+ ///
+ ///
+ bool IsApplicationDarkTheme();
+
+ ///
+ /// Invoked when the actual theme of the application has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
+ ///
+ event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
}
}
diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs
index f4d7ad8eb29..aa5040dac7a 100644
--- a/Flow.Launcher/MainWindow.xaml.cs
+++ b/Flow.Launcher/MainWindow.xaml.cs
@@ -20,6 +20,7 @@
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Infrastructure.Image;
using Flow.Launcher.Infrastructure.UserSettings;
+using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.ViewModel;
using Microsoft.Win32;
@@ -91,8 +92,8 @@ public MainWindow()
InitSoundEffects();
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
- ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
+ _viewModel.ActualApplicationThemeChanged += ViewModel_ActualApplicationThemeChanged;
}
#endregion
@@ -101,7 +102,7 @@ public MainWindow()
#pragma warning disable VSTHRD100 // Avoid async void methods
- private void ThemeManager_ActualApplicationThemeChanged(ModernWpf.ThemeManager sender, object args)
+ private void ViewModel_ActualApplicationThemeChanged(object sender, ActualApplicationThemeChangedEventArgs args)
{
_ = _theme.RefreshFrameAsync();
}
@@ -1351,7 +1352,7 @@ protected virtual void Dispose(bool disposing)
_notifyIcon?.Dispose();
animationSoundWMP?.Close();
animationSoundWPF?.Dispose();
- ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
+ _viewModel.ActualApplicationThemeChanged -= ViewModel_ActualApplicationThemeChanged;
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
}
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 6e82032ffe2..a2e5f1f8591 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -14,23 +14,24 @@
using System.Windows.Media;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Core;
+using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Core.Resource;
-using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Core.Storage;
using Flow.Launcher.Helper;
using Flow.Launcher.Infrastructure;
-using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Hotkey;
+using Flow.Launcher.Infrastructure.Http;
using Flow.Launcher.Infrastructure.Image;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
-using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.Plugin.SharedCommands;
+using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.ViewModel;
using JetBrains.Annotations;
+using ModernWpf;
using Squirrel;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
@@ -587,6 +588,17 @@ public long StopwatchLogInfo(string className, string message, Action action, [C
public Task StopwatchLogInfoAsync(string className, string message, Func action, [CallerMemberName] string methodName = "") =>
Stopwatch.InfoAsync(className, message, action, methodName);
+ public bool IsApplicationDarkTheme()
+ {
+ return ThemeManager.Current.ActualApplicationTheme == ApplicationTheme.Dark;
+ }
+
+ public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged
+ {
+ add => _mainVM.ActualApplicationThemeChanged += value;
+ remove => _mainVM.ActualApplicationThemeChanged -= value;
+ }
+
#endregion
#region Private Methods
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index 64a39fa6279..49f7ea6c535 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -22,6 +22,7 @@
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Storage;
using Microsoft.VisualStudio.Threading;
+using ModernWpf;
namespace Flow.Launcher.ViewModel
{
@@ -195,6 +196,18 @@ public MainViewModel()
RegisterViewUpdate();
_ = RegisterClockAndDateUpdateAsync();
+
+ ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
+ }
+
+ private void ThemeManager_ActualApplicationThemeChanged(ThemeManager sender, object args)
+ {
+ ActualApplicationThemeChanged?.Invoke(
+ Application.Current,
+ new ActualApplicationThemeChangedEventArgs()
+ {
+ IsDark = sender.ActualApplicationTheme == ApplicationTheme.Dark
+ });
}
private void RegisterViewUpdate()
@@ -821,6 +834,7 @@ private ResultsViewModel SelectedResults
public bool MainWindowVisibilityStatus { get; set; } = true;
public event VisibilityChangedEventHandler VisibilityChanged;
+ public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
public Visibility ClockPanelVisibility { get; set; }
public Visibility SearchIconVisibility { get; set; }
@@ -1975,6 +1989,7 @@ protected virtual void Dispose(bool disposing)
{
_resultsViewUpdateTask.Dispose();
}
+ ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
_disposed = true;
}
}