Skip to content

Commit c11ee2f

Browse files
committed
Improve code quality & comments & Fix lock issue
1 parent 734c5bb commit c11ee2f

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public BinaryStorage(string filename)
4242

4343
public async ValueTask<T> TryLoadAsync(T defaultData)
4444
{
45-
if (Data != null)
46-
return Data;
45+
if (Data != null) return Data;
4746

4847
if (File.Exists(FilePath))
4948
{
@@ -55,8 +54,7 @@ public async ValueTask<T> TryLoadAsync(T defaultData)
5554
}
5655

5756
await using var stream = new FileStream(FilePath, FileMode.Open);
58-
var d = await DeserializeAsync(stream, defaultData);
59-
Data = d;
57+
Data = await DeserializeAsync(stream, defaultData);
6058
}
6159
else
6260
{

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Flow.Launcher.Infrastructure.Storage
2020

2121
public PluginJsonStorage()
2222
{
23+
// C# related, add python related below
2324
var dataType = typeof(T);
2425
AssemblyName = dataType.Assembly.GetName().Name;
2526
DirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, AssemblyName);

Flow.Launcher.Plugin/Interfaces/ISavable.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
namespace Flow.Launcher.Plugin
22
{
33
/// <summary>
4-
/// Inherit this interface if additional data e.g. cache needs to be saved.
4+
/// Inherit this interface if additional data.
5+
/// If you need to save data which is not a setting or cache,
6+
/// please implement this interface.
57
/// </summary>
68
/// <remarks>
79
/// For storing plugin settings, prefer <see cref="IPublicAPI.LoadSettingJsonStorage{T}"/>
810
/// or <see cref="IPublicAPI.SaveSettingJsonStorage{T}"/>.
11+
/// For storing plugin caches, prefer <see cref="IPublicAPI.LoadCacheBinaryStorageAsync{T}"/>
912
/// or <see cref="IPublicAPI.SaveCacheBinaryStorageAsync{T}(string, string)"/>.
10-
/// Once called, your settings will be automatically saved by Flow.
13+
/// Once called, those settings and caches will be automatically saved by Flow.
1114
/// </remarks>
1215
public interface ISavable : IFeatures
1316
{
1417
/// <summary>
15-
/// Save additional plugin data, such as cache.
18+
/// Save additional plugin data.
1619
/// </summary>
1720
void Save();
1821
}

Flow.Launcher/PublicAPIInstance.cs

-6
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ public void RemovePluginSettings(string assemblyName)
229229
}
230230
}
231231

232-
/// <summary>
233-
/// Save plugin settings.
234-
/// </summary>
235232
public void SavePluginSettings()
236233
{
237234
foreach (var value in _pluginJsonStorages.Values)
@@ -378,9 +375,6 @@ public void RemovePluginCaches(string cacheDirectory)
378375
}
379376
}
380377

381-
/// <summary>
382-
/// Save plugin caches.
383-
/// </summary>
384378
public void SavePluginCaches()
385379
{
386380
foreach (var value in _pluginBinaryStorages.Values)

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

+11-18
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
7777

7878
private static readonly string WindowsAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps");
7979

80-
static Main()
81-
{
82-
}
83-
8480
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
8581
{
8682
var result = await cache.GetOrCreateAsync(query.Search, async entry =>
@@ -101,15 +97,15 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
10197
.ToArray() : null;
10298

10399
return _win32s.Cast<IProgram>()
104-
.Concat(_uwps)
105-
.AsParallel()
106-
.WithCancellation(token)
107-
.Where(HideUninstallersFilter)
108-
.Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories))
109-
.Where(p => p.Enabled)
110-
.Select(p => p.Result(query.Search, Context.API))
111-
.Where(r => r?.Score > 0)
112-
.ToList();
100+
.Concat(_uwps)
101+
.AsParallel()
102+
.WithCancellation(token)
103+
.Where(HideUninstallersFilter)
104+
.Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories))
105+
.Where(p => p.Enabled)
106+
.Select(p => p.Result(query.Search, Context.API))
107+
.Where(r => r?.Score > 0)
108+
.ToList();
113109
}
114110
catch (OperationCanceledException)
115111
{
@@ -193,7 +189,6 @@ public async Task InitAsync(PluginInitContext context)
193189
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
194190
{
195191
var pluginCachePath = Context.CurrentPluginMetadata.PluginCacheDirectoryPath;
196-
197192
FilesFolders.ValidateDirectory(pluginCachePath);
198193

199194
static void MoveFile(string sourcePath, string destinationPath)
@@ -294,10 +289,10 @@ public static async Task IndexWin32ProgramsAsync()
294289
{
295290
_win32s.Add(win32);
296291
}
297-
_win32sLock.Release();
298292
ResetCache();
299293
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
300294
_settings.LastIndexTime = DateTime.Now;
295+
_win32sLock.Release();
301296
}
302297

303298
public static async Task IndexUwpProgramsAsync()
@@ -309,10 +304,10 @@ public static async Task IndexUwpProgramsAsync()
309304
{
310305
_uwps.Add(uwp);
311306
}
312-
_uwpsLock.Release();
313307
ResetCache();
314308
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
315309
_settings.LastIndexTime = DateTime.Now;
310+
_uwpsLock.Release();
316311
}
317312

318313
public static async Task IndexProgramsAsync()
@@ -405,7 +400,6 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
405400
}
406401
else
407402
{
408-
// Release the lock if we cannot find the program
409403
_uwpsLock.Release();
410404
}
411405

@@ -425,7 +419,6 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
425419
}
426420
else
427421
{
428-
// Release the lock if we cannot find the program
429422
_win32sLock.Release();
430423
}
431424
}

0 commit comments

Comments
 (0)