diff --git a/Livestream.Monitor/Livestream.Monitor.csproj b/Livestream.Monitor/Livestream.Monitor.csproj
index 7ff22d7..88cb85a 100644
--- a/Livestream.Monitor/Livestream.Monitor.csproj
+++ b/Livestream.Monitor/Livestream.Monitor.csproj
@@ -59,6 +59,10 @@
..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
True
+
+ ..\packages\Octokit.0.16.0\lib\net45\Octokit.dll
+ True
+
diff --git a/Livestream.Monitor/Properties/AssemblyInfo.cs b/Livestream.Monitor/Properties/AssemblyInfo.cs
index f7f3823..ce42c5e 100644
--- a/Livestream.Monitor/Properties/AssemblyInfo.cs
+++ b/Livestream.Monitor/Properties/AssemblyInfo.cs
@@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.1.5.0")]
-[assembly: AssemblyFileVersion("1.1.5.0")]
+[assembly: AssemblyVersion("1.2.0.0")]
+[assembly: AssemblyFileVersion("1.2.0.0")]
diff --git a/Livestream.Monitor/ViewModels/ShellViewModel.cs b/Livestream.Monitor/ViewModels/ShellViewModel.cs
index ced93af..55f50b9 100644
--- a/Livestream.Monitor/ViewModels/ShellViewModel.cs
+++ b/Livestream.Monitor/ViewModels/ShellViewModel.cs
@@ -1,14 +1,24 @@
using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Threading.Tasks;
using System.Windows;
using Caliburn.Micro;
using Hardcodet.Wpf.TaskbarNotification;
+using Livestream.Monitor.Core;
using MahApps.Metro.Controls;
+using MahApps.Metro.Controls.Dialogs;
+using Octokit;
+using Application = System.Windows.Application;
namespace Livestream.Monitor.ViewModels
{
public class ShellViewModel : Conductor.Collection.OneActive
{
public const string TrayIconControlName = "TrayIcon";
+
+ private readonly Version currentAppVersion;
private WindowState windowState = WindowState.Normal;
private TaskbarIcon taskbarIcon;
private bool firstMinimize = true;
@@ -40,8 +50,8 @@ public ShellViewModel(
Settings.ActivateWith(this);
ThemeSelector.ActivateWith(this);
- var assemblyVersion = GetType().Assembly.GetName().Version;
- DisplayName = $"LIVESTREAM MONITOR V{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}";
+ currentAppVersion = GetType().Assembly.GetName().Version;
+ DisplayName = $"LIVESTREAM MONITOR V{currentAppVersion.Major}.{currentAppVersion.Minor}.{currentAppVersion.Build}";
}
public override string DisplayName { get; set; }
@@ -96,16 +106,73 @@ private void WindowMinimized()
}
}
- protected override void OnViewLoaded(object view)
+ protected override async void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
taskbarIcon = Application.Current.MainWindow.FindChild(TrayIconControlName);
+ await CheckForNewVersion();
}
-
+
protected override void OnDeactivate(bool close)
{
taskbarIcon.Dispose(); // this will be cleaned up on app close anyway but this is a bit cleaner
base.OnDeactivate(close);
}
+
+ private async Task CheckForNewVersion()
+ {
+ var githubClient =
+ new GitHubClient(new ProductHeaderValue("Livestream.Monitor",
+ $"{currentAppVersion.Major}.{currentAppVersion.Minor}.{currentAppVersion.Build}"));
+
+ const string githubRepository = "Livestream.Monitor";
+ const string githubUsername = "laurencee";
+
+ var dialogController = await this.ShowProgressAsync("Update Check", "Checking for newer version...");
+ try
+ {
+ var releases = await githubClient.Release.GetAll(githubUsername, githubRepository);
+ var latestRelease = releases.FirstOrDefault();
+ if (latestRelease != null)
+ {
+ if (IsNewerVersion(latestRelease))
+ {
+ await dialogController.CloseAsync();
+ var dialogResult = await this.ShowMessageAsync("New version available",
+ "There is a newer version available. Go to download page?",
+ MessageDialogStyle.AffirmativeAndNegative);
+
+ if (dialogResult == MessageDialogResult.Affirmative)
+ {
+ System.Diagnostics.Process.Start(latestRelease.HtmlUrl);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ if (dialogController.IsOpen) await dialogController.CloseAsync();
+ await this.ShowMessageAsync("Error",
+ $"An error occured while checking for a newer version.{Environment.NewLine}{ex.Message}");
+ }
+
+ if (dialogController.IsOpen) await dialogController.CloseAsync();
+ }
+
+ private bool IsNewerVersion(Release latestRelease)
+ {
+ if (string.IsNullOrWhiteSpace(latestRelease?.TagName)) return false;
+
+ try
+ {
+ var releaseVersion = new Version(latestRelease.TagName);
+ return releaseVersion > currentAppVersion;
+ }
+ catch
+ {
+ // failed to convert the tagname to a version for some reason
+ return false;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Livestream.Monitor/packages.config b/Livestream.Monitor/packages.config
index 6183935..ee58eed 100644
--- a/Livestream.Monitor/packages.config
+++ b/Livestream.Monitor/packages.config
@@ -6,4 +6,5 @@
+
\ No newline at end of file
diff --git a/TwitchTv/Properties/AssemblyInfo.cs b/TwitchTv/Properties/AssemblyInfo.cs
index d7831ed..52168bd 100644
--- a/TwitchTv/Properties/AssemblyInfo.cs
+++ b/TwitchTv/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.1.2.0")]
-[assembly: AssemblyFileVersion("1.1.2.0")]
+[assembly: AssemblyVersion("1.2.0.0")]
+[assembly: AssemblyFileVersion("1.2.0.0")]