mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
refactor: built-in default avatar
This commit is contained in:
parent
cb3727b524
commit
e4fb9eeb52
2 changed files with 12 additions and 4 deletions
|
@ -35,7 +35,7 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
private static AvatarManager _instance = null;
|
private static AvatarManager _instance = null;
|
||||||
|
|
||||||
[GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@users\.noreply\.github\.com$")]
|
[GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@.+\.github\.com$")]
|
||||||
private static partial Regex REG_GITHUB_USER_EMAIL();
|
private static partial Regex REG_GITHUB_USER_EMAIL();
|
||||||
|
|
||||||
private object _synclock = new object();
|
private object _synclock = new object();
|
||||||
|
@ -43,6 +43,7 @@ namespace SourceGit.Models
|
||||||
private List<IAvatarHost> _avatars = new List<IAvatarHost>();
|
private List<IAvatarHost> _avatars = new List<IAvatarHost>();
|
||||||
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
|
private Dictionary<string, Bitmap> _resources = new Dictionary<string, Bitmap>();
|
||||||
private HashSet<string> _requesting = new HashSet<string>();
|
private HashSet<string> _requesting = new HashSet<string>();
|
||||||
|
private HashSet<string> _defaultAvatars = new HashSet<string>();
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
|
@ -50,8 +51,8 @@ namespace SourceGit.Models
|
||||||
if (!Directory.Exists(_storePath))
|
if (!Directory.Exists(_storePath))
|
||||||
Directory.CreateDirectory(_storePath);
|
Directory.CreateDirectory(_storePath);
|
||||||
|
|
||||||
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/Images/github.png", UriKind.RelativeOrAbsolute));
|
LoadDefaultAvatar("noreply@github.com", "github.png");
|
||||||
_resources.Add("noreply@github.com", new Bitmap(icon));
|
LoadDefaultAvatar("unrealbot@epicgames.com", "unreal.png");
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
@ -140,7 +141,7 @@ namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
if (forceRefetch)
|
if (forceRefetch)
|
||||||
{
|
{
|
||||||
if (email.Equals("noreply@github.com", StringComparison.Ordinal))
|
if (_defaultAvatars.Contains(email))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (_resources.ContainsKey(email))
|
if (_resources.ContainsKey(email))
|
||||||
|
@ -185,6 +186,13 @@ namespace SourceGit.Models
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadDefaultAvatar(string key, string img)
|
||||||
|
{
|
||||||
|
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/Images/{img}", UriKind.RelativeOrAbsolute));
|
||||||
|
_resources.Add(key, new Bitmap(icon));
|
||||||
|
_defaultAvatars.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
private string GetEmailHash(string email)
|
private string GetEmailHash(string email)
|
||||||
{
|
{
|
||||||
var lowered = email.ToLower(CultureInfo.CurrentCulture).Trim();
|
var lowered = email.ToLower(CultureInfo.CurrentCulture).Trim();
|
||||||
|
|
BIN
src/Resources/Images/unreal.png
Normal file
BIN
src/Resources/Images/unreal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in a new issue