Flow.Launcher/Flow.Launcher.Infrastructure/Storage/FlowLauncherJsonStorage.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2023-04-25 12:04:08 +00:00
using System.IO;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.DependencyInjection;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
2025-04-04 03:46:07 +00:00
using Flow.Launcher.Plugin.SharedCommands;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Infrastructure.Storage
{
2021-05-11 19:10:03 +00:00
public class FlowLauncherJsonStorage<T> : JsonStorage<T> where T : new()
{
private static readonly string ClassName = "FlowLauncherJsonStorage";
// We should not initialize API in static constructor because it will create another API instance
private static IPublicAPI api = null;
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
2020-04-21 12:16:10 +00:00
public FlowLauncherJsonStorage()
{
var directoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName);
FilesFolders.ValidateDirectory(directoryPath);
var filename = typeof(T).Name;
FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}");
}
public new void Save()
{
try
{
base.Save();
}
catch (System.Exception e)
{
API.LogException(ClassName, $"Failed to save FL settings to path: {FilePath}", e);
}
}
public new async Task SaveAsync()
{
try
{
await base.SaveAsync();
}
catch (System.Exception e)
{
API.LogException(ClassName, $"Failed to save FL settings to path: {FilePath}", e);
}
}
}
}