Skip to content

Commit f7f5194

Browse files
Improve feedback when actions fail (#128)
1 parent bbeeba8 commit f7f5194

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

DesktopClock/MainWindow.xaml.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ public MainWindow()
6666
/// Copies the current time string to the clipboard.
6767
/// </summary>
6868
[RelayCommand]
69-
public void CopyToClipboard() => Clipboard.SetText(CurrentTimeOrCountdownString);
69+
public void CopyToClipboard()
70+
{
71+
try
72+
{
73+
Clipboard.SetText(CurrentTimeOrCountdownString);
74+
}
75+
catch
76+
{
77+
_trayIcon?.ShowNotification("Copy failed", "ouldn't update the clipboard. Try again.");
78+
}
79+
}
7080

7181
/// <summary>
7282
/// Minimizes the window.
@@ -239,7 +249,7 @@ private void TryPlaySound()
239249
}
240250
catch
241251
{
242-
// Ignore errors because we don't want a sound issue to crash the app.
252+
_trayIcon?.ShowNotification("Alert sound unavailable", "The WAV file couldn't be played.");
243253
}
244254
}
245255

@@ -403,8 +413,15 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
403413
}
404414
}
405415

406-
private static void OpenUrl(string url)
416+
private void OpenUrl(string url)
407417
{
408-
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
418+
try
419+
{
420+
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
421+
}
422+
catch
423+
{
424+
_trayIcon?.ShowNotification("Couldn't open link", url);
425+
}
409426
}
410427
}

DesktopClock/SettingsWindow.xaml.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void PickColor(Action<Color> applyColor, Color currentColor)
129129

130130
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
131131
{
132-
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
132+
OpenUrl(e.Uri.AbsoluteUri);
133133
e.Handled = true;
134134
}
135135

@@ -221,9 +221,18 @@ private void SettingsWindow_Closing(object sender, CancelEventArgs e)
221221
ViewModel.Settings.SettingsScrollPosition = SettingsScrollViewer.VerticalOffset;
222222
}
223223

224-
private static void OpenUrl(string url)
224+
private void OpenUrl(string url)
225225
{
226-
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
226+
try
227+
{
228+
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
229+
}
230+
catch
231+
{
232+
MessageBox.Show(this,
233+
$"Couldn't open {url}.",
234+
Title, MessageBoxButton.OK, MessageBoxImage.Error);
235+
}
227236
}
228237

229238
private static void OpenSettingsPath(string filePath)

0 commit comments

Comments
 (0)