Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost(notification): Merged Custom Sound Notification into Sound Notification #1352

Merged
merged 8 commits into from
Jan 16, 2024
9 changes: 2 additions & 7 deletions README.de.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Wählen Sie zuerst, wie im vorigen Abschnitt beschrieben, Ihre gewünschten Ger

## _Umschalten_ Benachrichtigung

SoundSwitch bietet fünf verschiedenen Arten der Benachrichtigung, wenn ein Gerät gewechselt wird:
SoundSwitch bietet vier verschiedenen Arten der Benachrichtigung, wenn ein Gerät gewechselt wird:

- #### 🎟 Banner
- #### 🎟 Banner Benachrichtigung
Verwendet ein Anzeigeelement, welches über allem liegt (always-on-top), nützlich für die Verwendung in Spielen. Dies ist die Standardart der Benachrichtigung.

- #### 🗨 Windows Benachrichtigung
Expand All @@ -44,11 +44,6 @@ Verwendet die Standard Windows Benachrichtigung. Im Falle von Windows 7, ist die
- #### 🎵 Akustische Benachrichtigung
Diese Benachrichtigung ist ein Ton, der über das aktuell aktive Augabegerät abgespielt wird. Auf diese Weise teilt das neue Gerät ihnen mit, dass es ausgewählt ist.

- #### 🎶 Angepasste Akustische Benachrichtigung
Genau wie bei der akustischen Benachrichtigung, aber mit einem Sound, welcher selbst definiert werden kann.

Wenn Sie zur stillen Windows Benachrichtigung zurückkehren möchten, öffnen Sie hierzu den Dateiauswahl-Dialog und drücken Abbrechen. Dadurch wird der eingestellte Sound entfernt.

## Profile

Mithilfe von Profilen ist es möglich zu einem bestimmten Gerät zu wechseln, wenn eine Bedingung eintritt. Profile können für die folgenden Zwecke definiert werden:
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ First set up your devices you want to cycle through, using _right click_ on the

## _Switched_ Notification

SoundSwitch provides five types of notification when a device is changed:
SoundSwitch provides four types of notification when a device is changed:

- #### 🎟 Banner
- #### 🎟 Banner Notification
Uses a custom always-on-top frame, useful for in-game usage. This is the recommended default display style.

- #### 🗨 Windows Notification
Expand All @@ -49,11 +49,6 @@ Uses the balloon tip of Windows. In the case of Windows 7, it's the little ballo
- #### 🎵 Sound Notification
This notification is a sound played on the switched device. This way when you are switching devices, the new device will 'chime' to tell you it's selected.

- #### 🎶 Customized Sound Notification
The same as a Sound Notification but you can specify the sound which is played.

If you want to return to a silent Toast Notification, open the file selector, and just press Cancel. Doing that will remove the set sound.

## Profiles

Using profiles, it is possible to switch to a specific device when a condition occurs. Profiles can be defined for the following purposes:
Expand Down
19 changes: 9 additions & 10 deletions SoundSwitch/Framework/Banner/BannerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public partial class BannerForm : Form
private BannerData _currentData;
private CancellationTokenSource _cancellationTokenSource = new();

/// <summary>
/// Get the Screen object
/// </summary>
private static Screen GetScreen()
{
return AppModel.Instance.NotifyUsingPrimaryScreen ? Screen.PrimaryScreen : Screen.FromPoint(Cursor.Position);
}

/// <summary>
/// Constructor for the <see cref="BannerForm"/> class
/// </summary>
Expand Down Expand Up @@ -64,14 +72,6 @@ public BannerForm()
// }
// }

/// <summary>
///
/// </summary>
private static Screen GetScreen()
{
return AppModel.Instance.NotifyUsingPrimaryScreen ? Screen.PrimaryScreen : Screen.FromPoint(Cursor.Position);
}

/// <summary>
/// Called internally to configure pass notification parameters
/// </summary>
Expand Down Expand Up @@ -112,7 +112,7 @@ internal void SetData(BannerData data)

