Skip to content

Commit 14334b0

Browse files
committed
enhance: do not save gpg.openpgp.program if gpg.program exists and the value has not been changed (#544)
1 parent c8a13bc commit 14334b0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Views/Preference.axaml.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,22 @@ protected override void OnClosing(WindowClosingEventArgs e)
137137
SetIfChanged(config, "gpg.format", GPGFormat.Value, "openpgp");
138138

139139
if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal))
140-
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile, "");
140+
{
141+
var oldGPG = string.Empty;
142+
if (GPGFormat.Value == "openpgp" && config.TryGetValue("gpg.program", out var openpgp))
143+
oldGPG = openpgp;
144+
else if (config.TryGetValue($"gpg.{GPGFormat.Value}.program", out var gpgProgram))
145+
oldGPG = gpgProgram;
146+
147+
bool changed = false;
148+
if (!string.IsNullOrEmpty(oldGPG))
149+
changed = oldGPG != GPGExecutableFile;
150+
else if (!string.IsNullOrEmpty(GPGExecutableFile))
151+
changed = true;
152+
153+
if (changed)
154+
new Commands.Config(null).Set($"gpg.{GPGFormat.Value}.program", GPGExecutableFile);
155+
}
141156

142157
base.OnClosing(e);
143158
}

0 commit comments

Comments
 (0)