Skip to content

Commit

Permalink
update ui
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed May 21, 2020
1 parent b8e9828 commit 733a41d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
4 changes: 2 additions & 2 deletions GitHubNotifier/DataTypes/RepositorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public RepositorySettings()
{
Enabled = true;
}
public RepositorySettings(string displayName, string repoName):this()
public RepositorySettings(string displayName, string repoName,int updateMinutes):this()
{
DisplayName = displayName;
RepoName = repoName;
UpdateMinutes = 30;
UpdateMinutes = updateMinutes;
}

public override string ToString()
Expand Down
44 changes: 42 additions & 2 deletions GitHubNotifier/Forms/UserSettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion GitHubNotifier/Forms/UserSettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void btnAddRepo_Click(object sender, System.EventArgs e)
{
if (!string.IsNullOrEmpty(txtbRepoDisplayName.Text) && !string.IsNullOrEmpty(txtbRepoName.Text))
{
UserSettingsManager.Instance.AddNewRepository(txtbRepoDisplayName.Text, txtbRepoName.Text);
UserSettingsManager.Instance.AddNewRepository(txtbRepoDisplayName.Text, txtbRepoName.Text,(int)nudMinutes.Value);
RefreshList();
}
}
Expand Down
2 changes: 1 addition & 1 deletion GitHubNotifier/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)

private async void MainForm_Load(object sender, EventArgs e)
{
var result = await GitHubUtils.GetRateLimit(Environment.GetEnvironmentVariable("GitHubNotifier_Token"));
var result = await GitHubUtils.GetRateLimit(UserSettingsManager.Instance.GitHubToken);
tsslblAPILimit.Text = "Api Limits:" + result.Rate;
foreach (RepositorySettings repo in UserSettingsManager.Instance.Repositories)
{
Expand Down
10 changes: 5 additions & 5 deletions GitHubNotifier/Managers/UserSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UserSettingsManager
public static UserSettingsManager Instance { get; set; } = _instance.Value;

public List<RepositorySettings> Repositories { get; set; }

public string GitHubToken { get; } = Environment.GetEnvironmentVariable("GitHubNotifier_Token");
private UserSettingsManager()
{
Load();
Expand All @@ -35,16 +35,16 @@ private void Load()
{
Repositories = new List<RepositorySettings>
{
new RepositorySettings("Analogy Log Viewer","Analogy-LogViewer/Analogy.LogViewer"),
new RepositorySettings("Analogy Serilog", "Analogy-LogViewer/Analogy.LogViewer.Serilog")
new RepositorySettings("Analogy Log Viewer","Analogy-LogViewer/Analogy.LogViewer",15),
new RepositorySettings("Analogy Serilog", "Analogy-LogViewer/Analogy.LogViewer.Serilog",15)
};
}

}

internal void AddNewRepository(string displayName, string id)
internal void AddNewRepository(string displayName, string id, int updateInterval)
{
Repositories.Add(new RepositorySettings(displayName, id));
Repositories.Add(new RepositorySettings(displayName, id,updateInterval));
}
internal void RemoveRepository(RepositorySettings repo) => Repositories.Remove(repo);
public void Save()
Expand Down
11 changes: 7 additions & 4 deletions GitHubNotifier/UserControls/RepositoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitHubNotifier.Managers;

namespace GitHubNotifier
{
Expand All @@ -20,6 +21,7 @@ public RepositoryEntry(RepositorySettings repo) : this()
{
Repo = repo;
lnkLabel.Text = repo.RepoUrl;
timerUpdate.Interval = repo.UpdateMinutes * 60 * 1000;
}

private async void RepositoryEntry_Load(object sender, EventArgs e)
Expand All @@ -33,13 +35,14 @@ public async Task Check()
}
public async Task CheckDownloads()
{
var entries = (await GitHubUtils.GetAsync<GithubReleaseEntry[]>(Repo.RepoApiReleasesUrl)).OrderByDescending(r => r.Published).ToList();

var entries = (await GitHubUtils.GetAsync<GithubReleaseEntry[]>(Repo.RepoApiReleasesUrl, UserSettingsManager.Instance.GitHubToken)).OrderByDescending(r => r.Published).ToList();
var downloads = entries.SelectMany(entry => entry.Assets).Sum(a => a.Downloads);
if (Repo.LastTotalDownloads != downloads)
{
PopupMessage msg = new PopupMessage
{
Caption = Name,
Caption = Repo.DisplayName,
Text = lblDownloads.Text,
Image = Properties.Resources.Download_32x32
};
Expand All @@ -58,12 +61,12 @@ public async Task CheckDownloads()
}
public async Task CheckStars()
{
var repoInfo = await GitHubUtils.GetAsync<GithubRepo>(Repo.RepoApiUrl);
var repoInfo = await GitHubUtils.GetAsync<GithubRepo>(Repo.RepoApiUrl, UserSettingsManager.Instance.GitHubToken);
if (Repo.LastTotalStars != repoInfo.Stargazers)
{
PopupMessage msg = new PopupMessage
{
Caption = Name,
Caption = Repo.DisplayName,
Text = "Likes: " + repoInfo.Stargazers,
Image = Properties.Resources.Feature_32x32
};
Expand Down
4 changes: 2 additions & 2 deletions GitHubNotifier/Utils/GitHubUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitHubNotifier.Utils
{
public static class GitHubUtils
{
public static async Task<GitHubRateLimit> GetRateLimit(string token = null)
public static async Task<GitHubRateLimit> GetRateLimit(string token)
{
string uri = "https://api.github.com/rate_limit";
using (HttpClient client = new HttpClient())
Expand All @@ -26,7 +26,7 @@ public static async Task<GitHubRateLimit> GetRateLimit(string token = null)
}
}

public static async Task<T> GetAsync<T>(string uri, string token = null)
public static async Task<T> GetAsync<T>(string uri, string token)
{
using (HttpClient client = new HttpClient())
{
Expand Down

0 comments on commit 733a41d

Please sign in to comment.