@@ -27,16 +27,20 @@ pub struct ScreenCaptureOptions {
2727 /// Screen capture permission persistence
2828 pub persist_mode : PersistMode ,
2929
30+ /// Restore token to restore previous capture
31+ pub restore_token : Option < String > ,
32+
3033 /// Pipewire specific options
3134 pub pipewire : PipewireOptions ,
3235}
3336
3437impl Default for ScreenCaptureOptions {
3538 fn default ( ) -> Self {
36- Self {
39+ ScreenCaptureOptions {
3740 show_cursor : true ,
3841 source_types : SourceType :: all ( ) ,
3942 persist_mode : PersistMode :: DoNot ,
43+ restore_token : None ,
4044 pipewire : PipewireOptions :: default ( ) ,
4145 }
4246 }
@@ -187,6 +191,7 @@ pub struct StreamClosedError;
187191/// To properly close a capture stream call [`StreamHandle::close`].
188192pub struct StreamHandle {
189193 session : Session < ' static , Screencast < ' static > > ,
194+ restore_token : Option < String > ,
190195 sender : pipewire:: channel:: Sender < stream:: Command > ,
191196}
192197
@@ -226,6 +231,11 @@ impl StreamHandle {
226231 . send ( stream:: Command :: RemoveModifier ( modifier) )
227232 . map_err ( |_| StreamClosedError )
228233 }
234+
235+ /// Get the restore token
236+ pub fn restore_token ( & self ) -> Option < & str > {
237+ self . restore_token . as_deref ( )
238+ }
229239}
230240
231241#[ derive( Debug , thiserror:: Error ) ]
@@ -279,13 +289,15 @@ async fn start_screen_capture_boxed(
279289 cursor_mode,
280290 options. source_types ,
281291 false ,
282- None ,
292+ options . restore_token . as_deref ( ) ,
283293 options. persist_mode ,
284294 )
285295 . await ?;
286296
287297 let response = proxy. start ( & session, None ) . await ?. response ( ) ?;
288298
299+ let restore_token = response. restore_token ( ) ;
300+
289301 let stream = response
290302 . streams ( )
291303 . first ( )
@@ -314,5 +326,9 @@ async fn start_screen_capture_boxed(
314326 . await
315327 . map_err ( |_| StartCaptureError :: CaptureThreadPanicked ) ??;
316328
317- Ok ( StreamHandle { session, sender } )
329+ Ok ( StreamHandle {
330+ session,
331+ restore_token : restore_token. map ( |s| s. to_owned ( ) ) ,
332+ sender,
333+ } )
318334}
0 commit comments