Skip to content

Commit 62e32dc

Browse files
committed
Merge branch 'dev' into 250405-KoreanIME
# Conflicts: # Flow.Launcher/Languages/en.xaml # Flow.Launcher/Resources/Dark.xaml
2 parents 762b267 + 2e740b1 commit 62e32dc

File tree

182 files changed

+3292
-1468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3292
-1468
lines changed

Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Flow.Launcher.Core.Plugin.JsonRPCV2Models
1212
{
1313
public class JsonRPCPublicAPI
1414
{
15-
private IPublicAPI _api;
15+
private readonly IPublicAPI _api;
1616

1717
public JsonRPCPublicAPI(IPublicAPI api)
1818
{
@@ -104,7 +104,6 @@ public List<PluginPair> GetAllPlugins()
104104
return _api.GetAllPlugins();
105105
}
106106

107-
108107
public MatchResult FuzzySearch(string query, string stringToCompare)
109108
{
110109
return _api.FuzzySearch(query, stringToCompare);
@@ -156,6 +155,11 @@ public void LogWarn(string className, string message, [CallerMemberName] string
156155
_api.LogWarn(className, message, methodName);
157156
}
158157

158+
public void LogError(string className, string message, [CallerMemberName] string methodName = "")
159+
{
160+
_api.LogError(className, message, methodName);
161+
}
162+
159163
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
160164
{
161165
_api.OpenDirectory(DirectoryPath, FileNameOrFilePath);
@@ -185,5 +189,10 @@ public void StopLoadingBar()
185189
{
186190
_api.StopLoadingBar();
187191
}
192+
193+
public void SavePluginCaches()
194+
{
195+
_api.SavePluginCaches();
196+
}
188197
}
189198
}

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Flow.Launcher.Infrastructure.UserSettings;
1414
using Flow.Launcher.Plugin;
1515
using Flow.Launcher.Plugin.SharedCommands;
16+
using IRemovable = Flow.Launcher.Core.Storage.IRemovable;
1617
using ISavable = Flow.Launcher.Plugin.ISavable;
1718

1819
namespace Flow.Launcher.Core.Plugin
@@ -22,6 +23,8 @@ namespace Flow.Launcher.Core.Plugin
2223
/// </summary>
2324
public static class PluginManager
2425
{
26+
private static readonly string ClassName = nameof(PluginManager);
27+
2528
private static IEnumerable<PluginPair> _contextMenuPlugins;
2629

2730
public static List<PluginPair> AllPlugins { get; private set; }
@@ -65,6 +68,7 @@ public static void Save()
6568
}
6669

6770
API.SavePluginSettings();
71+
API.SavePluginCaches();
6872
}
6973

7074
public static async ValueTask DisposePluginsAsync()
@@ -192,7 +196,7 @@ public static async Task InitializePluginsAsync()
192196
{
193197
try
194198
{
195-
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
199+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Init method time cost for <{pair.Metadata.Name}>",
196200
() => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API)));
197201

198202
pair.Metadata.InitTime += milliseconds;
@@ -264,7 +268,7 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
264268

265269
try
266270
{
267-
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
271+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
268272
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));
269273

270274
token.ThrowIfCancellationRequested();
@@ -575,11 +579,11 @@ internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool remo
575579

