diff --git a/ntfysh_client/NotificationDialog.cs b/ntfysh_client/NotificationDialog.cs index 7f70a8f..9ad7d2f 100644 --- a/ntfysh_client/NotificationDialog.cs +++ b/ntfysh_client/NotificationDialog.cs @@ -102,10 +102,8 @@ namespace ntfysh_client // ok, show the window Show(); SetWindowPosition(); - if(playNotificationSound) - { - PlayNotificationSound(); - } + + if (playNotificationSound) PlayNotificationSound(); } private void ApplyTheme() @@ -274,25 +272,22 @@ namespace ntfysh_client private void PlayNotificationSound() { - bool found = false; try { - using RegistryKey? key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\.Default\Notification.Default\.Current"); - if (key != null) - { - Object? o = key.GetValue(null); // pass null to get (Default) - if (o != null) - { - SoundPlayer theSound = new SoundPlayer((String)o); - theSound.Play(); - found = true; - } - } + using RegistryKey? defaultSoundPathKey = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\.Default\Notification.Default\.Current"); + + if (defaultSoundPathKey is null) throw new Exception(); + + if (defaultSoundPathKey.GetValue(null) is not string defaultSoundPath) throw new Exception(); + + SoundPlayer loadedSound = new(defaultSoundPath); + + loadedSound.Play(); } catch - { } - if (!found) + { SystemSounds.Beep.Play(); // consolation prize + } } } }