@@ -129,7 +129,7 @@ enum SpircCommand {
129129 Shuffle ( bool ) ,
130130 Repeat ( bool ) ,
131131 RepeatTrack ( bool ) ,
132- Disconnect ,
132+ Disconnect { pause : bool } ,
133133 SetPosition ( u32 ) ,
134134 SetVolume ( u16 ) ,
135135 Activate ,
@@ -311,8 +311,8 @@ impl Spirc {
311311 pub fn set_position_ms ( & self , position_ms : u32 ) -> Result < ( ) , Error > {
312312 Ok ( self . commands . send ( SpircCommand :: SetPosition ( position_ms) ) ?)
313313 }
314- pub fn disconnect ( & self ) -> Result < ( ) , Error > {
315- Ok ( self . commands . send ( SpircCommand :: Disconnect ) ?)
314+ pub fn disconnect ( & self , pause : bool ) -> Result < ( ) , Error > {
315+ Ok ( self . commands . send ( SpircCommand :: Disconnect { pause } ) ?)
316316 }
317317 pub fn activate ( & self ) -> Result < ( ) , Error > {
318318 Ok ( self . commands . send ( SpircCommand :: Activate ) ?)
@@ -438,20 +438,17 @@ impl SpircTask {
438438 error!( "error updating connect state for volume update: {why}" )
439439 }
440440 } ,
441- else => break
441+ else => break ,
442442 }
443443 }
444444
445445 if !self . shutdown && self . connect_state . is_active ( ) {
446- if let Err ( why) = self . notify ( ) . await {
447- warn ! ( "notify before unexpected shutdown couldn't be send: {why}" )
446+ warn ! ( "unexpected shutdown" ) ;
447+ if let Err ( why) = self . handle_disconnect ( ) . await {
448+ error ! ( "error during disconnecting: {why}" )
448449 }
449450 }
450451
451- // clears the session id, leaving an empty state
452- if let Err ( why) = self . session . spclient ( ) . delete_connect_state_request ( ) . await {
453- warn ! ( "deleting connect_state failed before unexpected shutdown: {why}" )
454- }
455452 self . session . dealer ( ) . close ( ) . await ;
456453 }
457454
@@ -651,7 +648,10 @@ impl SpircTask {
651648 self . handle_volume_down ( ) ;
652649 self . notify ( ) . await
653650 }
654- SpircCommand :: Disconnect => {
651+ SpircCommand :: Disconnect { pause } => {
652+ if pause {
653+ self . handle_pause ( )
654+ }
655655 self . handle_disconnect ( ) . await ?;
656656 self . notify ( ) . await
657657 }
@@ -1142,15 +1142,18 @@ impl SpircTask {
11421142 }
11431143
11441144 async fn handle_disconnect ( & mut self ) -> Result < ( ) , Error > {
1145- self . handle_stop ( ) ;
1146-
1147- self . play_status = SpircPlayStatus :: Stopped { } ;
11481145 self . connect_state
11491146 . update_position_in_relation ( self . now_ms ( ) ) ;
11501147 self . notify ( ) . await ?;
11511148
11521149 self . connect_state . became_inactive ( & self . session ) . await ?;
11531150
1151+ // this should clear the active session id, leaving an empty state
1152+ self . session
1153+ . spclient ( )
1154+ . delete_connect_state_request ( )
1155+ . await ?;
1156+
11541157 self . player
11551158 . emit_session_disconnected_event ( self . session . connection_id ( ) , self . session . username ( ) ) ;
11561159
0 commit comments