From d1a5cc8e843b32a094a03d5aa157c1989ee39fcb Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 5 Jul 2025 13:35:28 +0800 Subject: [PATCH] Add theme mode api functions --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 11 +++++++++++ Flow.Launcher/PublicAPIInstance.cs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index f47ee5e11..1827354d0 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -595,5 +595,16 @@ namespace Flow.Launcher.Plugin /// /// 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/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 6e82032ff..a2e5f1f85 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -14,23 +14,24 @@ using System.Windows; 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 @@ namespace Flow.Launcher 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