apply suggestions

This commit is contained in:
mshafer1
2025-01-11 08:42:06 -06:00
parent 4fbc4ca4e4
commit d8cbe96875

View File

@@ -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
}
}
}
}