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

Add Force Selected Profile option #1120

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public interface ISoundSwitchConfiguration : IConfiguration

bool AutoAddNewConnectedDevices { get; set; }

bool ForceSelectedProfile { get; set; }

/// <summary>
/// What to do with the TrayIcon when changing default device
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public SoundSwitchConfiguration()
// Basic Settings
FirstRun = true;
SwitchForegroundProgram = false;
ForceSelectedProfile = false;

// Audio Settings
ChangeCommunications = false;
Expand Down Expand Up @@ -101,6 +102,8 @@ public SoundSwitchConfiguration()
public bool SwitchForegroundProgram { get; set; }
public IconChangerFactory.ActionEnum SwitchIcon { get; set; }

public bool ForceSelectedProfile { get; set; }

[Obsolete]
public HashSet<ProfileSetting> ProfileSettings { get; set; } = new();

Expand Down
12 changes: 12 additions & 0 deletions SoundSwitch/Framework/Profile/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ private bool IsSteamBigPicture(WindowMonitor.Event @event)
private void SwitchAudio(Profile profile, uint processId)
{
_notificationManager.NotifyProfileChanged(profile, processId);

if (AppModel.Instance.ForceSelectedProfile)
{
_forcedProfile = profile;
}

foreach (var device in profile.Devices)
{
var deviceToUse = CheckDeviceAvailable(device.DeviceInfo);
Expand All @@ -389,6 +395,12 @@ private void SwitchAudio(Profile profile, uint processId)
public void SwitchAudio(Profile profile)
{
_notificationManager.NotifyProfileChanged(profile, null);

if (AppModel.Instance.ForceSelectedProfile)
{
_forcedProfile = profile;
}

foreach (var device in profile.Devices)
{
var deviceToUse = CheckDeviceAvailable(device.DeviceInfo);
Expand Down
10 changes: 10 additions & 0 deletions SoundSwitch/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ public bool AutoAddNewDevice
}
}

public bool ForceSelectedProfile
{
get => AppConfigs.Configuration.ForceSelectedProfile;
set
{
AppConfigs.Configuration.ForceSelectedProfile = value;
AppConfigs.Configuration.Save();
}
}

#region Misc settings

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions SoundSwitch/Model/IAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public interface IAppModel : IDisposable
/// </summary>
bool SwitchForegroundProgram { get; set; }

/// <summary>
/// Behaves same as Having a frofile trigger set to force, but maintains it on the selected profile.
/// Allows changing between desired profiles, while preventing other programs from changing sound settings.
/// </summary>
bool ForceSelectedProfile { get; set; }

/// <summary>
/// Always show banner on primary screen instead of active screen
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions SoundSwitch/UI/Forms/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SoundSwitch/UI/Forms/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public SettingsForm(IAudioDeviceLister audioDeviceLister)
var hotkeysToolTip = new ToolTip();
hotkeysToolTip.SetToolTip(hotkeysCheckBox, SettingsStrings.hotkeysTooltip);

forceSelectedProfileCheckbox.Checked = AppConfigs.Configuration.ForceSelectedProfile;

// Settings - Basic
startWithWindowsCheckBox.Checked = AppModel.Instance.RunAtStartup;

Expand Down Expand Up @@ -807,5 +809,11 @@ private void muteHotKeyCheckbox_CheckedChanged(object sender, EventArgs e)
{
forceSetHotkeys(sender, muteHotKey);
}

private void forceSelectedProfileCheckbox_CheckedChanged(object sender, EventArgs e)
{
AppModel.Instance.ForceSelectedProfile = forceSelectedProfileCheckbox.Checked;
}

}
}