Skip to content

Commit 851df97

Browse files
authored
Merge pull request #2430 from Flow-Launcher/Allow-SettingsChange-without-template-file
Improve JsonRPC plugin settings
2 parents 5351e57 + 9275421 commit 851df97

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ protected void ExecuteFlowLauncherAPI(string method, object[] parameters)
126126

127127
private async Task InitSettingAsync()
128128
{
129-
if (!File.Exists(SettingConfigurationPath))
130-
return;
129+
JsonRpcConfigurationModel configuration = null;
130+
if (File.Exists(SettingConfigurationPath))
131+
{
132+
var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
133+
configuration =
134+
deserializer.Deserialize<JsonRpcConfigurationModel>(
135+
await File.ReadAllTextAsync(SettingConfigurationPath));
136+
}
131137

132-
var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance)
133-
.Build();
134-
var configuration =
135-
deserializer.Deserialize<JsonRpcConfigurationModel>(
136-
await File.ReadAllTextAsync(SettingConfigurationPath));
137138

138139
Settings ??= new JsonRPCPluginSettings
139140
{

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Flow.Launcher.Core.Plugin
1111
{
1212
public class JsonRPCPluginSettings
1313
{
14-
public required JsonRpcConfigurationModel Configuration { get; init; }
14+
public required JsonRpcConfigurationModel? Configuration { get; init; }
1515

1616
public required string SettingPath { get; init; }
1717
public Dictionary<string, FrameworkElement> SettingControls { get; } = new();
@@ -37,6 +37,11 @@ public async Task InitializeAsync()
3737
_storage = new JsonStorage<ConcurrentDictionary<string, object>>(SettingPath);
3838
Settings = await _storage.LoadAsync();
3939

40+
if (Settings != null)
41+
{
42+
return;
43+
}
44+
4045
foreach (var (type, attributes) in Configuration.Body)
4146
{
4247
if (attributes.Name == null)
@@ -59,10 +64,7 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
5964

6065
foreach (var (key, value) in settings)
6166
{
62-
if (Settings.ContainsKey(key))
63-
{
64-
Settings[key] = value;
65-
}
67+
Settings[key] = value;
6668

6769
if (SettingControls.TryGetValue(key, out var control))
6870
{
@@ -83,6 +85,7 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
8385
}
8486
}
8587
}
88+
Save();
8689
}
8790

8891
public async Task SaveAsync()

0 commit comments

Comments
 (0)