var screen = GetScreen();

Location = data.Position.GetScreenPosition(screen, Height, Width);
Location = data.Position.GetScreenPosition(screen, Height, Width);

_timerHide.Enabled = true;

Expand Down Expand Up @@ -154,7 +154,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}


/// <summary>
/// Event handler for the "hiding" timer.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public bool Migrate()
NotificationSettings = NotificationTypeEnum.BannerNotification;
}

if (NotificationSettings == NotificationTypeEnum.CustomNotification)
{
NotificationSettings = NotificationTypeEnum.SoundNotification;
XangelMusic marked this conversation as resolved.
Show resolved Hide resolved
}

#pragma warning disable 612
if (!MigratedFields.Contains(nameof(KeepSystrayIcon)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,46 @@ public interface INotification : IEnumImpl<NotificationTypeEnum>
/// </summary>
INotificationConfiguration Configuration { get; set; }

/// <summary>
/// Does this notification support showing an icon
/// </summary>
bool SupportIcon => false;

/// <summary>
/// Notify the change of default audio device
/// </summary>
/// <param name="audioDevice"></param>
void NotifyDefaultChanged(DeviceFullInfo audioDevice);

/// <summary>
/// Called when the set sound changed
/// Notify when a profile has changed
/// </summary>
/// <param name="newSound"></param>
void OnSoundChanged(CachedSound newSound);
/// <param name="profile"></param>
/// <param name="icon"></param>
/// <param name="processId"></param>
void NotifyProfileChanged(Profile.Profile profile, [CanBeNull] Bitmap icon, uint? processId);

/// <summary>
/// Does the notification support a Custom Sound
/// Notify about the mute state having changed
/// </summary>
/// <returns></returns>
NotificationCustomSoundEnum SupportCustomSound();
void NotifyMuteChanged(string microphoneName, bool newMuteState);

/// <summary>
/// Does the notification need a Custom Sound set to work
/// Does this notification support showing an icon
/// </summary>
/// <returns></returns>
bool NeedCustomSound();
bool SupportIcon => false;

/// <summary>
/// Is this notification available
/// Called when the set sound changed
/// </summary>
/// <returns></returns>
bool IsAvailable();
/// <param name="newSound"></param>
void OnSoundChanged(CachedSound newSound);

/// <summary>
/// Notify when a profile has changed
/// Does the notification support a Custom Sound
/// </summary>
/// <param name="profile"></param>
/// <param name="icon"></param>
/// <param name="processId"></param>
void NotifyProfileChanged(Profile.Profile profile, [CanBeNull] Bitmap icon, uint? processId);
/// <returns></returns>
bool SupportCustomSound();

/// <summary>
/// Notify about the mute state having changed
/// Is this notification available
/// </summary>
void NotifyMuteChanged(string microphoneName, bool newMuteState);
/// <returns></returns>
bool IsAvailable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,48 @@
using SoundSwitch.Common.Framework.Audio.Device;
using SoundSwitch.Framework.Audio;
using SoundSwitch.Framework.Banner;
using SoundSwitch.Framework.Banner.Position;
using SoundSwitch.Framework.NotificationManager.Notification.Configuration;
using SoundSwitch.Localization;
using SoundSwitch.Model;
using SoundSwitch.Properties;

namespace SoundSwitch.Framework.NotificationManager.Notification
{
public class NotificationBanner : INotification
internal class NotificationBanner : INotification
{
public NotificationTypeEnum TypeEnum => NotificationTypeEnum.BannerNotification;
public string Label => SettingsStrings.notificationOptionBanner;

public INotificationConfiguration Configuration { get; set; }

private readonly BannerManager _bannerManager = new();
private readonly BannerPositionFactory _bannerPositionFactory = new();

public bool SupportIcon => true;
private IPosition BannerPosition() => _bannerPositionFactory.Get(Configuration.BannerPosition);
XangelMusic marked this conversation as resolved.
Show resolved Hide resolved

public void NotifyDefaultChanged(DeviceFullInfo audioDevice)
{
var toastData = new BannerData
{
Image = audioDevice.LargeIcon.ToBitmap(),
Text = audioDevice.NameClean,
Position = BannerPosition()
XangelMusic marked this conversation as resolved.
Show resolved Hide resolved
};
if (CustomSoundCheck(audioDevice))
{
toastData.SoundFile = Configuration.CustomSound;
toastData.CurrentDeviceId = audioDevice.Id;
}

toastData.Title = audioDevice.Type switch
{
DataFlow.Render => SettingsStrings.tooltipOnHoverOptionPlaybackDevice,
DataFlow.Capture => SettingsStrings.tooltipOnHoverOptionRecordingDevice,
_ => throw new ArgumentOutOfRangeException(nameof(audioDevice.Type), audioDevice.Type, null)
};

_bannerManager.ShowNotification(toastData);
}

public void NotifyProfileChanged(Profile.Profile profile, Bitmap icon, uint? processId)
{
Expand All @@ -46,7 +71,7 @@ public void NotifyProfileChanged(Profile.Profile profile, Bitmap icon, uint? pro
Image = icon,
Title = string.Format(SettingsStrings.profile_notification_text, profile.Name),
Text = string.Join("\n", profile.Devices.Select(wrapper => wrapper.DeviceInfo.NameClean).Distinct()),
Position = _bannerPositionFactory.Get(Configuration.BannerPosition)
Position = BannerPosition()
XangelMusic marked this conversation as resolved.
Show resolved Hide resolved
};
_bannerManager.ShowNotification(bannerData);
}
Expand All @@ -62,51 +87,20 @@ public void NotifyMuteChanged(string microphoneName, bool newMuteState)
Priority = 2,
Image = icon,
Title = title,
Position = _bannerPositionFactory.Get(Configuration.BannerPosition)
Position = BannerPosition()
XangelMusic marked this conversation as resolved.
Show resolved Hide resolved
};
_bannerManager.ShowNotification(bannerData);
}

public void NotifyDefaultChanged(DeviceFullInfo audioDevice)
{
var toastData = new BannerData
{
Image = audioDevice.LargeIcon.ToBitmap(),
Text = audioDevice.NameClean,
Position = _bannerPositionFactory.Get(Configuration.BannerPosition)
};
if (audioDevice.Type == DataFlow.Render && Configuration.CustomSound != null && File.Exists(Configuration.CustomSound.FilePath))
{
toastData.SoundFile = Configuration.CustomSound;
toastData.CurrentDeviceId = audioDevice.Id;
}

toastData.Title = audioDevice.Type switch
{
DataFlow.Render => SettingsStrings.tooltipOnHoverOptionPlaybackDevice,
DataFlow.Capture => SettingsStrings.tooltipOnHoverOptionRecordingDevice,
_ => throw new ArgumentOutOfRangeException(nameof(audioDevice.Type), audioDevice.Type, null)
};

_bannerManager.ShowNotification(toastData);
}
public bool SupportIcon => true;

public void OnSoundChanged(CachedSound newSound)
{
Configuration.CustomSound = newSound;
}
public void OnSoundChanged(CachedSound newSound) => Configuration.CustomSound = newSound;

public NotificationCustomSoundEnum SupportCustomSound() => NotificationCustomSoundEnum.Optional;
public bool SupportCustomSound() => true;

public bool NeedCustomSound()
{
return false;
}
// Available in all Windows versions
public bool IsAvailable() => true;

public bool IsAvailable()
{
// Available in all Windows versions
return true;
}
public bool CustomSoundCheck(DeviceFullInfo audioDevice) => audioDevice.Type == DataFlow.Render && Configuration.CustomSound != null && File.Exists(Configuration.CustomSound.FilePath);
}
}

This file was deleted.

Loading
Loading