-
Notifications
You must be signed in to change notification settings - Fork 91
/
Contributors.xaml.cs
108 lines (97 loc) · 3.54 KB
/
Contributors.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using HandyControl.Controls;
using HandyControl.Data;
using HandyControl.Themes;
using HandyControl.Tools;
using MahApps.Metro.Controls;
using Octokit;
namespace AUCapture_WPF
{
/// <summary>
/// Interaction logic for Contributors.xaml
/// </summary>
public partial class Contributors
{
public Queue<RepositoryContributor> RepoContributorsToBeAdded = new();
public ObservableCollection<RepositoryContributor> CurrentContributors = new();
public Contributors(bool dark)
{
InitializeComponent();
if (dark)
{
SharedResourceDictionary.SharedDictionaries.Clear();
ResourceHelper.GetTheme("HandyTheme", Resources).Skin = SkinType.Dark;
}
DataContext = CurrentContributors;
AddContributors();
}
public async void AddContributors()
{
GitHubClient client = new GitHubClient(new ProductHeaderValue("AmongUsCapture"));
IReadOnlyList<RepositoryContributor> repoContribs = await client.Repository.GetAllContributors("automuteus", "amonguscapture");
var tempList = repoContribs.Where(x => x.Id != 49699333).ToList();
tempList.Shuffle();
RepoContributorsToBeAdded = new Queue<RepositoryContributor>(tempList);
CurrentContributors.Add(RepoContributorsToBeAdded.Dequeue());
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (RepoContributorsToBeAdded.Count != 0)
{
var c = RepoContributorsToBeAdded.Dequeue();
CurrentContributors.Add(c);
Console.WriteLine(c.Login);
}
else
{
var timer = sender as DispatcherTimer;
timer.Stop();
}
}
public static void OpenBrowser(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
// throw
}
}
private void Gravatar_MouseDown(object sender, MouseButtonEventArgs e)
{
var tar = sender as Gravatar;
var tarContext = tar.DataContext as RepositoryContributor;
OpenBrowser(tarContext.HtmlUrl);
}
}
}