diff --git a/DigitalWellbeingWPF/Helpers/Notifier.cs b/DigitalWellbeingWPF/Helpers/Notifier.cs index 4fc7397..1e4f0aa 100644 --- a/DigitalWellbeingWPF/Helpers/Notifier.cs +++ b/DigitalWellbeingWPF/Helpers/Notifier.cs @@ -19,6 +19,8 @@ public static class Notifier private static int NOTIFICATION_TIMOUT_SECONDS = 10; private static int CHECK_INTERVAL = 130; + private static EventHandler defaultNotificationHandler; + static Notifier() { trayIcon = new System.Windows.Forms.NotifyIcon(); @@ -47,28 +49,30 @@ static Notifier() mWindow.Close(); }); - // Always visible for notifications - //trayIcon.Visible = true; + // Always visible for notifications to work + trayIcon.Visible = true; } - public static void ShowNotification(string title, string message, System.Windows.Forms.ToolTipIcon icon = System.Windows.Forms.ToolTipIcon.None) + public static void ShowNotification(string title, string message, EventHandler clickHandler = null, System.Windows.Forms.ToolTipIcon icon = System.Windows.Forms.ToolTipIcon.None) { trayIcon.BalloonTipTitle = title; trayIcon.BalloonTipText = message; trayIcon.BalloonTipIcon = icon; + + trayIcon.BalloonTipClicked += clickHandler ?? defaultNotificationHandler; + trayIcon.ShowBalloonTip(NOTIFICATION_TIMOUT_SECONDS * 1000); } - public static void ShowTrayIcon(EventHandler handler) + public static void SetDoubleClickHandler(EventHandler doubleClickHandler) { - trayIcon.DoubleClick += handler; - trayIcon.BalloonTipClicked += handler; - trayIcon.Visible = true; + trayIcon.DoubleClick += doubleClickHandler; } - public static void HideTrayIcon() + public static void SetDefaultNotificationHandler(EventHandler baloonTipHandlerClick) { - trayIcon.Visible = false; + defaultNotificationHandler = baloonTipHandlerClick; + trayIcon.BalloonTipClicked += baloonTipHandlerClick; } #region App Time Limit Checker diff --git a/DigitalWellbeingWPF/Helpers/Updater.cs b/DigitalWellbeingWPF/Helpers/Updater.cs index bfc5026..9c1faa1 100644 --- a/DigitalWellbeingWPF/Helpers/Updater.cs +++ b/DigitalWellbeingWPF/Helpers/Updater.cs @@ -50,7 +50,7 @@ public static int ParseVersion(string strVersion) if (strVersion == string.Empty) return version; - strVersion = Regex.Replace(strVersion, "[^0-9.]", ""); // Remove all non-numbers and period + strVersion = Regex.Replace(strVersion, "[^0-9]", ""); // Remove all non-numbers if (int.TryParse(strVersion, out version)) { diff --git a/DigitalWellbeingWPF/MainWindow.xaml.cs b/DigitalWellbeingWPF/MainWindow.xaml.cs index 54e699f..f159efb 100644 --- a/DigitalWellbeingWPF/MainWindow.xaml.cs +++ b/DigitalWellbeingWPF/MainWindow.xaml.cs @@ -42,6 +42,8 @@ public MainWindow() // Init Notifier Notifier.InitNotifierTimer(); + // Set Default Click Handler for any Notification + Notifier.SetDefaultNotificationHandler((s, e) => RestoreWindow()); // Check Autorun File InitAutoRun(); @@ -101,14 +103,13 @@ private void Window_StateChanged(object sender, EventArgs e) public void MinimizeToTray() { this.Hide(); - Notifier.ShowTrayIcon((s, e) => RestoreWindow()); + Notifier.SetDoubleClickHandler((s, e) => RestoreWindow()); } public void RestoreWindow() { this.Show(); this.WindowState = WindowState.Normal; - Notifier.HideTrayIcon(); // Trigger refresh usagePage.OnNavigate(); diff --git a/DigitalWellbeingWPF/Views/SettingsPage.xaml.cs b/DigitalWellbeingWPF/Views/SettingsPage.xaml.cs index b3198ee..af8c226 100644 --- a/DigitalWellbeingWPF/Views/SettingsPage.xaml.cs +++ b/DigitalWellbeingWPF/Views/SettingsPage.xaml.cs @@ -29,6 +29,7 @@ namespace DigitalWellbeingWPF.Views public partial class SettingsPage : Page { private readonly ApplicationTheme? systemTheme; + private int UPDATE_CHECK_DELAY = 20; public SettingsPage() { @@ -215,13 +216,22 @@ private void LoadAboutApp() private async void CheckForUpdates() { + await Task.Delay(UPDATE_CHECK_DELAY * 1000); + strLatestVersion = await Updater.GetLatestVersion(); latestVersion = Updater.ParseVersion(strLatestVersion); if (Updater.IsUpdateAvailable(currentVersion, latestVersion)) { TxtLatestVersion.Text = $" (Update Available {strLatestVersion})"; - Notifier.ShowNotification(App.APPNAME, $"Update Available: {strLatestVersion}"); + Notifier.ShowNotification( + App.APPNAME, + $"Update Available: {strLatestVersion}", + (s, e) => + { + (Application.Current.MainWindow as MainWindow).GoToSettings(); + } + ); } }