Skip to content

Commit

Permalink
fix(profile): possible issue with profile where the the state couldn'…
Browse files Browse the repository at this point in the history
…t be restored after the profile ended.

Fixes SOUNDSWITCH-1HM
  • Loading branch information
Belphemur committed Sep 26, 2023
1 parent ca4463c commit a648e4e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions SoundSwitch/Framework/Profile/ProfileManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ProfileManager
private Profile? _steamProfile;
private Profile? _forcedProfile;

private readonly Dictionary<User32.NativeMethods.HWND, Profile> _activeWindowsTrigger = new();
private readonly ConcurrentDictionary<User32.NativeMethods.HWND, Profile> _activeWindowsTrigger = new();

private readonly Dictionary<string, (Profile Profile, Trigger.Trigger Trigger)> _profileByApplication = new();
private readonly Dictionary<string, (Profile Profile, Trigger.Trigger Trigger)> _profilesByWindowName = new();
Expand Down Expand Up @@ -289,7 +290,7 @@ private bool SaveCurrentState(User32.NativeMethods.HWND windowHandle, Profile pr
RecordingCommunication = recordingCommunication,
NotifyOnActivation = profile.NotifyOnActivation
};
_activeWindowsTrigger.Add(windowHandle, currentState);
_activeWindowsTrigger.TryAdd(windowHandle, currentState);
return true;
}

Expand All @@ -307,7 +308,7 @@ private bool RestoreState(User32.NativeMethods.HWND windowHandle)

SwitchAudio(oldState);
oldState.Dispose();
_activeWindowsTrigger.Remove(windowHandle);
_activeWindowsTrigger.TryRemove(windowHandle, out _);
return true;
}

Expand Down

0 comments on commit a648e4e

Please sign in to comment.