@@ -1297,6 +1297,74 @@ impl SpircTask {
12971297 ) ;
12981298
12991299 if let Some ( mut cluster) = cluster_update. cluster . take ( ) {
1300+ if let Ok ( reason_enum) = reason {
1301+ match reason_enum {
1302+ ServerClusterUpdateReason :: DEVICE_NEW_CONNECTION
1303+ | ServerClusterUpdateReason :: NEW_DEVICE_APPEARED
1304+ | ServerClusterUpdateReason :: DEVICES_DISAPPEARED => {
1305+ for device_id in & cluster_update. devices_that_changed {
1306+ self . emit_cluster_update ( ClusterUpdateEvent {
1307+ reason : crate :: spirc:: ClusterUpdateReason :: DeviceListChanged ,
1308+ device_id : device_id. clone ( ) ,
1309+ } ) ;
1310+ }
1311+ }
1312+ ServerClusterUpdateReason :: DEVICE_ALIAS_CHANGED
1313+ | ServerClusterUpdateReason :: DEVICE_VOLUME_CHANGED => {
1314+ for device_id in & cluster_update. devices_that_changed {
1315+ self . emit_cluster_update ( ClusterUpdateEvent {
1316+ reason : crate :: spirc:: ClusterUpdateReason :: DeviceInfoChanged ,
1317+ device_id : device_id. clone ( ) ,
1318+ } ) ;
1319+ }
1320+ }
1321+ ServerClusterUpdateReason :: DEVICE_STATE_CHANGED => {
1322+ for device_id in & cluster_update. devices_that_changed {
1323+ self . emit_cluster_update ( ClusterUpdateEvent {
1324+ reason : crate :: spirc:: ClusterUpdateReason :: DeviceStateChanged ,
1325+ device_id : device_id. clone ( ) ,
1326+ } ) ;
1327+ }
1328+ }
1329+ _ => { }
1330+ }
1331+ }
1332+
1333+ // Check for active device changes
1334+ let new_active_device_id = cluster. active_device_id . clone ( ) ;
1335+ if Some ( new_active_device_id. clone ( ) ) != self . last_active_device_id {
1336+ self . emit_cluster_update ( ClusterUpdateEvent {
1337+ reason : crate :: spirc:: ClusterUpdateReason :: ActiveDeviceChanged ,
1338+ device_id : new_active_device_id. clone ( ) ,
1339+ } ) ;
1340+ self . last_active_device_id = Some ( new_active_device_id) ;
1341+ }
1342+
1343+ // Sync device state to cluster_state_sender (after emitting events)
1344+ let devices: HashMap < String , DeviceInfo > = cluster
1345+ . device
1346+ . iter ( )
1347+ . map ( |( _, device) | {
1348+ let info = DeviceInfo {
1349+ device_id : device. device_id . clone ( ) ,
1350+ device_alias : device. name . clone ( ) ,
1351+ device_type : format ! ( "{:?}" , device. device_type) ,
1352+ volume : device. volume as u32 ,
1353+ is_active : device. device_id == cluster. active_device_id ,
1354+ } ;
1355+ ( info. device_id . clone ( ) , info)
1356+ } )
1357+ . collect ( ) ;
1358+
1359+ let _ = self . cluster_state_sender . send ( ClusterState {
1360+ devices,
1361+ active_device_id : if cluster. active_device_id . is_empty ( ) {
1362+ None
1363+ } else {
1364+ Some ( cluster. active_device_id . clone ( ) )
1365+ } ,
1366+ } ) ;
1367+
13001368 let became_inactive = self . connect_state . is_active ( )
13011369 && cluster. active_device_id != self . session . device_id ( ) ;
13021370 if became_inactive {
0 commit comments