mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2430 from Flow-Launcher/Allow-SettingsChange-without-template-file
Improve JsonRPC plugin settings
This commit is contained in:
commit
851df97649
2 changed files with 16 additions and 12 deletions
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue