Skip to content

Commit 8ed0f14

Browse files
committed
fix: possible issue where device not removed from the list when renamed
1 parent 9aac99e commit 8ed0f14

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

SoundSwitch.Common/Framework/Audio/Collection/DeviceCollection.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void Add(T item)
5050
throw new ArgumentNullException();
5151
}
5252

53-
_byId.TryAdd(item.Id, item);
54-
_byName.TryAdd(GetNameKey(item), item);
53+
_byId[item.Id] = item;
54+
_byName[GetNameKey(item)] = item;
5555
}
5656

5757
public void Clear()
@@ -82,7 +82,7 @@ public bool Remove(T item)
8282
throw new ArgumentNullException();
8383
}
8484

85-
var removeId = _byId.Remove(item.Id);
85+
var removeId = _byId.Remove(item.Id, out var removedById);
8686
var removeName = _byName.Remove(GetNameKey(item), out var removedByName);
8787

8888
//If we found it by name, remove it also with it's id
@@ -93,6 +93,12 @@ public bool Remove(T item)
9393
_byId.Remove(removedByName.Id);
9494
}
9595

96+
//Same thing if we removed it by ID, try to remove from the name in case the name had changed
97+
if (removeId)
98+
{
99+
_byName.Remove(GetNameKey(removedById));
100+
}
101+
96102
return removeId || removeName;
97103
}
98104

0 commit comments

Comments
 (0)