mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3797 from Flow-Launcher/theme_mode_api
Add Theme mode API Function
This commit is contained in:
commit
aedfbfc632
5 changed files with 64 additions and 7 deletions
|
|
@ -40,6 +40,13 @@ namespace Flow.Launcher.Plugin
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
|
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A delegate for when the actual application theme is changed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
public delegate void ActualApplicationThemeChangedEventHandler(object sender, ActualApplicationThemeChangedEventArgs args);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The event args for <see cref="VisibilityChangedEventHandler"/>
|
/// The event args for <see cref="VisibilityChangedEventHandler"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -77,4 +84,15 @@ namespace Flow.Launcher.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Query Query { get; set; }
|
public Query Query { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The event args for <see cref="ActualApplicationThemeChangedEventHandler"/>
|
||||||
|
/// </summary>
|
||||||
|
public class ActualApplicationThemeChangedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <see langword="true"/> if the application has changed actual theme
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDark { get; init; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -595,5 +595,16 @@ namespace Flow.Launcher.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The time taken to execute the method in milliseconds</returns>
|
/// <returns>The time taken to execute the method in milliseconds</returns>
|
||||||
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");
|
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Representing whether the application is using a dark theme
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool IsApplicationDarkTheme();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when the actual theme of the application has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
|
||||||
|
/// </summary>
|
||||||
|
event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.Infrastructure.Hotkey;
|
using Flow.Launcher.Infrastructure.Hotkey;
|
||||||
using Flow.Launcher.Infrastructure.Image;
|
using Flow.Launcher.Infrastructure.Image;
|
||||||
using Flow.Launcher.Infrastructure.UserSettings;
|
using Flow.Launcher.Infrastructure.UserSettings;
|
||||||
|
using Flow.Launcher.Plugin;
|
||||||
using Flow.Launcher.Plugin.SharedCommands;
|
using Flow.Launcher.Plugin.SharedCommands;
|
||||||
using Flow.Launcher.ViewModel;
|
using Flow.Launcher.ViewModel;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
@ -91,8 +92,8 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
InitSoundEffects();
|
InitSoundEffects();
|
||||||
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
|
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
|
||||||
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
|
|
||||||
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
|
||||||
|
_viewModel.ActualApplicationThemeChanged += ViewModel_ActualApplicationThemeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -101,7 +102,7 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
#pragma warning disable VSTHRD100 // Avoid async void methods
|
#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();
|
_ = _theme.RefreshFrameAsync();
|
||||||
}
|
}
|
||||||
|
|
@ -1351,7 +1352,7 @@ namespace Flow.Launcher
|
||||||
_notifyIcon?.Dispose();
|
_notifyIcon?.Dispose();
|
||||||
animationSoundWMP?.Close();
|
animationSoundWMP?.Close();
|
||||||
animationSoundWPF?.Dispose();
|
animationSoundWPF?.Dispose();
|
||||||
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
|
_viewModel.ActualApplicationThemeChanged -= ViewModel_ActualApplicationThemeChanged;
|
||||||
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
|
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,24 @@ using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
using Flow.Launcher.Core;
|
using Flow.Launcher.Core;
|
||||||
|
using Flow.Launcher.Core.ExternalPlugins;
|
||||||
using Flow.Launcher.Core.Plugin;
|
using Flow.Launcher.Core.Plugin;
|
||||||
using Flow.Launcher.Core.Resource;
|
using Flow.Launcher.Core.Resource;
|
||||||
using Flow.Launcher.Core.ExternalPlugins;
|
|
||||||
using Flow.Launcher.Core.Storage;
|
using Flow.Launcher.Core.Storage;
|
||||||
using Flow.Launcher.Helper;
|
using Flow.Launcher.Helper;
|
||||||
using Flow.Launcher.Infrastructure;
|
using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.Infrastructure.Http;
|
|
||||||
using Flow.Launcher.Infrastructure.Hotkey;
|
using Flow.Launcher.Infrastructure.Hotkey;
|
||||||
|
using Flow.Launcher.Infrastructure.Http;
|
||||||
using Flow.Launcher.Infrastructure.Image;
|
using Flow.Launcher.Infrastructure.Image;
|
||||||
using Flow.Launcher.Infrastructure.Logger;
|
using Flow.Launcher.Infrastructure.Logger;
|
||||||
using Flow.Launcher.Infrastructure.Storage;
|
using Flow.Launcher.Infrastructure.Storage;
|
||||||
using Flow.Launcher.Infrastructure.UserSettings;
|
using Flow.Launcher.Infrastructure.UserSettings;
|
||||||
using Flow.Launcher.Plugin;
|
using Flow.Launcher.Plugin;
|
||||||
using Flow.Launcher.Plugin.SharedModels;
|
|
||||||
using Flow.Launcher.Plugin.SharedCommands;
|
using Flow.Launcher.Plugin.SharedCommands;
|
||||||
|
using Flow.Launcher.Plugin.SharedModels;
|
||||||
using Flow.Launcher.ViewModel;
|
using Flow.Launcher.ViewModel;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using ModernWpf;
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||||
|
|
||||||
|
|
@ -587,6 +588,17 @@ namespace Flow.Launcher
|
||||||
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
|
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
|
||||||
Stopwatch.InfoAsync(className, message, action, 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
|
#endregion
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ using Flow.Launcher.Plugin;
|
||||||
using Flow.Launcher.Plugin.SharedCommands;
|
using Flow.Launcher.Plugin.SharedCommands;
|
||||||
using Flow.Launcher.Storage;
|
using Flow.Launcher.Storage;
|
||||||
using Microsoft.VisualStudio.Threading;
|
using Microsoft.VisualStudio.Threading;
|
||||||
|
using ModernWpf;
|
||||||
|
|
||||||
namespace Flow.Launcher.ViewModel
|
namespace Flow.Launcher.ViewModel
|
||||||
{
|
{
|
||||||
|
|
@ -195,6 +196,18 @@ namespace Flow.Launcher.ViewModel
|
||||||
|
|
||||||
RegisterViewUpdate();
|
RegisterViewUpdate();
|
||||||
_ = RegisterClockAndDateUpdateAsync();
|
_ = 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()
|
private void RegisterViewUpdate()
|
||||||
|
|
@ -821,6 +834,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
public bool MainWindowVisibilityStatus { get; set; } = true;
|
public bool MainWindowVisibilityStatus { get; set; } = true;
|
||||||
|
|
||||||
public event VisibilityChangedEventHandler VisibilityChanged;
|
public event VisibilityChangedEventHandler VisibilityChanged;
|
||||||
|
public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
|
||||||
|
|
||||||
public Visibility ClockPanelVisibility { get; set; }
|
public Visibility ClockPanelVisibility { get; set; }
|
||||||
public Visibility SearchIconVisibility { get; set; }
|
public Visibility SearchIconVisibility { get; set; }
|
||||||
|
|
@ -1975,6 +1989,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
{
|
{
|
||||||
_resultsViewUpdateTask.Dispose();
|
_resultsViewUpdateTask.Dispose();
|
||||||
}
|
}
|
||||||
|
ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue