mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve code quality & comments & Fix lock issue
This commit is contained in:
parent
734c5bb67d
commit
c11ee2f9e7
5 changed files with 20 additions and 31 deletions
|
|
@ -42,8 +42,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
|
||||
public async ValueTask<T> TryLoadAsync(T defaultData)
|
||||
{
|
||||
if (Data != null)
|
||||
return Data;
|
||||
if (Data != null) return Data;
|
||||
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
|
|
@ -55,8 +54,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
}
|
||||
|
||||
await using var stream = new FileStream(FilePath, FileMode.Open);
|
||||
var d = await DeserializeAsync(stream, defaultData);
|
||||
Data = d;
|
||||
Data = await DeserializeAsync(stream, defaultData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
|
||||
public PluginJsonStorage()
|
||||
{
|
||||
// C# related, add python related below
|
||||
var dataType = typeof(T);
|
||||
AssemblyName = dataType.Assembly.GetName().Name;
|
||||
DirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, AssemblyName);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
namespace Flow.Launcher.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Inherit this interface if additional data e.g. cache needs to be saved.
|
||||
/// Inherit this interface if additional data.
|
||||
/// If you need to save data which is not a setting or cache,
|
||||
/// please implement this interface.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For storing plugin settings, prefer <see cref="IPublicAPI.LoadSettingJsonStorage{T}"/>
|
||||
/// or <see cref="IPublicAPI.SaveSettingJsonStorage{T}"/>.
|
||||
/// For storing plugin caches, prefer <see cref="IPublicAPI.LoadCacheBinaryStorageAsync{T}"/>
|
||||
/// or <see cref="IPublicAPI.SaveCacheBinaryStorageAsync{T}(string, string)"/>.
|
||||
/// Once called, your settings will be automatically saved by Flow.
|
||||
/// Once called, those settings and caches will be automatically saved by Flow.
|
||||
/// </remarks>
|
||||
public interface ISavable : IFeatures
|
||||
{
|
||||
/// <summary>
|
||||
/// Save additional plugin data, such as cache.
|
||||
/// Save additional plugin data.
|
||||
/// </summary>
|
||||
void Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,6 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save plugin settings.
|
||||
/// </summary>
|
||||
public void SavePluginSettings()
|
||||
{
|
||||
foreach (var value in _pluginJsonStorages.Values)
|
||||
|
|
@ -378,9 +375,6 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save plugin caches.
|
||||
/// </summary>
|
||||
public void SavePluginCaches()
|
||||
{
|
||||
foreach (var value in _pluginBinaryStorages.Values)
|
||||
|
|
|
|||
|
|
@ -77,10 +77,6 @@ namespace Flow.Launcher.Plugin.Program
|
|||
|
||||
private static readonly string WindowsAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps");
|
||||
|
||||
static Main()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
|
||||
{
|
||||
var result = await cache.GetOrCreateAsync(query.Search, async entry =>
|
||||
|
|
@ -101,15 +97,15 @@ namespace Flow.Launcher.Plugin.Program
|
|||
.ToArray() : null;
|
||||
|
||||
return _win32s.Cast<IProgram>()
|
||||
.Concat(_uwps)
|
||||
.AsParallel()
|
||||
.WithCancellation(token)
|
||||
.Where(HideUninstallersFilter)
|
||||
.Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories))
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, Context.API))
|
||||
.Where(r => r?.Score > 0)
|
||||
.ToList();
|
||||
.Concat(_uwps)
|
||||
.AsParallel()
|
||||
.WithCancellation(token)
|
||||
.Where(HideUninstallersFilter)
|
||||
.Where(p => HideDuplicatedWindowsAppFilter(p, uwpsDirectories))
|
||||
.Where(p => p.Enabled)
|
||||
.Select(p => p.Result(query.Search, Context.API))
|
||||
.Where(r => r?.Score > 0)
|
||||
.ToList();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
|
@ -193,7 +189,6 @@ namespace Flow.Launcher.Plugin.Program
|
|||
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
|
||||
{
|
||||
var pluginCachePath = Context.CurrentPluginMetadata.PluginCacheDirectoryPath;
|
||||
|
||||
FilesFolders.ValidateDirectory(pluginCachePath);
|
||||
|
||||
static void MoveFile(string sourcePath, string destinationPath)
|
||||
|
|
@ -294,10 +289,10 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
_win32s.Add(win32);
|
||||
}
|
||||
_win32sLock.Release();
|
||||
ResetCache();
|
||||
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
|
||||
_settings.LastIndexTime = DateTime.Now;
|
||||
_win32sLock.Release();
|
||||
}
|
||||
|
||||
public static async Task IndexUwpProgramsAsync()
|
||||
|
|
@ -309,10 +304,10 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
_uwps.Add(uwp);
|
||||
}
|
||||
_uwpsLock.Release();
|
||||
ResetCache();
|
||||
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
|
||||
_settings.LastIndexTime = DateTime.Now;
|
||||
_uwpsLock.Release();
|
||||
}
|
||||
|
||||
public static async Task IndexProgramsAsync()
|
||||
|
|
@ -405,7 +400,6 @@ namespace Flow.Launcher.Plugin.Program
|
|||
}
|
||||
else
|
||||
{
|
||||
// Release the lock if we cannot find the program
|
||||
_uwpsLock.Release();
|
||||
}
|
||||
|
||||
|
|
@ -425,7 +419,6 @@ namespace Flow.Launcher.Plugin.Program
|
|||
}
|
||||
else
|
||||
{
|
||||
// Release the lock if we cannot find the program
|
||||
_win32sLock.Release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue