From 80dfa059cef7e96dbc6411d4c18386a9fa0e0ca6 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Fri, 31 May 2024 00:25:30 +0800 Subject: [PATCH 1/2] feat: add gpg format switcher --- src/Models/GPGFormat.cs | 25 +++++++++++++++ src/Resources/Locales/en_US.axaml | 4 ++- src/Resources/Locales/zh_CN.axaml | 4 ++- src/ViewModels/RepositoryConfigure.cs | 32 +++++++++++++++---- src/Views/Preference.axaml | 46 ++++++++++++++++++++++----- src/Views/Preference.axaml.cs | 36 +++++++++++++++++---- src/Views/RepositoryConfigure.axaml | 34 +++++++++++++++++--- 7 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 src/Models/GPGFormat.cs diff --git a/src/Models/GPGFormat.cs b/src/Models/GPGFormat.cs new file mode 100644 index 00000000..bf3b3678 --- /dev/null +++ b/src/Models/GPGFormat.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace SourceGit.Models +{ + public class GPGFormat(string name, string value, string desc) + { + public string Name { get; set; } = name; + public string Value { get; set; } = value; + public string Desc { get; set; } = desc; + + 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; + } + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 59b22081..4ff2e840 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -310,7 +310,9 @@ Git version Git (>= 2.23.0) is required by this app GPG SIGNING - Commit GPG signing + Commit GPG signing + Tag GPG signing + GPG Format Install Path Input path for installed gpg program User Signing Key diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 5bec8ad7..4dde24da 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -310,7 +310,9 @@ Git 版本 本软件要求GIT最低版本为2.23.0 GPG签名 - 启用提交签名 + 启用提交签名 + 启用标签签名 + GPG签名格式 可执行文件位置 gpg.exe所在路径 用户签名KEY diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 7af0c83f..c1bbdcf5 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -17,7 +17,19 @@ namespace SourceGit.ViewModels set; } - public bool GPGSigningEnabled + public Models.GPGFormat GPGFormat + { + get; + set; + } + + public bool GPGCommitSigningEnabled + { + get; + set; + } + + public bool GPGTagSigningEnabled { get; set; @@ -44,8 +56,14 @@ namespace SourceGit.ViewModels UserName = name; if (_cached.TryGetValue("user.email", out var email)) UserEmail = email; - if (_cached.TryGetValue("commit.gpgsign", out var gpgsign)) - GPGSigningEnabled = gpgsign == "true"; + if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign)) + 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)) @@ -58,20 +76,22 @@ namespace SourceGit.ViewModels { SetIfChanged("user.name", UserName); SetIfChanged("user.email", UserEmail); - SetIfChanged("commit.gpgsign", GPGSigningEnabled ? "true" : "false"); + 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) + private void SetIfChanged(string key, string value, string defaultValue = null) { bool changed = false; if (_cached.TryGetValue(key, out var old)) { changed = old != value; } - else if (!string.IsNullOrEmpty(value)) + else if (!string.IsNullOrEmpty(value) && value != defaultValue) { changed = true; } diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 6500e3e1..a75eece1 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -5,6 +5,7 @@ xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:m="using:SourceGit.Models" xmlns:c="using:SourceGit.Converters" + xmlns:ac="using:Avalonia.Controls.Converters" xmlns:vm="using:SourceGit.ViewModels" xmlns:v="using:SourceGit.Views" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" @@ -403,16 +404,41 @@ + + + + - + + + + + + + + + + + + + - + Text="{Binding #me.GPGExecutableFile, Mode=TwoWay}" + IsEnabled="{Binding #me.GPGFormat, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static m:GPGFormat.OPENPGP}}">