576580
if (removePluginSettings)
577581
{
578-
// For dotnet plugins, we need to remove their PluginJsonStorage instance
579-
if (AllowedLanguage.IsDotNet(plugin.Language))
582+
// For dotnet plugins, we need to remove their PluginJsonStorage and PluginBinaryStorage instances
583+
if (AllowedLanguage.IsDotNet(plugin.Language) && API is IRemovable removable)
580584
{
581-
var method = API.GetType().GetMethod("RemovePluginSettings");
582-
method?.Invoke(API, new object[] { plugin.AssemblyName });
585+
removable.RemovePluginSettings(plugin.AssemblyName);
586+
removable.RemovePluginCaches(plugin.PluginCacheDirectoryPath);
583587
}
584588

585589
try

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
#pragma warning restore IDE0005
1212
using Flow.Launcher.Infrastructure.UserSettings;
1313
using Flow.Launcher.Plugin;
14-
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
1514

1615
namespace Flow.Launcher.Core.Plugin
1716
{
1817
public static class PluginsLoader
1918
{
19+
private static readonly string ClassName = nameof(PluginsLoader);
20+
21+
// We should not initialize API in static constructor because it will create another API instance
22+
private static IPublicAPI api = null;
23+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
24+
2025
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
2126
{
2227
var dotnetPlugins = DotNetPlugins(metadatas);
@@ -59,8 +64,7 @@ private static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source
5964

6065
foreach (var metadata in metadatas)
6166
{
62-
var milliseconds = Stopwatch.Debug(
63-
$"|PluginsLoader.DotNetPlugins|Constructor init cost for {metadata.Name}", () =>
67+
var milliseconds = API.StopwatchLogDebug(ClassName, $"Constructor init cost for {metadata.Name}", () =>
6468
{
6569
Assembly assembly = null;
6670
IAsyncPlugin plugin = null;

Flow.Launcher.Core/Resource/LocalizationConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Flow.Launcher.Core.Resource
88
{
9+
[Obsolete("LocalizationConverter is obsolete. Use with Flow.Launcher.Localization NuGet package instead.")]
910
public class LocalizationConverter : IValueConverter
1011
{
1112
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
using System.ComponentModel;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
3+
using Flow.Launcher.Plugin;
24

35
namespace Flow.Launcher.Core.Resource
46
{
57
public class LocalizedDescriptionAttribute : DescriptionAttribute
68
{
7-
private readonly Internationalization _translator;
9+
// We should not initialize API in static constructor because it will create another API instance
10+
private static IPublicAPI api = null;
11+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
12+
813
private readonly string _resourceKey;
914

1015
public LocalizedDescriptionAttribute(string resourceKey)
1116
{
12-
_translator = InternationalizationManager.Instance;
1317
_resourceKey = resourceKey;
1418
}
1519

1620
public override string Description
1721
{
1822
get
1923
{
20-
string description = _translator.GetTranslation(_resourceKey);
24+
string description = API.GetTranslation(_resourceKey);
2125
return string.IsNullOrWhiteSpace(description) ?
2226
string.Format("[[{0}]]", _resourceKey) : description;
2327
}

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Flow.Launcher.Infrastructure.Logger;
1717
using Flow.Launcher.Infrastructure.UserSettings;
1818
using Flow.Launcher.Plugin;
19+
using Flow.Launcher.Plugin.SharedModels;
1920
using Microsoft.Win32;
2021

2122
namespace Flow.Launcher.Core.Resource
@@ -81,11 +82,6 @@ public Theme(IPublicAPI publicAPI, Settings settings)
8182

8283
#region Theme Resources
8384

84-
public string GetCurrentTheme()
85-
{
86-
return _settings.Theme;
87-
}
88-
8985
private void MakeSureThemeDirectoriesExist()
9086
{
9187
foreach (var dir in _themeDirectories.Where(dir => !Directory.Exists(dir)))
@@ -127,7 +123,7 @@ public void UpdateFonts()
127123
try
128124
{
129125
// Load a ResourceDictionary for the specified theme.
130-
var themeName = GetCurrentTheme();
126+
var themeName = _settings.Theme;
131127
var dict = GetThemeResourceDictionary(themeName);
132128

133129
// Apply font settings to the theme resource.
@@ -330,7 +326,7 @@ private ResourceDictionary GetResourceDictionary(string theme)
330326

331327
private ResourceDictionary GetCurrentResourceDictionary()
332328
{
333-
return GetResourceDictionary(GetCurrentTheme());
329+
return GetResourceDictionary(_settings.Theme);
334330
}
335331

336332
private ThemeData GetThemeDataFromPath(string path)
@@ -383,9 +379,20 @@ private string GetThemePath(string themeName)
383379

384380
#endregion
385381

386-
#region Load & Change
382+
#region Get & Change Theme
383+
384+
public ThemeData GetCurrentTheme()
385+
{
386+
var themes = GetAvailableThemes();
387+
var matchingTheme = themes.FirstOrDefault(t => t.FileNameWithoutExtension == _settings.Theme);
388+
if (matchingTheme == null)
389+
{
390+
Log.Warn($"No matching theme found for '{_settings.Theme}'. Falling back to the first available theme.");
391+
}
392+
return matchingTheme ?? themes.FirstOrDefault();
393+
}
387394

388-
public List<ThemeData> LoadAvailableThemes()
395+
public List<ThemeData> GetAvailableThemes()
389396
{
390397
List<ThemeData> themes = new List<ThemeData>();
391398
foreach (var themeDirectory in _themeDirectories)
@@ -403,7 +410,7 @@ public List<ThemeData> LoadAvailableThemes()
403410
public bool ChangeTheme(string theme = null)
404411
{
405412
if (string.IsNullOrEmpty(theme))
406-
theme = GetCurrentTheme();
413+
theme = _settings.Theme;
407414

408415
string path = GetThemePath(theme);
409416
try
@@ -426,7 +433,7 @@ public bool ChangeTheme(string theme = null)
426433

427434
BlurEnabled = IsBlurTheme();
428435

429-
// Can only apply blur but here also apply drop shadow effect to avoid possible drop shadow effect issues
436+
// Apply blur and drop shadow effect so that we do not need to call it again
430437
_ = RefreshFrameAsync();
431438

432439
return true;
@@ -591,7 +598,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
591598
{
592599
AutoDropShadow(useDropShadowEffect);
593600
}
594-
SetBlurForWindow(GetCurrentTheme(), backdropType);
601+
SetBlurForWindow(_settings.Theme, backdropType);
595602

596603
if (!BlurEnabled)
597604
{
@@ -610,7 +617,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
610617
// Get the actual backdrop type and drop shadow effect settings
611618
var (backdropType, _) = GetActualValue();
612619

613-
SetBlurForWindow(GetCurrentTheme(), backdropType);
620+
SetBlurForWindow(_settings.Theme, backdropType);
614621
}, DispatcherPriority.Render);
615622
}
616623

@@ -898,11 +905,5 @@ private static bool IsBlurTheme()
898905
}
899906

900907
#endregion
901-
902-
#region Classes
903-
904-
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null);
905-
906-
#endregion
907908
}
908909
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
using System;
22
using System.Globalization;
33
using System.Windows.Data;
4+
using CommunityToolkit.Mvvm.DependencyInjection;
5+
using Flow.Launcher.Plugin;
46

57
namespace Flow.Launcher.Core.Resource
68
{
79
public class TranslationConverter : IValueConverter
810
{
11+
// We should not initialize API in static constructor because it will create another API instance
12+
private static IPublicAPI api = null;
13+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
14+
915
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1016
{
1117
var key = value.ToString();
12-
if (String.IsNullOrEmpty(key))
13-
return key;
14-
return InternationalizationManager.Instance.GetTranslation(key);
18+
if (string.IsNullOrEmpty(key)) return key;
19+
return API.GetTranslation(key);
1520
}
1621

17-
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException();
22+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
23+
throw new InvalidOperationException();
1824
}
1925
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Flow.Launcher.Core.Storage;
2+
3+
/// <summary>
4+
/// Remove storage instances from <see cref="Launcher.Plugin.IPublicAPI"/> instance
5+
/// </summary>
6+
public interface IRemovable
7+
{
8+
/// <summary>
9+
/// Remove all <see cref="Infrastructure.Storage.PluginJsonStorage{T}"/> instances of one plugin
10+
/// </summary>
11+
/// <param name="assemblyName"></param>
12+
public void RemovePluginSettings(string assemblyName);
13+
14+
/// <summary>
15+
/// Remove all <see cref="Infrastructure.Storage.PluginBinaryStorage{T}"/> instances of one plugin
16+
/// </summary>
17+
/// <param name="cacheDirectory"></param>
18+
public void RemovePluginCaches(string cacheDirectory);
19+
}

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</PackageReference>
6868
<PackageReference Include="NLog" Version="4.7.10" />
6969
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
70+
<PackageReference Include="SharpVectors.Wpf" Version="1.8.4.2" />
7071
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
7172
<!--ToolGood.Words.Pinyin v3.0.2.6 results in high memory usage when search with pinyin is enabled-->
7273
<!--Bumping to it or higher needs to test and ensure this is no longer a problem-->

Flow.Launcher.Infrastructure/Image/ImageCache.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
2-
using System.Collections.Concurrent;
32
using System.Collections.Generic;
43
using System.Linq;
5-
using System.Threading;
64
using System.Threading.Tasks;
75
using System.Windows.Media;
86
using BitFaster.Caching.Lfu;
@@ -55,7 +53,6 @@ public bool TryGetValue(string key, bool isFullImage, out ImageSource image)
5553
return image != null;
5654
}
5755

58-
5956
image = null;
6057
return false;
6158
}

0 commit comments

Comments
 (0)