Skip to content

Commit 3be50e9

Browse files
hotfix: Updater version parsing bug, Updater delay, Better baloontip click handling
1 parent e978484 commit 3be50e9

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

DigitalWellbeingWPF/Helpers/Notifier.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public static class Notifier
1919
private static int NOTIFICATION_TIMOUT_SECONDS = 10;
2020
private static int CHECK_INTERVAL = 130;
2121

22+
private static EventHandler defaultNotificationHandler;
23+
2224
static Notifier()
2325
{
2426
trayIcon = new System.Windows.Forms.NotifyIcon();
@@ -47,28 +49,30 @@ static Notifier()
4749
mWindow.Close();
4850
});
4951

50-
// Always visible for notifications
51-
//trayIcon.Visible = true;
52+
// Always visible for notifications to work
53+
trayIcon.Visible = true;
5254
}
5355

54-
public static void ShowNotification(string title, string message, System.Windows.Forms.ToolTipIcon icon = System.Windows.Forms.ToolTipIcon.None)
56+
public static void ShowNotification(string title, string message, EventHandler clickHandler = null, System.Windows.Forms.ToolTipIcon icon = System.Windows.Forms.ToolTipIcon.None)
5557
{
5658
trayIcon.BalloonTipTitle = title;
5759
trayIcon.BalloonTipText = message;
5860
trayIcon.BalloonTipIcon = icon;
61+
62+
trayIcon.BalloonTipClicked += clickHandler ?? defaultNotificationHandler;
63+
5964
trayIcon.ShowBalloonTip(NOTIFICATION_TIMOUT_SECONDS * 1000);
6065
}
6166

62-
public static void ShowTrayIcon(EventHandler handler)
67+
public static void SetDoubleClickHandler(EventHandler doubleClickHandler)
6368
{
64-
trayIcon.DoubleClick += handler;
65-
trayIcon.BalloonTipClicked += handler;
66-
trayIcon.Visible = true;
69+
trayIcon.DoubleClick += doubleClickHandler;
6770
}
6871

69-
public static void HideTrayIcon()
72+
public static void SetDefaultNotificationHandler(EventHandler baloonTipHandlerClick)
7073
{
71-
trayIcon.Visible = false;
74+
defaultNotificationHandler = baloonTipHandlerClick;
75+
trayIcon.BalloonTipClicked += baloonTipHandlerClick;
7276
}
7377

7478
#region App Time Limit Checker

DigitalWellbeingWPF/Helpers/Updater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static int ParseVersion(string strVersion)
5050

5151
if (strVersion == string.Empty) return version;
5252

53-
strVersion = Regex.Replace(strVersion, "[^0-9.]", ""); // Remove all non-numbers and period
53+
strVersion = Regex.Replace(strVersion, "[^0-9]", ""); // Remove all non-numbers
5454

5555
if (int.TryParse(strVersion, out version))
5656
{

DigitalWellbeingWPF/MainWindow.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public MainWindow()
4242

4343
// Init Notifier
4444
Notifier.InitNotifierTimer();
45+
// Set Default Click Handler for any Notification
46+
Notifier.SetDefaultNotificationHandler((s, e) => RestoreWindow());
4547

4648
// Check Autorun File
4749
InitAutoRun();
@@ -101,14 +103,13 @@ private void Window_StateChanged(object sender, EventArgs e)
101103
public void MinimizeToTray()
102104
{
103105
this.Hide();
104-
Notifier.ShowTrayIcon((s, e) => RestoreWindow());
106+
Notifier.SetDoubleClickHandler((s, e) => RestoreWindow());
105107
}
106108

107109
public void RestoreWindow()
108110
{
109111
this.Show();
110112
this.WindowState = WindowState.Normal;
111-
Notifier.HideTrayIcon();
112113

113114
// Trigger refresh
114115
usagePage.OnNavigate();

DigitalWellbeingWPF/Views/SettingsPage.xaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace DigitalWellbeingWPF.Views
2929
public partial class SettingsPage : Page
3030
{
3131
private readonly ApplicationTheme? systemTheme;
32+
private int UPDATE_CHECK_DELAY = 20;
3233

3334
public SettingsPage()
3435
{
@@ -215,13 +216,22 @@ private void LoadAboutApp()
215216

216217
private async void CheckForUpdates()
217218
{
219+
await Task.Delay(UPDATE_CHECK_DELAY * 1000);
220+
218221
strLatestVersion = await Updater.GetLatestVersion();
219222
latestVersion = Updater.ParseVersion(strLatestVersion);
220223

221224
if (Updater.IsUpdateAvailable(currentVersion, latestVersion))
222225
{
223226
TxtLatestVersion.Text = $" (Update Available {strLatestVersion})";
224-
Notifier.ShowNotification(App.APPNAME, $"Update Available: {strLatestVersion}");
227+
Notifier.ShowNotification(
228+
App.APPNAME,
229+
$"Update Available: {strLatestVersion}",
230+
(s, e) =>
231+
{
232+
(Application.Current.MainWindow as MainWindow).GoToSettings();
233+
}
234+
);
225235
}
226236
}
227237

0 commit comments

Comments
 (0)