Skip to content

Commit a6c038f

Browse files
authored
Merge branch 'dev' into check_plugin_modified
2 parents 446c61f + 8e6eaf7 commit a6c038f

File tree

8 files changed

+67
-11
lines changed

8 files changed

+67
-11
lines changed

Flow.Launcher.Plugin/EventHandler.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ namespace Flow.Launcher.Plugin
3939
/// <param name="sender"></param>
4040
/// <param name="args"></param>
4141
public delegate void VisibilityChangedEventHandler(object sender, VisibilityChangedEventArgs args);
42-
42+
43+
/// <summary>
44+
/// A delegate for when the actual application theme is changed
45+
/// </summary>
46+
/// <param name="sender"></param>
47+
/// <param name="args"></param>
48+
public delegate void ActualApplicationThemeChangedEventHandler(object sender, ActualApplicationThemeChangedEventArgs args);
49+
4350
/// <summary>
4451
/// The event args for <see cref="VisibilityChangedEventHandler"/>
4552
/// </summary>
@@ -77,4 +84,15 @@ public class FlowLauncherQueryEventArgs
7784
/// </summary>
7885
public Query Query { get; set; }
7986
}
87+
88+
/// <summary>
89+
/// The event args for <see cref="ActualApplicationThemeChangedEventHandler"/>
90+
/// </summary>
91+
public class ActualApplicationThemeChangedEventArgs : EventArgs
92+
{
93+
/// <summary>
94+
/// <see langword="true"/> if the application has changed actual theme
95+
/// </summary>
96+
public bool IsDark { get; init; }
97+
}
8098
}

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,5 +595,16 @@ public interface IPublicAPI
595595
/// </summary>
596596
/// <returns>The time taken to execute the method in milliseconds</returns>
597597
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");
598+
599+
/// <summary>
600+
/// Representing whether the application is using a dark theme
601+
/// </summary>
602+
/// <returns></returns>
603+
bool IsApplicationDarkTheme();
604+
605+
/// <summary>
606+
/// Invoked when the actual theme of the application has changed. Currently, the plugin will continue to be subscribed even if it is turned off.
607+
/// </summary>
608+
event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
598609
}
599610
}

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Flow.Launcher.Infrastructure.Hotkey;
2121
using Flow.Launcher.Infrastructure.Image;
2222
using Flow.Launcher.Infrastructure.UserSettings;
23+
using Flow.Launcher.Plugin;
2324
using Flow.Launcher.Plugin.SharedCommands;
2425
using Flow.Launcher.ViewModel;
2526
using Microsoft.Win32;
@@ -91,8 +92,8 @@ public MainWindow()
9192

9293
InitSoundEffects();
9394
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
94-
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
9595
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
96+
_viewModel.ActualApplicationThemeChanged += ViewModel_ActualApplicationThemeChanged;
9697
}
9798

9899
#endregion
@@ -101,7 +102,7 @@ public MainWindow()
101102

102103
#pragma warning disable VSTHRD100 // Avoid async void methods
103104

104-
private void ThemeManager_ActualApplicationThemeChanged(ModernWpf.ThemeManager sender, object args)
105+
private void ViewModel_ActualApplicationThemeChanged(object sender, ActualApplicationThemeChangedEventArgs args)
105106
{
106107
_ = _theme.RefreshFrameAsync();
107108
}
@@ -1351,7 +1352,7 @@ protected virtual void Dispose(bool disposing)
13511352
_notifyIcon?.Dispose();
13521353
animationSoundWMP?.Close();
13531354
animationSoundWPF?.Dispose();
1354-
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
1355+
_viewModel.ActualApplicationThemeChanged -= ViewModel_ActualApplicationThemeChanged;
13551356
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
13561357
}
13571358

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414
using System.Windows.Media;
1515
using CommunityToolkit.Mvvm.DependencyInjection;
1616
using Flow.Launcher.Core;
17+
using Flow.Launcher.Core.ExternalPlugins;
1718
using Flow.Launcher.Core.Plugin;
1819
using Flow.Launcher.Core.Resource;
19-
using Flow.Launcher.Core.ExternalPlugins;
2020
using Flow.Launcher.Core.Storage;
2121
using Flow.Launcher.Helper;
2222
using Flow.Launcher.Infrastructure;
23-
using Flow.Launcher.Infrastructure.Http;
2423
using Flow.Launcher.Infrastructure.Hotkey;
24+
using Flow.Launcher.Infrastructure.Http;
2525
using Flow.Launcher.Infrastructure.Image;
2626
using Flow.Launcher.Infrastructure.Logger;
2727
using Flow.Launcher.Infrastructure.Storage;
2828
using Flow.Launcher.Infrastructure.UserSettings;
2929
using Flow.Launcher.Plugin;
30-
using Flow.Launcher.Plugin.SharedModels;
3130
using Flow.Launcher.Plugin.SharedCommands;
31+
using Flow.Launcher.Plugin.SharedModels;
3232
using Flow.Launcher.ViewModel;
3333
using JetBrains.Annotations;
34+
using ModernWpf;
3435
using Squirrel;
3536
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
3637

