From 61b22bf1fd24bb87d52dfe28e501d1705f1c772b Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sat, 2 May 2026 10:05:28 -0500 Subject: [PATCH 1/5] Improve feedback when user-initiated actions fail These changes make failures more understandable instead of letting them fail silently or crash the app. Clipboard, link-opening, and alert playback errors are all cases where the user explicitly asked the app to do something, so the app should explain why nothing appeared to happen and give enough context to recover. --- DesktopClock/MainWindow.xaml.cs | 26 ++++++++++++++++++++++---- DesktopClock/SettingsWindow.xaml.cs | 15 ++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 6ac1c37..b96d6e3 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Media; +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -66,7 +67,17 @@ public MainWindow() /// Copies the current time string to the clipboard. /// [RelayCommand] - public void CopyToClipboard() => Clipboard.SetText(CurrentTimeOrCountdownString); + public void CopyToClipboard() + { + try + { + Clipboard.SetText(CurrentTimeOrCountdownString); + } + catch (ExternalException ex) when (ex.ErrorCode == unchecked((int)0x800401D0)) + { + _trayIcon?.ShowNotification("Copy failed", "The clipboard is busy. Try copying again."); + } + } /// /// Minimizes the window. @@ -239,7 +250,7 @@ private void TryPlaySound() } catch { - // Ignore errors because we don't want a sound issue to crash the app. + _trayIcon?.ShowNotification("Alert sound unavailable", "The WAV file couldn't be played."); } } @@ -403,8 +414,15 @@ private void Window_KeyDown(object sender, KeyEventArgs e) } } - private static void OpenUrl(string url) + private void OpenUrl(string url) { - Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + try + { + Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + } + catch + { + _trayIcon?.ShowNotification("Couldn't open link", $"Couldn't open {url}."); + } } } diff --git a/DesktopClock/SettingsWindow.xaml.cs b/DesktopClock/SettingsWindow.xaml.cs index a225976..7445232 100644 --- a/DesktopClock/SettingsWindow.xaml.cs +++ b/DesktopClock/SettingsWindow.xaml.cs @@ -129,7 +129,7 @@ private void PickColor(Action applyColor, Color currentColor) private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { - Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true }); + OpenUrl(e.Uri.AbsoluteUri); e.Handled = true; } @@ -221,9 +221,18 @@ private void SettingsWindow_Closing(object sender, CancelEventArgs e) ViewModel.Settings.SettingsScrollPosition = SettingsScrollViewer.VerticalOffset; } - private static void OpenUrl(string url) + private void OpenUrl(string url) { - Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + try + { + Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); + } + catch + { + MessageBox.Show(this, + $"Couldn't open {url}.", + Title, MessageBoxButton.OK, MessageBoxImage.Error); + } } private static void OpenSettingsPath(string filePath) From 18170e52a8f6175a806b3395453c88fbf534166b Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sat, 2 May 2026 10:06:46 -0500 Subject: [PATCH 2/5] make it cover all clipboard errors --- DesktopClock/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index b96d6e3..4eaac68 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -73,9 +73,9 @@ public void CopyToClipboard() { Clipboard.SetText(CurrentTimeOrCountdownString); } - catch (ExternalException ex) when (ex.ErrorCode == unchecked((int)0x800401D0)) + catch (ExternalException) { - _trayIcon?.ShowNotification("Copy failed", "The clipboard is busy. Try copying again."); + _trayIcon?.ShowNotification("Copy failed", "Windows couldn't update the clipboard. Try again."); } } From 24a3301924cc153fd6c1f4012f27da12d0fab192 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sat, 2 May 2026 10:07:34 -0500 Subject: [PATCH 3/5] update --- DesktopClock/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 4eaac68..580fcee 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -75,7 +75,7 @@ public void CopyToClipboard() } catch (ExternalException) { - _trayIcon?.ShowNotification("Copy failed", "Windows couldn't update the clipboard. Try again."); + _trayIcon?.ShowNotification("Copy failed", "Couldn't update the clipboard. Try again."); } } From 38c497ecdd901f29fc8e1cc19a24e721f77031d8 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sat, 2 May 2026 10:14:14 -0500 Subject: [PATCH 4/5] update --- DesktopClock/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 580fcee..9b33805 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -75,7 +75,7 @@ public void CopyToClipboard() } catch (ExternalException) { - _trayIcon?.ShowNotification("Copy failed", "Couldn't update the clipboard. Try again."); + _trayIcon?.ShowNotification("Copy failed", "ouldn't update the clipboard. Try again."); } } @@ -422,7 +422,7 @@ private void OpenUrl(string url) } catch { - _trayIcon?.ShowNotification("Couldn't open link", $"Couldn't open {url}."); + _trayIcon?.ShowNotification("Couldn't open link", url); } } } From 55c4c41c604ccb4b7781a7026ada572c34eb1900 Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Sat, 2 May 2026 10:16:22 -0500 Subject: [PATCH 5/5] catch all --- DesktopClock/MainWindow.xaml.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 9b33805..804d4ff 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -4,7 +4,6 @@ using System.Globalization; using System.IO; using System.Media; -using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -73,7 +72,7 @@ public void CopyToClipboard() { Clipboard.SetText(CurrentTimeOrCountdownString); } - catch (ExternalException) + catch { _trayIcon?.ShowNotification("Copy failed", "ouldn't update the clipboard. Try again."); }