From 5549165625e36f7b80d636e8e7ee6e44b6020979 Mon Sep 17 00:00:00 2001 From: Carbon Date: Fri, 22 Jan 2021 16:34:21 -0600 Subject: [PATCH] Added a contributors page --- AUCapture-WPF/AUCapture-WPF.csproj | 2 + AUCapture-WPF/Contributors.xaml | 57 +++++++++++++++ AUCapture-WPF/Contributors.xaml.cs | 108 +++++++++++++++++++++++++++++ AUCapture-WPF/Extensions.cs | 35 ++++++++++ AUCapture-WPF/MainWindow.xaml | 18 +++-- AUCapture-WPF/MainWindow.xaml.cs | 6 ++ 6 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 AUCapture-WPF/Contributors.xaml create mode 100644 AUCapture-WPF/Contributors.xaml.cs create mode 100644 AUCapture-WPF/Extensions.cs diff --git a/AUCapture-WPF/AUCapture-WPF.csproj b/AUCapture-WPF/AUCapture-WPF.csproj index 96b52cf7..6c0a1f96 100644 --- a/AUCapture-WPF/AUCapture-WPF.csproj +++ b/AUCapture-WPF/AUCapture-WPF.csproj @@ -43,6 +43,7 @@ + @@ -100,6 +101,7 @@ + diff --git a/AUCapture-WPF/Contributors.xaml b/AUCapture-WPF/Contributors.xaml new file mode 100644 index 00000000..b365aa35 --- /dev/null +++ b/AUCapture-WPF/Contributors.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AUCapture-WPF/Contributors.xaml.cs b/AUCapture-WPF/Contributors.xaml.cs new file mode 100644 index 00000000..2cafcb0c --- /dev/null +++ b/AUCapture-WPF/Contributors.xaml.cs @@ -0,0 +1,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 +{ + /// + /// Interaction logic for Contributors.xaml + /// + public partial class Contributors + { + public Queue RepoContributorsToBeAdded = new(); + public ObservableCollection 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 repoContribs = await client.Repository.GetAllContributors("automuteus", "amonguscapture"); + var tempList = repoContribs.Where(x => x.Id != 49699333).ToList(); + tempList.Shuffle(); + RepoContributorsToBeAdded = new Queue(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); + } + } +} diff --git a/AUCapture-WPF/Extensions.cs b/AUCapture-WPF/Extensions.cs new file mode 100644 index 00000000..d6f0f19c --- /dev/null +++ b/AUCapture-WPF/Extensions.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AUCapture_WPF +{ + public static class ThreadSafeRandom + { + [ThreadStatic] private static Random Local; + + public static Random ThisThreadsRandom + { + get { return Local ?? (Local = new Random(unchecked(Environment.TickCount * 31 + Thread.CurrentThread.ManagedThreadId))); } + } + } + + static class MyExtensions + { + public static void Shuffle(this IList list) + { + int n = list.Count; + while (n > 1) + { + n--; + int k = ThreadSafeRandom.ThisThreadsRandom.Next(n + 1); + T value = list[k]; + list[k] = list[n]; + list[n] = value; + } + } + } +} diff --git a/AUCapture-WPF/MainWindow.xaml b/AUCapture-WPF/MainWindow.xaml index efe37db4..f32c82dd 100644 --- a/AUCapture-WPF/MainWindow.xaml +++ b/AUCapture-WPF/MainWindow.xaml @@ -49,6 +49,15 @@ + + + @@ -183,7 +194,7 @@ @@ -224,16 +235,13 @@ - Waiting for among us - +