Skip to content

Commit 358460c

Browse files
committed
Move storage to api call for websearch and calculator plugins
1 parent a9695e3 commit 358460c

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public PluginJsonStorage()
99
{
1010
// C# related, add python related below
1111
var dataType = typeof(T);
12-
var assemblyName = typeof(T).Assembly.GetName().Name;
12+
var assemblyName = dataType.Assembly.GetName().Name;
1313
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, assemblyName);
1414
Helper.ValidateDirectory(DirectoryPath);
1515

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
3333
public void Init(PluginInitContext context)
3434
{
3535
Context = context;
36-
37-
_viewModel = new SettingsViewModel();
38-
_settings = _viewModel.Settings;
36+
_settings = context.API.LoadJsonStorage<Settings>();
37+
_viewModel = new SettingsViewModel(_settings);
3938

4039
MagesEngine = new Engine(new Configuration
4140
{

Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ namespace Flow.Launcher.Plugin.Caculator.ViewModels
1010
{
1111
public class SettingsViewModel : BaseModel
1212
{
13-
private readonly PluginJsonStorage<Settings> _storage;
14-
15-
public SettingsViewModel()
13+
public SettingsViewModel(Settings settings)
1614
{
17-
_storage = new PluginJsonStorage<Settings>();
18-
Settings = _storage.Load();
15+
Settings = settings;
1916
}
2017

21-
public Settings Settings { get; set; }
18+
public Settings Settings { get; init; }
2219

2320
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
2421
}

Plugins/Flow.Launcher.Plugin.PluginsManager/ViewModels/SettingsViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
55
{
66
internal class SettingsViewModel
77
{
8-
private readonly PluginJsonStorage<Settings> storage;
9-
108
internal Settings Settings { get; set; }
119

1210
internal PluginInitContext Context { get; set; }
1311

1412
public SettingsViewModel(PluginInitContext context, Settings settings)
1513
{
1614
Context = context;
17-
storage = new PluginJsonStorage<Settings>();
1815
Settings = settings;
1916
}
2017
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, IResultUpdated
1818
{
1919
private PluginInitContext _context;
2020

21-
private readonly Settings _settings;
22-
private readonly SettingsViewModel _viewModel;
21+
private Settings _settings;
22+
private SettingsViewModel _viewModel;
2323

2424
internal const string Images = "Images";
2525
internal static string DefaultImagesDirectory;
@@ -160,19 +160,17 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
160160
return new List<Result>();
161161
}
162162

163-
public Main()
164-
{
165-
_viewModel = new SettingsViewModel();
166-
_settings = _viewModel.Settings;
167-
}
168-
169163
public Task InitAsync(PluginInitContext context)
170164
{
171165
return Task.Run(Init);
172166

173167
void Init()
174168
{
175169
_context = context;
170+
171+
_settings = _context.API.LoadJsonStorage<Settings>();
172+
_viewModel = new SettingsViewModel(_settings);
173+
176174
var pluginDirectory = _context.CurrentPluginMetadata.PluginDirectory;
177175
var bundledImagesDirectory = Path.Combine(pluginDirectory, Images);
178176

Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ public class SettingsViewModel
66
{
77
private readonly PluginJsonStorage<Settings> _storage;
88

9-
public SettingsViewModel()
9+
public SettingsViewModel(Settings settings)
1010
{
11-
_storage = new PluginJsonStorage<Settings>();
12-
Settings = _storage.Load();
11+
Settings = settings;
1312
}
1413

15-
public Settings Settings { get; set; }
14+
public Settings Settings { get; }
1615

1716
public void Save()
1817
{

0 commit comments

Comments
 (0)