Skip to content

Commit 31e6fe1

Browse files
committed
fix(Foreground): Issue with Foreground application wrongly detected as SoundSwitch causing SoundSwitch to stop notifying when audio is changed.
1 parent 88f10e9 commit 31e6fe1

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

SoundSwitch.Audio.Manager/AudioSwitcher.cs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using CoreAudio;
6+
using Serilog;
67
using SoundSwitch.Audio.Manager.Interop.Client;
78
using SoundSwitch.Audio.Manager.Interop.Com.Threading;
89
using SoundSwitch.Audio.Manager.Interop.Com.User;
@@ -167,6 +168,11 @@ public void SwitchProcessTo(string deviceId, ERole role, EDataFlow flow, uint pr
167168
public void SwitchForegroundProcessTo(string deviceId, ERole role, EDataFlow flow)
168169
{
169170
var processId = ComThread.Invoke(() => User32.ForegroundProcessId);
171+
if (processId == Environment.ProcessId)
172+
{
173+
Log.Warning("Tried to switch audio device of the app");
174+
return;
175+
}
170176
SwitchProcessTo(deviceId, role, flow, processId);
171177
}
172178

SoundSwitch.Audio.Manager/WindowMonitor.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.Threading.Tasks;
4+
using Serilog;
45
using SoundSwitch.Audio.Manager.Interop.Com.Threading;
56
using SoundSwitch.Audio.Manager.Interop.Com.User;
67

@@ -70,6 +71,12 @@ public WindowMonitor()
7071
//Couldn't find the processId of the window
7172
if (processId == 0) return;
7273

74+
if (processId == Environment.ProcessId)
75+
{
76+
Log.Information("Foreground = SoundSwitch, don't save.");
77+
return;
78+
}
79+
7380
Task.Factory.StartNew(() =>
7481
{
7582
try

SoundSwitch/Framework/Configuration/SoundSwitchConfiguration.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using CoreAudio;
2020
using Newtonsoft.Json;
2121
using Serilog;
22+
using SoundSwitch.Audio.Manager;
2223
using SoundSwitch.Common.Framework.Audio.Device;
2324
using SoundSwitch.Framework.DeviceCyclerManager;
2425
using SoundSwitch.Framework.NotificationManager;
@@ -220,13 +221,14 @@ public bool Migrate()
220221
MigratedFields.Add("CleanupSelectedDevices");
221222
migrated = true;
222223
}
223-
224+
224225
if (!MigratedFields.Contains("CleanupProfilesForeground"))
225226
{
226227
foreach (var profile in Profiles)
227228
{
228229
profile.SwitchForegroundApp = false;
229230
}
231+
230232
MigratedFields.Add("CleanupProfilesForeground");
231233
migrated = true;
232234
}
@@ -241,7 +243,15 @@ public bool Migrate()
241243
.ToHashSet();
242244
MigratedFields.Add("ProfileWin7");
243245
migrated = true;
244-
}
246+
}
247+
248+
var switchForegroundFix = $"{nameof(SwitchForegroundProgram)}_fix";
249+
if (!MigratedFields.Contains(switchForegroundFix) && SwitchForegroundProgram)
250+
{
251+
AudioSwitcher.Instance.ResetProcessDeviceConfiguration();
252+
MigratedFields.Add(switchForegroundFix);
253+
migrated = true;
254+
}
245255

246256
return migrated;
247257
#pragma warning restore 612

0 commit comments

Comments
 (0)