mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Move storage to api call for websearch and calculator plugins
This commit is contained in:
parent
a9695e3119
commit
358460cb22
6 changed files with 15 additions and 25 deletions
|
|
@ -9,7 +9,7 @@ namespace Flow.Launcher.Infrastructure.Storage
|
|||
{
|
||||
// C# related, add python related below
|
||||
var dataType = typeof(T);
|
||||
var assemblyName = typeof(T).Assembly.GetName().Name;
|
||||
var assemblyName = dataType.Assembly.GetName().Name;
|
||||
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, assemblyName);
|
||||
Helper.ValidateDirectory(DirectoryPath);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ namespace Flow.Launcher.Plugin.Caculator
|
|||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Context = context;
|
||||
|
||||
_viewModel = new SettingsViewModel();
|
||||
_settings = _viewModel.Settings;
|
||||
_settings = context.API.LoadJsonStorage<Settings>();
|
||||
_viewModel = new SettingsViewModel(_settings);
|
||||
|
||||
MagesEngine = new Engine(new Configuration
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,15 +10,12 @@ namespace Flow.Launcher.Plugin.Caculator.ViewModels
|
|||
{
|
||||
public class SettingsViewModel : BaseModel
|
||||
{
|
||||
private readonly PluginJsonStorage<Settings> _storage;
|
||||
|
||||
public SettingsViewModel()
|
||||
public SettingsViewModel(Settings settings)
|
||||
{
|
||||
_storage = new PluginJsonStorage<Settings>();
|
||||
Settings = _storage.Load();
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
public Settings Settings { get; init; }
|
||||
|
||||
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
|
|||
{
|
||||
internal class SettingsViewModel
|
||||
{
|
||||
private readonly PluginJsonStorage<Settings> storage;
|
||||
|
||||
internal Settings Settings { get; set; }
|
||||
|
||||
internal PluginInitContext Context { get; set; }
|
||||
|
|
@ -14,7 +12,6 @@ namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
|
|||
public SettingsViewModel(PluginInitContext context, Settings settings)
|
||||
{
|
||||
Context = context;
|
||||
storage = new PluginJsonStorage<Settings>();
|
||||
Settings = settings;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
{
|
||||
private PluginInitContext _context;
|
||||
|
||||
private readonly Settings _settings;
|
||||
private readonly SettingsViewModel _viewModel;
|
||||
private Settings _settings;
|
||||
private SettingsViewModel _viewModel;
|
||||
|
||||
internal const string Images = "Images";
|
||||
internal static string DefaultImagesDirectory;
|
||||
|
|
@ -160,12 +160,6 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
return new List<Result>();
|
||||
}
|
||||
|
||||
public Main()
|
||||
{
|
||||
_viewModel = new SettingsViewModel();
|
||||
_settings = _viewModel.Settings;
|
||||
}
|
||||
|
||||
public Task InitAsync(PluginInitContext context)
|
||||
{
|
||||
return Task.Run(Init);
|
||||
|
|
@ -173,6 +167,10 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
void Init()
|
||||
{
|
||||
_context = context;
|
||||
|
||||
_settings = _context.API.LoadJsonStorage<Settings>();
|
||||
_viewModel = new SettingsViewModel(_settings);
|
||||
|
||||
var pluginDirectory = _context.CurrentPluginMetadata.PluginDirectory;
|
||||
var bundledImagesDirectory = Path.Combine(pluginDirectory, Images);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ namespace Flow.Launcher.Plugin.WebSearch
|
|||
{
|
||||
private readonly PluginJsonStorage<Settings> _storage;
|
||||
|
||||
public SettingsViewModel()
|
||||
public SettingsViewModel(Settings settings)
|
||||
{
|
||||
_storage = new PluginJsonStorage<Settings>();
|
||||
Settings = _storage.Load();
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
public Settings Settings { get; }
|
||||
|
||||
public void Save()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue