diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 6ac1c37..804d4ff 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -66,7 +66,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 + { + _trayIcon?.ShowNotification("Copy failed", "ouldn't update the clipboard. Try again."); + } + } /// /// Minimizes the window. @@ -239,7 +249,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 +413,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", 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)