From cd9196bb84aaa1a67bc0237e9cdc7efe824fe5f1 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 2 Aug 2024 18:06:45 +0800 Subject: [PATCH] feature: supports get avatar from avatars.githubusercontent.com * move all images to `src/Resources/Images` folder --- src/Models/AvatarManager.cs | 78 +++++++++++++----- src/Models/ExternalMerger.cs | 2 +- src/Models/ExternalTool.cs | 2 +- .../ExternalToolIcons/JetBrains/CL.png | Bin .../ExternalToolIcons/JetBrains/DB.png | Bin .../ExternalToolIcons/JetBrains/DL.png | Bin .../ExternalToolIcons/JetBrains/DS.png | Bin .../ExternalToolIcons/JetBrains/GO.png | Bin .../ExternalToolIcons/JetBrains/JB.png | Bin .../ExternalToolIcons/JetBrains/PC.png | Bin .../ExternalToolIcons/JetBrains/PS.png | Bin .../ExternalToolIcons/JetBrains/PY.png | Bin .../ExternalToolIcons/JetBrains/QA.png | Bin .../ExternalToolIcons/JetBrains/QD.png | Bin .../ExternalToolIcons/JetBrains/RD.png | Bin .../ExternalToolIcons/JetBrains/RM.png | Bin .../ExternalToolIcons/JetBrains/RR.png | Bin .../ExternalToolIcons/JetBrains/WRS.png | Bin .../ExternalToolIcons/JetBrains/WS.png | Bin .../ExternalToolIcons/beyond_compare.png | Bin .../{ => Images}/ExternalToolIcons/codium.png | Bin .../{ => Images}/ExternalToolIcons/fleet.png | Bin .../{ => Images}/ExternalToolIcons/git.png | Bin .../{ => Images}/ExternalToolIcons/kdiff3.png | Bin .../{ => Images}/ExternalToolIcons/meld.png | Bin .../ExternalToolIcons/p4merge.png | Bin .../{ => Images}/ExternalToolIcons/rider.png | Bin .../ExternalToolIcons/sublime_text.png | Bin .../ExternalToolIcons/tortoise_merge.png | Bin .../{ => Images}/ExternalToolIcons/vs.png | Bin .../{ => Images}/ExternalToolIcons/vscode.png | Bin .../ExternalToolIcons/vscode_insiders.png | Bin .../ExternalToolIcons/win_merge.png | Bin .../{ => Images}/ExternalToolIcons/xcode.png | Bin src/Resources/{ => Images}/ShellIcons/cmd.png | Bin .../{ => Images}/ShellIcons/git-bash.png | Bin .../{ => Images}/ShellIcons/pwsh.png | Bin src/Resources/{ => Images}/ShellIcons/wt.png | Bin src/Resources/Images/github.png | Bin 0 -> 4095 bytes src/SourceGit.csproj | 7 +- src/Views/Avatar.cs | 23 +----- src/Views/Preference.axaml | 8 +- 42 files changed, 71 insertions(+), 49 deletions(-) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/CL.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/DB.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/DL.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/DS.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/GO.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/JB.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/PC.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/PS.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/PY.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/QA.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/QD.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/RD.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/RM.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/RR.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/WRS.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/JetBrains/WS.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/beyond_compare.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/codium.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/fleet.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/git.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/kdiff3.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/meld.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/p4merge.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/rider.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/sublime_text.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/tortoise_merge.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/vs.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/vscode.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/vscode_insiders.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/win_merge.png (100%) rename src/Resources/{ => Images}/ExternalToolIcons/xcode.png (100%) rename src/Resources/{ => Images}/ShellIcons/cmd.png (100%) rename src/Resources/{ => Images}/ShellIcons/git-bash.png (100%) rename src/Resources/{ => Images}/ShellIcons/pwsh.png (100%) rename src/Resources/{ => Images}/ShellIcons/wt.png (100%) create mode 100644 src/Resources/Images/github.png diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index ed39bcf7..a380c1bc 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -1,21 +1,26 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Net.Http; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Avalonia.Media.Imaging; +using Avalonia.Platform; using Avalonia.Threading; namespace SourceGit.Models { public interface IAvatarHost { - void OnAvatarResourceChanged(string md5); + void OnAvatarResourceChanged(string email); } - public static class AvatarManager + public static partial class AvatarManager { public static string SelectedServer { @@ -33,29 +38,35 @@ namespace SourceGit.Models { while (true) { - var md5 = null as string; + var email = null as string; lock (_synclock) { foreach (var one in _requesting) { - md5 = one; + email = one; break; } } - if (md5 == null) + if (email == null) { Thread.Sleep(100); continue; } + var md5 = GetEmailHash(email); + var matchGithubUser = REG_GITHUB_USER_EMAIL().Match(email); + var url = matchGithubUser.Success ? + $"https://avatars.githubusercontent.com/{matchGithubUser.Groups[2].Value}" : + $"{SelectedServer}{md5}?d=404"; + var localFile = Path.Combine(_storePath, md5); var img = null as Bitmap; try { var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(2) }; - var task = client.GetAsync($"{SelectedServer}{md5}?d=404"); + var task = client.GetAsync(url); task.Wait(); var rsp = task.Result; @@ -82,13 +93,13 @@ namespace SourceGit.Models lock (_synclock) { - _requesting.Remove(md5); + _requesting.Remove(email); } Dispatcher.UIThread.InvokeAsync(() => { - _resources[md5] = img; - NotifyResourceChanged(md5); + _resources[email] = img; + NotifyResourceChanged(email); }); } }); @@ -104,25 +115,36 @@ namespace SourceGit.Models _avatars.Remove(host); } - public static Bitmap Request(string md5, bool forceRefetch = false) + public static Bitmap Request(string email, bool forceRefetch) { + if (email.Equals("noreply@github.com", StringComparison.Ordinal)) + { + if (_githubEmailAvatar == null) + { + var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/Images/github.png", UriKind.RelativeOrAbsolute)); + _githubEmailAvatar = new Bitmap(icon); + } + + return _githubEmailAvatar; + } + if (forceRefetch) { - if (_resources.ContainsKey(md5)) - _resources.Remove(md5); + if (_resources.ContainsKey(email)) + _resources.Remove(email); - var localFile = Path.Combine(_storePath, md5); + var localFile = Path.Combine(_storePath, GetEmailHash(email)); if (File.Exists(localFile)) File.Delete(localFile); - NotifyResourceChanged(md5); + NotifyResourceChanged(email); } else { - if (_resources.TryGetValue(md5, out var value)) + if (_resources.TryGetValue(email, out var value)) return value; - var localFile = Path.Combine(_storePath, md5); + var localFile = Path.Combine(_storePath, GetEmailHash(email)); if (File.Exists(localFile)) { try @@ -130,7 +152,7 @@ namespace SourceGit.Models using (var stream = File.OpenRead(localFile)) { var img = Bitmap.DecodeToWidth(stream, 128); - _resources.Add(md5, img); + _resources.Add(email, img); return img; } } @@ -143,18 +165,28 @@ namespace SourceGit.Models lock (_synclock) { - if (!_requesting.Contains(md5)) - _requesting.Add(md5); + if (!_requesting.Contains(email)) + _requesting.Add(email); } return null; } - private static void NotifyResourceChanged(string md5) + private static string GetEmailHash(string email) + { + var lowered = email.ToLower(CultureInfo.CurrentCulture).Trim(); + var hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(lowered)); + var builder = new StringBuilder(); + foreach (var c in hash) + builder.Append(c.ToString("x2")); + return builder.ToString(); + } + + private static void NotifyResourceChanged(string email) { foreach (var avatar in _avatars) { - avatar.OnAvatarResourceChanged(md5); + avatar.OnAvatarResourceChanged(email); } } @@ -163,5 +195,9 @@ namespace SourceGit.Models private static readonly List _avatars = new List(); private static readonly Dictionary _resources = new Dictionary(); private static readonly HashSet _requesting = new HashSet(); + + [GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@users\.noreply\.github\.com$")] + private static partial Regex REG_GITHUB_USER_EMAIL(); + private static Bitmap _githubEmailAvatar = null; } } diff --git a/src/Models/ExternalMerger.cs b/src/Models/ExternalMerger.cs index 9a27db0b..9855f9d3 100644 --- a/src/Models/ExternalMerger.cs +++ b/src/Models/ExternalMerger.cs @@ -20,7 +20,7 @@ namespace SourceGit.Models { get { - var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute)); + var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/Images/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute)); return new Bitmap(icon); } } diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index 401fb987..5ea8c744 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -25,7 +25,7 @@ namespace SourceGit.Models try { - var asset = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{icon}.png", + var asset = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/Images/ExternalToolIcons/{icon}.png", UriKind.RelativeOrAbsolute)); IconImage = new Bitmap(asset); } diff --git a/src/Resources/ExternalToolIcons/JetBrains/CL.png b/src/Resources/Images/ExternalToolIcons/JetBrains/CL.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/CL.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/CL.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/DB.png b/src/Resources/Images/ExternalToolIcons/JetBrains/DB.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/DB.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/DB.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/DL.png b/src/Resources/Images/ExternalToolIcons/JetBrains/DL.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/DL.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/DL.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/DS.png b/src/Resources/Images/ExternalToolIcons/JetBrains/DS.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/DS.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/DS.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/GO.png b/src/Resources/Images/ExternalToolIcons/JetBrains/GO.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/GO.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/GO.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/JB.png b/src/Resources/Images/ExternalToolIcons/JetBrains/JB.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/JB.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/JB.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/PC.png b/src/Resources/Images/ExternalToolIcons/JetBrains/PC.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/PC.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/PC.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/PS.png b/src/Resources/Images/ExternalToolIcons/JetBrains/PS.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/PS.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/PS.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/PY.png b/src/Resources/Images/ExternalToolIcons/JetBrains/PY.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/PY.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/PY.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/QA.png b/src/Resources/Images/ExternalToolIcons/JetBrains/QA.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/QA.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/QA.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/QD.png b/src/Resources/Images/ExternalToolIcons/JetBrains/QD.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/QD.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/QD.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/RD.png b/src/Resources/Images/ExternalToolIcons/JetBrains/RD.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/RD.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/RD.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/RM.png b/src/Resources/Images/ExternalToolIcons/JetBrains/RM.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/RM.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/RM.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/RR.png b/src/Resources/Images/ExternalToolIcons/JetBrains/RR.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/RR.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/RR.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/WRS.png b/src/Resources/Images/ExternalToolIcons/JetBrains/WRS.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/WRS.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/WRS.png diff --git a/src/Resources/ExternalToolIcons/JetBrains/WS.png b/src/Resources/Images/ExternalToolIcons/JetBrains/WS.png similarity index 100% rename from src/Resources/ExternalToolIcons/JetBrains/WS.png rename to src/Resources/Images/ExternalToolIcons/JetBrains/WS.png diff --git a/src/Resources/ExternalToolIcons/beyond_compare.png b/src/Resources/Images/ExternalToolIcons/beyond_compare.png similarity index 100% rename from src/Resources/ExternalToolIcons/beyond_compare.png rename to src/Resources/Images/ExternalToolIcons/beyond_compare.png diff --git a/src/Resources/ExternalToolIcons/codium.png b/src/Resources/Images/ExternalToolIcons/codium.png similarity index 100% rename from src/Resources/ExternalToolIcons/codium.png rename to src/Resources/Images/ExternalToolIcons/codium.png diff --git a/src/Resources/ExternalToolIcons/fleet.png b/src/Resources/Images/ExternalToolIcons/fleet.png similarity index 100% rename from src/Resources/ExternalToolIcons/fleet.png rename to src/Resources/Images/ExternalToolIcons/fleet.png diff --git a/src/Resources/ExternalToolIcons/git.png b/src/Resources/Images/ExternalToolIcons/git.png similarity index 100% rename from src/Resources/ExternalToolIcons/git.png rename to src/Resources/Images/ExternalToolIcons/git.png diff --git a/src/Resources/ExternalToolIcons/kdiff3.png b/src/Resources/Images/ExternalToolIcons/kdiff3.png similarity index 100% rename from src/Resources/ExternalToolIcons/kdiff3.png rename to src/Resources/Images/ExternalToolIcons/kdiff3.png diff --git a/src/Resources/ExternalToolIcons/meld.png b/src/Resources/Images/ExternalToolIcons/meld.png similarity index 100% rename from src/Resources/ExternalToolIcons/meld.png rename to src/Resources/Images/ExternalToolIcons/meld.png diff --git a/src/Resources/ExternalToolIcons/p4merge.png b/src/Resources/Images/ExternalToolIcons/p4merge.png similarity index 100% rename from src/Resources/ExternalToolIcons/p4merge.png rename to src/Resources/Images/ExternalToolIcons/p4merge.png diff --git a/src/Resources/ExternalToolIcons/rider.png b/src/Resources/Images/ExternalToolIcons/rider.png similarity index 100% rename from src/Resources/ExternalToolIcons/rider.png rename to src/Resources/Images/ExternalToolIcons/rider.png diff --git a/src/Resources/ExternalToolIcons/sublime_text.png b/src/Resources/Images/ExternalToolIcons/sublime_text.png similarity index 100% rename from src/Resources/ExternalToolIcons/sublime_text.png rename to src/Resources/Images/ExternalToolIcons/sublime_text.png diff --git a/src/Resources/ExternalToolIcons/tortoise_merge.png b/src/Resources/Images/ExternalToolIcons/tortoise_merge.png similarity index 100% rename from src/Resources/ExternalToolIcons/tortoise_merge.png rename to src/Resources/Images/ExternalToolIcons/tortoise_merge.png diff --git a/src/Resources/ExternalToolIcons/vs.png b/src/Resources/Images/ExternalToolIcons/vs.png similarity index 100% rename from src/Resources/ExternalToolIcons/vs.png rename to src/Resources/Images/ExternalToolIcons/vs.png diff --git a/src/Resources/ExternalToolIcons/vscode.png b/src/Resources/Images/ExternalToolIcons/vscode.png similarity index 100% rename from src/Resources/ExternalToolIcons/vscode.png rename to src/Resources/Images/ExternalToolIcons/vscode.png diff --git a/src/Resources/ExternalToolIcons/vscode_insiders.png b/src/Resources/Images/ExternalToolIcons/vscode_insiders.png similarity index 100% rename from src/Resources/ExternalToolIcons/vscode_insiders.png rename to src/Resources/Images/ExternalToolIcons/vscode_insiders.png diff --git a/src/Resources/ExternalToolIcons/win_merge.png b/src/Resources/Images/ExternalToolIcons/win_merge.png similarity index 100% rename from src/Resources/ExternalToolIcons/win_merge.png rename to src/Resources/Images/ExternalToolIcons/win_merge.png diff --git a/src/Resources/ExternalToolIcons/xcode.png b/src/Resources/Images/ExternalToolIcons/xcode.png similarity index 100% rename from src/Resources/ExternalToolIcons/xcode.png rename to src/Resources/Images/ExternalToolIcons/xcode.png diff --git a/src/Resources/ShellIcons/cmd.png b/src/Resources/Images/ShellIcons/cmd.png similarity index 100% rename from src/Resources/ShellIcons/cmd.png rename to src/Resources/Images/ShellIcons/cmd.png diff --git a/src/Resources/ShellIcons/git-bash.png b/src/Resources/Images/ShellIcons/git-bash.png similarity index 100% rename from src/Resources/ShellIcons/git-bash.png rename to src/Resources/Images/ShellIcons/git-bash.png diff --git a/src/Resources/ShellIcons/pwsh.png b/src/Resources/Images/ShellIcons/pwsh.png similarity index 100% rename from src/Resources/ShellIcons/pwsh.png rename to src/Resources/Images/ShellIcons/pwsh.png diff --git a/src/Resources/ShellIcons/wt.png b/src/Resources/Images/ShellIcons/wt.png similarity index 100% rename from src/Resources/ShellIcons/wt.png rename to src/Resources/Images/ShellIcons/wt.png diff --git a/src/Resources/Images/github.png b/src/Resources/Images/github.png new file mode 100644 index 0000000000000000000000000000000000000000..3a7abb16c4e70346536274977c960ac50f3f6c5d GIT binary patch literal 4095 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 JdV}i;{{eKNd=LNt literal 0 HcmV?d00001 diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index ecb55bd2..009d838f 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -29,10 +29,11 @@ - - - + + + + diff --git a/src/Views/Avatar.cs b/src/Views/Avatar.cs index 62c853b7..7daa425a 100644 --- a/src/Views/Avatar.cs +++ b/src/Views/Avatar.cs @@ -1,7 +1,5 @@ using System; using System.Globalization; -using System.Security.Cryptography; -using System.Text; using Avalonia; using Avalonia.Controls; @@ -42,7 +40,7 @@ namespace SourceGit.Views { if (User != null) { - Models.AvatarManager.Request(_emailMD5, true); + Models.AvatarManager.Request(User.Email, true); InvalidateVisual(); } }; @@ -59,7 +57,7 @@ namespace SourceGit.Views return; var corner = (float)Math.Max(2, Bounds.Width / 16); - var img = Models.AvatarManager.Request(_emailMD5); + var img = Models.AvatarManager.Request(User.Email, false); if (img != null) { var rect = new Rect(0, 0, Bounds.Width, Bounds.Height); @@ -74,9 +72,9 @@ namespace SourceGit.Views } } - public void OnAvatarResourceChanged(string md5) + public void OnAvatarResourceChanged(string email) { - if (_emailMD5 == md5) + if (User.Email.Equals(email, StringComparison.Ordinal)) { InvalidateVisual(); } @@ -97,10 +95,7 @@ namespace SourceGit.Views private static void OnUserPropertyChanged(Avatar avatar, AvaloniaPropertyChangedEventArgs e) { if (avatar.User == null) - { - avatar._emailMD5 = null; return; - } var placeholder = string.IsNullOrWhiteSpace(avatar.User.Name) ? "?" : avatar.User.Name.Substring(0, 1); var chars = placeholder.ToCharArray(); @@ -108,15 +103,6 @@ namespace SourceGit.Views foreach (var c in chars) sum += Math.Abs(c); - var lowered = avatar.User.Email.ToLower(CultureInfo.CurrentCulture).Trim(); - var hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(lowered)); - var builder = new StringBuilder(); - foreach (var c in hash) - builder.Append(c.ToString("x2")); - var md5 = builder.ToString(); - if (avatar._emailMD5 == null || avatar._emailMD5 != md5) - avatar._emailMD5 = md5; - avatar._fallbackBrush = new LinearGradientBrush { GradientStops = FALLBACK_GRADIENTS[sum % FALLBACK_GRADIENTS.Length], @@ -139,6 +125,5 @@ namespace SourceGit.Views private FormattedText _fallbackLabel = null; private LinearGradientBrush _fallbackBrush = null; - private string _emailMD5 = null; } } diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 31df2fab..f254a735 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -294,22 +294,22 @@ IsVisible="{OnPlatform False, Windows=True}"> - + - + - + - +