Merge pull request #2430 from Flow-Launcher/Allow-SettingsChange-without-template-file

Improve JsonRPC plugin settings
This commit is contained in:
Garulf 2023-11-21 16:50:58 -05:00 committed by GitHub
commit 851df97649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View file

@ -126,14 +126,15 @@ namespace Flow.Launcher.Core.Plugin
private async Task InitSettingAsync()
{
if (!File.Exists(SettingConfigurationPath))
return;
JsonRpcConfigurationModel configuration = null;
if (File.Exists(SettingConfigurationPath))
{
var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
configuration =
deserializer.Deserialize<JsonRpcConfigurationModel>(
await File.ReadAllTextAsync(SettingConfigurationPath));
}
var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();
var configuration =
deserializer.Deserialize<JsonRpcConfigurationModel>(
await File.ReadAllTextAsync(SettingConfigurationPath));
Settings ??= new JsonRPCPluginSettings
{

View file

@ -11,7 +11,7 @@ namespace Flow.Launcher.Core.Plugin
{
public class JsonRPCPluginSettings
{
public required JsonRpcConfigurationModel Configuration { get; init; }
public required JsonRpcConfigurationModel? Configuration { get; init; }
public required string SettingPath { get; init; }
public Dictionary<string, FrameworkElement> SettingControls { get; } = new();
@ -37,6 +37,11 @@ namespace Flow.Launcher.Core.Plugin
_storage = new JsonStorage<ConcurrentDictionary<string, object>>(SettingPath);
Settings = await _storage.LoadAsync();
if (Settings != null)
{
return;
}
foreach (var (type, attributes) in Configuration.Body)
{
if (attributes.Name == null)
@ -59,10 +64,7 @@ namespace Flow.Launcher.Core.Plugin
foreach (var (key, value) in settings)
{
if (Settings.ContainsKey(key))
{
Settings[key] = value;
}
Settings[key] = value;
if (SettingControls.TryGetValue(key, out var control))
{
@ -83,6 +85,7 @@ namespace Flow.Launcher.Core.Plugin
}
}
}
Save();
}
public async Task SaveAsync()