@@ -587,6 +588,17 @@ public long StopwatchLogInfo(string className, string message, Action action, [C
587588
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
588589
Stopwatch.InfoAsync(className, message, action, methodName);
589590

591+
public bool IsApplicationDarkTheme()
592+
{
593+
return ThemeManager.Current.ActualApplicationTheme == ApplicationTheme.Dark;
594+
}
595+
596+
public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged
597+
{
598+
add => _mainVM.ActualApplicationThemeChanged += value;
599+
remove => _mainVM.ActualApplicationThemeChanged -= value;
600+
}
601+
590602
#endregion
591603

592604
#region Private Methods

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Flow.Launcher.Plugin.SharedCommands;
2323
using Flow.Launcher.Storage;
2424
using Microsoft.VisualStudio.Threading;
25+
using ModernWpf;
2526

2627
namespace Flow.Launcher.ViewModel
2728
{
@@ -195,6 +196,18 @@ public MainViewModel()
195196

196197
RegisterViewUpdate();
197198
_ = RegisterClockAndDateUpdateAsync();
199+
200+
ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
201+
}
202+
203+
private void ThemeManager_ActualApplicationThemeChanged(ThemeManager sender, object args)
204+
{
205+
ActualApplicationThemeChanged?.Invoke(
206+
Application.Current,
207+
new ActualApplicationThemeChangedEventArgs()
208+
{
209+
IsDark = sender.ActualApplicationTheme == ApplicationTheme.Dark
210+
});
198211
}
199212

200213
private void RegisterViewUpdate()
@@ -821,6 +834,7 @@ private ResultsViewModel SelectedResults
821834
public bool MainWindowVisibilityStatus { get; set; } = true;
822835

823836
public event VisibilityChangedEventHandler VisibilityChanged;
837+
public event ActualApplicationThemeChangedEventHandler ActualApplicationThemeChanged;
824838

825839
public Visibility ClockPanelVisibility { get; set; }
826840
public Visibility SearchIconVisibility { get; set; }
@@ -1975,6 +1989,7 @@ protected virtual void Dispose(bool disposing)
19751989
{
19761990
_resultsViewUpdateTask.Dispose();
19771991
}
1992+
ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
19781993
_disposed = true;
19791994
}
19801995
}

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
104104
.Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories))
105105
.Where(p => p.Enabled)
106106
.Select(p => p.Result(query.Search, Context.API))
107-
.Where(r => r?.Score > 0)
107+
.Where(r => string.IsNullOrEmpty(query.Search) || r?.Score > 0)
108108
.ToList();
109109
}
110110
catch (OperationCanceledException)

Plugins/Flow.Launcher.Plugin.Program/Programs/UWPPackage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public Result Result(string query, IPublicAPI api)
424424
}
425425
}
426426

427-
if (!matchResult.IsSearchPrecisionScoreMet())
427+
if (!matchResult.IsSearchPrecisionScoreMet() && !string.IsNullOrEmpty(query))
428428
return null;
429429

430430
var result = new Result
@@ -468,7 +468,6 @@ public Result Result(string query, IPublicAPI api)
468468
}
469469
};
470470

471-
472471
return result;
473472
}
474473

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public Result Result(string query, IPublicAPI api)
136136

137137
List<string> candidates = new List<string>();
138138

139-
if (!matchResult.IsSearchPrecisionScoreMet())
139+
if (!matchResult.IsSearchPrecisionScoreMet() && !string.IsNullOrEmpty(query))
140140
{
141141
if (ExecutableName != null) // only lnk program will need this one
142142
{

0 commit comments

Comments
 (0)