diff --git a/BuildsAppReborn.Access.UI/Notifications/DefaultNotificationProvider.cs b/BuildsAppReborn.Access.UI/Notifications/DefaultNotificationProvider.cs index e0a3e6b..fb7ec89 100644 --- a/BuildsAppReborn.Access.UI/Notifications/DefaultNotificationProvider.cs +++ b/BuildsAppReborn.Access.UI/Notifications/DefaultNotificationProvider.cs @@ -2,11 +2,9 @@ using System.ComponentModel.Composition; using System.Text; using System.Windows; - using BuildsAppReborn.Contracts.Composition; using BuildsAppReborn.Contracts.Models; using BuildsAppReborn.Contracts.UI.Notifications; - using ToastNotifications; using ToastNotifications.Lifetime; using ToastNotifications.Messages; @@ -24,11 +22,11 @@ internal class DefaultNotificationProvider : INotificationProvider public DefaultNotificationProvider() { this.notifier = new Notifier(cfg => - { - cfg.PositionProvider = new PrimaryScreenPositionProvider(Corner.BottomRight, 10, 50); - cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(TimeSpan.FromSeconds(10), MaximumNotificationCount.FromCount(3)); - cfg.Dispatcher = Application.Current.Dispatcher; - }); + { + cfg.PositionProvider = new PrimaryScreenPositionProvider(Corner.BottomRight, 10, 50); + cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(TimeSpan.FromSeconds(10), MaximumNotificationCount.FromCount(3)); + cfg.Dispatcher = Application.Current.Dispatcher; + }); } #endregion @@ -43,11 +41,14 @@ public void ShowBuild(IBuild build, Func iconProvider, Action - { - notificationClickAction?.Invoke(build); - n.Close(); - } }; + var displayOptions = new MessageOptions + { + NotificationClickAction = n => + { + notificationClickAction?.Invoke(build); + n.Close(); + } + }; switch (build.Status) { @@ -73,11 +74,32 @@ public void ShowBuild(IBuild build, Func iconProvider, Action + { + clickAction.Invoke(); + n.Close(); + } + }; + this.notifier.ShowInformation(sb.ToString(), displayOptions); + } } public Boolean IsSupported => true; diff --git a/BuildsAppReborn.Access.UI/Notifications/Windows10NotificationProvider.cs b/BuildsAppReborn.Access.UI/Notifications/Windows10NotificationProvider.cs index d49a852..06d1859 100644 --- a/BuildsAppReborn.Access.UI/Notifications/Windows10NotificationProvider.cs +++ b/BuildsAppReborn.Access.UI/Notifications/Windows10NotificationProvider.cs @@ -1,9 +1,7 @@ using System; using System.ComponentModel.Composition; using System.IO; - using Windows.UI.Notifications; - using BuildsAppReborn.Contracts.Composition; using BuildsAppReborn.Contracts.Models; using BuildsAppReborn.Contracts.UI.Notifications; @@ -37,13 +35,18 @@ public void ShowBuild(IBuild build, Func iconProvider, Action { notificationClickAction?.Invoke(build); }; + if (notificationClickAction != null) toast.Activated += (sender, args) => { notificationClickAction.Invoke(build); }; // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut! ToastNotificationManager.CreateToastNotifier(AppId).Show(toast); } public void ShowMessage(String title, String message) + { + ShowMessage(title, message, null); + } + + public void ShowMessage(String title, String message, Action clickAction) { // Get a toast XML template var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); @@ -57,6 +60,7 @@ public void ShowMessage(String title, String message) // Create the toast and attach event listeners var toast = new ToastNotification(toastXml); + if (clickAction != null) toast.Activated += (sender, args) => { clickAction.Invoke(); }; // Show the toast. Be sure to specify the AppUserModelId on your application's shortcut! ToastNotificationManager.CreateToastNotifier(AppId).Show(toast); diff --git a/BuildsAppReborn.Client/App.xaml.cs b/BuildsAppReborn.Client/App.xaml.cs index 7b0480c..b02392c 100644 --- a/BuildsAppReborn.Client/App.xaml.cs +++ b/BuildsAppReborn.Client/App.xaml.cs @@ -44,7 +44,7 @@ protected override void OnStartup(StartupEventArgs e) this.updateChecker = compositionContainer.GetExportedValue(); this.updateChecker.Start(); - this.updateChecker.UpdateCheck(); + this.updateChecker.UpdateCheck(false); this.globalSettingsContainer = compositionContainer.GetExportedValue(); this.buildMonitor = compositionContainer.GetExportedValue(); @@ -106,7 +106,7 @@ private void RegisterToWindowsStartUp() var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { - var fileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); + var fileName = Path.GetFileName(Assembly.GetEntryAssembly().Location); key?.SetValue(Consts.ApplicationName, $"\"{Path.Combine(Consts.InstallationFolder, fileName)}\""); } } diff --git a/BuildsAppReborn.Client/Resources/NotifyIconResources.xaml b/BuildsAppReborn.Client/Resources/NotifyIconResources.xaml index 2f4a9b3..61bb856 100644 --- a/BuildsAppReborn.Client/Resources/NotifyIconResources.xaml +++ b/BuildsAppReborn.Client/Resources/NotifyIconResources.xaml @@ -6,6 +6,7 @@ + diff --git a/BuildsAppReborn.Client/UpdateChecker.cs b/BuildsAppReborn.Client/UpdateChecker.cs index d2ccd7d..615c455 100644 --- a/BuildsAppReborn.Client/UpdateChecker.cs +++ b/BuildsAppReborn.Client/UpdateChecker.cs @@ -1,7 +1,7 @@ using System; -using System.Collections.Generic; using System.ComponentModel.Composition; using System.Diagnostics; +using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -11,7 +11,6 @@ using BuildsAppReborn.Contracts.Models; using BuildsAppReborn.Contracts.UI.Notifications; using BuildsAppReborn.Infrastructure; - using log4net; using Squirrel; @@ -52,9 +51,9 @@ public void Stop() this.timer.Stop(); } - public async void UpdateCheck() + public async void UpdateCheck(Boolean manualCheck) { - await UpdateCheckInternal(); + await UpdateCheckInternal(manualCheck); } #endregion @@ -69,10 +68,10 @@ public async void UpdateCheck() private async void TimerOnElapsed(Object sender, ElapsedEventArgs elapsedEventArgs) { - await UpdateCheckInternal(); + await UpdateCheckInternal(false); } - private async Task UpdateCheckInternal() + private async Task UpdateCheckInternal(Boolean manualCheck) { #if DEBUG return; @@ -88,29 +87,42 @@ private async Task UpdateCheckInternal() { using (var updateManager = await updateMgrTask) { - if (!GeneralSettings.AutoInstall) + var updateInfo = await updateManager.CheckForUpdate(); + if (updateInfo.ReleasesToApply.Any()) { - var updateInfo = await updateManager.CheckForUpdate(); - if (GeneralSettings.NotifyOnNewUpdate) + this.logger.Info("New Update found!"); + if (!GeneralSettings.AutoInstall) { - // ToDo: show if new update available - } - // ToDo: implement update when user accepts - } - else - { - var result = await updateManager.UpdateApp(); - if (result != null) - { - this.logger.Info("New Update found!"); if (GeneralSettings.NotifyOnNewUpdate) { - this.notificationProvider?.ShowMessage($"{this.version.ProductName} New update found!", "Update will be installed automatically on next start."); + // ToDo: show if new update available } + // ToDo: implement update when user accepts } else { - this.logger.Info("No Update found!"); + this.logger.Debug("Auto installing update..."); + await updateManager.DownloadReleases(updateInfo.ReleasesToApply); + var path = await updateManager.ApplyReleases(updateInfo); + if (path != null) + { + this.logger.Debug("Update install finished."); + if (GeneralSettings.NotifyOnNewUpdate) + { + this.notificationProvider?.ShowMessage($"{this.version.ProductName} - Update check finished!", + "New Updates installed. Click here to restart.", + () => UpdateManager.RestartApp(Path.Combine(path, Path.GetFileName(entryAssembly.Location)))); + } + } + else this.logger.Debug("Update install failed."); + } + } + else + { + this.logger.Info("No Update found!"); + if (manualCheck) + { + this.notificationProvider?.ShowMessage($"{this.version.ProductName} - Update check finished!", "No updates found!"); } } } @@ -134,8 +146,10 @@ private async Task UpdateCheckInternal() private ILog logger = LogManager.GetLogger(typeof(UpdateChecker)); private INotificationProvider notificationProvider; private Timer timer = new Timer(); - private FileVersionInfo version = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); + private FileVersionInfo version = FileVersionInfo.GetVersionInfo(entryAssembly.Location); #endregion + + private static Assembly entryAssembly = Assembly.GetEntryAssembly(); } } \ No newline at end of file diff --git a/BuildsAppReborn.Client/ViewModels/NotifyIconViewModel.cs b/BuildsAppReborn.Client/ViewModels/NotifyIconViewModel.cs index 29777b8..782fb0b 100644 --- a/BuildsAppReborn.Client/ViewModels/NotifyIconViewModel.cs +++ b/BuildsAppReborn.Client/ViewModels/NotifyIconViewModel.cs @@ -19,13 +19,14 @@ public class NotifyIconViewModel : ViewModelBase #region Constructors [ImportingConstructor] - public NotifyIconViewModel(ExportFactory buildsExportFactory, ExportFactory settingsExportFactory, BuildCache buildCache, NotificationManager notificationManager) + internal NotifyIconViewModel(ExportFactory buildsExportFactory, ExportFactory settingsExportFactory, BuildCache buildCache, NotificationManager notificationManager, UpdateChecker updateChecker) { if (buildCache.CacheStatus == BuildCacheStatus.NotConfigured) TrayIcon = IconProvider.SettingsIcon; else TrayIcon = IconProvider.LoadingIcon; this.buildsExportFactory = buildsExportFactory; this.settingsExportFactory = settingsExportFactory; + this.updateChecker = updateChecker; buildCache.CacheUpdated += (sender, args) => { TrayIcon = buildCache.CurrentIcon; }; Initialize(); @@ -35,6 +36,8 @@ public NotifyIconViewModel(ExportFactory buildsExportFactory, #region Public Properties + public ICommand CheckUpdateCommand { get; private set; } + public ICommand ExitApplicationCommand { get; private set; } public ICommand ShowSettingsWindowCommand { get; private set; } @@ -112,6 +115,8 @@ private void Initialize() ShowSettingsWindowCommand = new DelegateCommand(() => { OpenWindow(this.settingsExportFactory); }); ExitApplicationCommand = new DelegateCommand(() => Application.Current.Shutdown()); + + CheckUpdateCommand = new DelegateCommand(() => this.updateChecker.UpdateCheck(true)); } #endregion @@ -122,6 +127,7 @@ private void Initialize() private readonly ExportFactory settingsExportFactory; private String trayIcon; + private readonly UpdateChecker updateChecker; #endregion } diff --git a/BuildsAppReborn.Contracts.UI/Notifications/INotificationProvider.cs b/BuildsAppReborn.Contracts.UI/Notifications/INotificationProvider.cs index 876f606..75772fb 100644 --- a/BuildsAppReborn.Contracts.UI/Notifications/INotificationProvider.cs +++ b/BuildsAppReborn.Contracts.UI/Notifications/INotificationProvider.cs @@ -1,5 +1,4 @@ using System; - using BuildsAppReborn.Contracts.Models; namespace BuildsAppReborn.Contracts.UI.Notifications @@ -18,6 +17,8 @@ public interface INotificationProvider void ShowMessage(String title, String message); + void ShowMessage(String title, String message, Action clickAction); + #endregion } } \ No newline at end of file