From 4b0af79f7388702fd9fcaf426d6defbef1472feb Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 4 Jun 2024 10:20:31 +0800 Subject: [PATCH] enhance: GPG signing settings. * remove gpg format settings from repository's local setting * add support for X.509 format * ux style --- src/Models/GPGFormat.cs | 22 ++++++++------------- src/Resources/Locales/en_US.axaml | 2 +- src/Resources/Locales/zh_CN.axaml | 6 +++--- src/ViewModels/RepositoryConfigure.cs | 15 ++------------ src/Views/Preference.axaml | 10 ++++++---- src/Views/Preference.axaml.cs | 26 ++++++++++++------------- src/Views/RepositoryConfigure.axaml | 28 ++++----------------------- 7 files changed, 37 insertions(+), 72 deletions(-) diff --git a/src/Models/GPGFormat.cs b/src/Models/GPGFormat.cs index bf3b3678..0ba4e9e2 100644 --- a/src/Models/GPGFormat.cs +++ b/src/Models/GPGFormat.cs @@ -2,24 +2,18 @@ namespace SourceGit.Models { - public class GPGFormat(string name, string value, string desc) + public class GPGFormat(string name, string value, string desc, string program, bool needFindProgram) { public string Name { get; set; } = name; public string Value { get; set; } = value; public string Desc { get; set; } = desc; + public string Program { get; set; } = program; + public bool NeedFindProgram { get; set; } = needFindProgram; - public static readonly GPGFormat OPENPGP = new GPGFormat("OPENPGP", "openpgp", "DEFAULT"); - - public static readonly GPGFormat SSH = new GPGFormat("SSH", "ssh", "Git >= 2.34.0"); - - public static readonly List Supported = new List() { - OPENPGP, - SSH, - }; - - public bool Equals(GPGFormat other) - { - return Value == other.Value; - } + public static readonly List Supported = [ + new GPGFormat("OPENPGP", "openpgp", "DEFAULT", "gpg", true), + new GPGFormat("X.509", "x509", "", "gpgsm", true), + new GPGFormat("SSH", "ssh", "Requires Git >= 2.34.0", "ssh-keygen", false), + ]; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index edf3fe1a..b5a96ecd 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -314,7 +314,7 @@ Commit GPG signing Tag GPG signing GPG Format - Install Path + Program Install Path Input path for installed gpg program User Signing Key User's gpg signing key diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 015cb6cc..f1c5a95f 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -316,9 +316,9 @@ GPG签名 启用提交签名 启用标签签名 - GPG签名格式 - 可执行文件位置 - gpg.exe所在路径 + 签名格式 + 签名程序位置 + 签名程序所在路径 用户签名KEY 输入签名提交所使用的KEY 外部合并工具 diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index c1bbdcf5..1409dfa2 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -17,12 +17,6 @@ namespace SourceGit.ViewModels set; } - public Models.GPGFormat GPGFormat - { - get; - set; - } - public bool GPGCommitSigningEnabled { get; @@ -60,10 +54,6 @@ namespace SourceGit.ViewModels GPGCommitSigningEnabled = gpgCommitSign == "true"; if (_cached.TryGetValue("tag.gpgSign", out var gpgTagSign)) GPGTagSigningEnabled = gpgTagSign == "true"; - if (_cached.TryGetValue("gpg.format", out var gpgFormat)) - GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat); - else - GPGFormat = Models.GPGFormat.OPENPGP; if (_cached.TryGetValue("user.signingkey", out var signingKey)) GPGUserSigningKey = signingKey; if (_cached.TryGetValue("http.proxy", out var proxy)) @@ -78,20 +68,19 @@ namespace SourceGit.ViewModels SetIfChanged("user.email", UserEmail); SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false"); SetIfChanged("tag.gpgSign", GPGTagSigningEnabled ? "true" : "false"); - SetIfChanged("gpg.format", GPGFormat?.Value, Models.GPGFormat.OPENPGP.Value); SetIfChanged("user.signingkey", GPGUserSigningKey); SetIfChanged("http.proxy", HttpProxy); return null; } - private void SetIfChanged(string key, string value, string defaultValue = null) + private void SetIfChanged(string key, string value) { bool changed = false; if (_cached.TryGetValue(key, out var old)) { changed = old != value; } - else if (!string.IsNullOrEmpty(value) && value != defaultValue) + else if (!string.IsNullOrEmpty(value)) { changed = true; } diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 46279470..ab11cca3 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -409,7 +409,7 @@ - + + SelectedItem="{Binding #me.GPGFormat, Mode=TwoWay}"> @@ -433,12 +433,14 @@ + Margin="0,0,16,0" + IsVisible="{Binding #me.GPGFormat.NeedFindProgram}"/> + Watermark="{DynamicResource Text.Preference.GPG.Path.Placeholder}" + IsVisible="{Binding #me.GPGFormat.NeedFindProgram}">