Skip to content

Commit 56536d0

Browse files
committed
Add log for plugin binary storage
1 parent 8cd81b7 commit 56536d0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
using System.IO;
2+
using System.Threading.Tasks;
3+
using CommunityToolkit.Mvvm.DependencyInjection;
4+
using Flow.Launcher.Plugin;
5+
using Flow.Launcher.Plugin.SharedCommands;
26

37
namespace Flow.Launcher.Infrastructure.Storage
48
{
59
public class PluginBinaryStorage<T> : BinaryStorage<T> where T : new()
610
{
11+
private static readonly string ClassName = "PluginBinaryStorage";
12+
13+
// We should not initialize API in static constructor because it will create another API instance
14+
private static IPublicAPI api = null;
15+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
16+
717
public PluginBinaryStorage(string cacheName, string cacheDirectory)
818
{
919
DirectoryPath = cacheDirectory;
10-
Helper.ValidateDirectory(DirectoryPath);
20+
FilesFolders.ValidateDirectory(DirectoryPath);
1121

1222
FilePath = Path.Combine(DirectoryPath, $"{cacheName}{FileSuffix}");
1323
}
24+
25+
public new void Save()
26+
{
27+
try
28+
{
29+
base.Save();
30+
}
31+
catch (System.Exception e)
32+
{
33+
API.LogException(ClassName, $"Failed to save plugin caches to path: {FilePath}", e);
34+
}
35+
}
36+
37+
public new async Task SaveAsync()
38+
{
39+
try
40+
{
41+
await base.SaveAsync();
42+
}
43+
catch (System.Exception e)
44+
{
45+
API.LogException(ClassName, $"Failed to save plugin caches to path: {FilePath}", e);
46+
}
47+
}
1448
}
1549
}

0 commit comments

Comments
 (0)