44
55using ChromaControl . SDK . OpenRGB . Internal ;
66using ChromaControl . SDK . OpenRGB . Structs ;
7- using System . Collections . Concurrent ;
8- using System . Collections . Immutable ;
97using System . Drawing ;
108using System . Text . Json . Nodes ;
119
@@ -15,7 +13,6 @@ namespace ChromaControl.SDK.OpenRGB;
1513public class OpenRGBService : IOpenRGBService , IAsyncDisposable
1614{
1715 private NativeOpenRGBService _service ;
18- private BlockingCollection < OpenRGBDevice > _devices ;
1916 private readonly OpenRGBManager _manager ;
2017
2118 /// <inheritdoc/>
@@ -24,9 +21,6 @@ public class OpenRGBService : IOpenRGBService, IAsyncDisposable
2421 /// <inheritdoc/>
2522 public event EventHandler < bool > ? StartedChanged ;
2623
27- /// <inheritdoc/>
28- public ImmutableList < OpenRGBDevice > Devices => [ .. _devices ] ;
29-
3024 /// <inheritdoc/>
3125 public event EventHandler < IReadOnlyList < OpenRGBDevice > > ? DeviceListUpdated ;
3226
@@ -37,7 +31,6 @@ public OpenRGBService()
3731 {
3832 _manager = new ( ) ;
3933 _service = new ( ) ;
40- _devices = [ ] ;
4134
4235 _service . DeviceListUpdated += OnDeviceListUpdated ;
4336 }
@@ -61,32 +54,27 @@ public async Task Restart(CancellationToken cancellationToken = default)
6154 _service = new ( ) ;
6255 _service . DeviceListUpdated += OnDeviceListUpdated ;
6356
64- _devices = [ ] ;
65-
6657 _manager . Stop ( ) ;
6758
6859 await StartServiceAsync ( cancellationToken ) ;
6960 }
7061 }
7162
7263 /// <inheritdoc/>
73- public async Task UpdateDeviceListAsync ( CancellationToken cancellationToken = default )
64+ public async Task < IReadOnlyList < OpenRGBDevice > > GetDeviceListAsync ( CancellationToken cancellationToken = default )
7465 {
75- while ( _devices . Count > 0 )
76- {
77- _devices . TryTake ( out _ ) ;
78- }
66+ var result = new List < OpenRGBDevice > ( ) ;
7967
8068 var controllerCountResult = await _service . RequestControllerCountAsync ( cancellationToken ) ;
8169
8270 for ( uint i = 0 ; i < controllerCountResult . Count ; i ++ )
8371 {
8472 var controllerDataResult = await _service . RequestControllerDataAsync ( i , cancellationToken ) ;
8573
86- _devices . Add ( controllerDataResult . Device , cancellationToken ) ;
74+ result . Add ( controllerDataResult . Device ) ;
8775 }
8876
89- DeviceListUpdated ? . Invoke ( this , Devices ) ;
77+ return result ;
9078 }
9179
9280 /// <inheritdoc/>
@@ -243,7 +231,8 @@ internal async Task StopServiceAsync()
243231
244232 private async void OnDeviceListUpdated ( object ? sender , EventArgs e )
245233 {
246- await UpdateDeviceListAsync ( ) ;
234+ var devices = await GetDeviceListAsync ( ) ;
235+ DeviceListUpdated ? . Invoke ( this , devices ) ;
247236
248237 Started = true ;
249238 StartedChanged ? . Invoke ( this , Started ) ;
0 commit comments