@@ -326,6 +326,20 @@ impl subscription::Server for SubscriptionImpl {
326326 model. read_until = value;
327327 Promise :: ok ( ( ) )
328328 }
329+ fn refresh (
330+ & mut self ,
331+ _: subscription:: RefreshParams ,
332+ _: subscription:: RefreshResults ,
333+ ) -> capnp:: capability:: Promise < ( ) , capnp:: Error > {
334+ let sender = self . topic_listener . clone ( ) ;
335+ Promise :: from_future ( async move {
336+ sender
337+ . send ( ControlFlow :: Continue ( ( ) ) )
338+ . await
339+ . map_err ( |e| capnp:: Error :: failed ( format ! ( "{:?}" , e) ) ) ?;
340+ Ok ( ( ) )
341+ } )
342+ }
329343}
330344
331345#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
@@ -343,7 +357,7 @@ impl SystemNotifier {
343357 dbpath : & str ,
344358 notification_proxy : Arc < dyn models:: NotificationProxy > ,
345359 network : Arc < dyn models:: NetworkMonitorProxy > ,
346- keyring : oo7 :: Keyring ,
360+ credentials : crate :: credentials :: Credentials ,
347361 ) -> Self {
348362 Self {
349363 watching : Rc :: new ( RefCell :: new ( HashMap :: new ( ) ) ) ,
@@ -352,7 +366,7 @@ impl SystemNotifier {
352366 proxy : notification_proxy,
353367 http : build_client ( ) . unwrap ( ) ,
354368 network,
355- keyring : Rc :: new ( keyring ) ,
369+ credentials ,
356370 } ,
357371 }
358372 }
@@ -388,6 +402,18 @@ impl SystemNotifier {
388402 Ok ( ( ) )
389403 } )
390404 }
405+ pub fn refresh_all ( & mut self ) -> Promise < ( ) , capnp:: Error > {
406+ let watching = self . watching . clone ( ) ;
407+ Promise :: from_future ( async move {
408+ let reqs: Vec < _ > = watching
409+ . borrow ( )
410+ . values ( )
411+ . map ( |w| w. refresh_request ( ) )
412+ . collect ( ) ;
413+ join_all ( reqs. into_iter ( ) . map ( |x| x. send ( ) . promise ) ) . await ;
414+ Ok ( ( ) )
415+ } )
416+ }
391417}
392418
393419impl system_notifier:: Server for SystemNotifier {
@@ -457,35 +483,26 @@ impl system_notifier::Server for SystemNotifier {
457483 _: system_notifier:: ListAccountsParams ,
458484 mut results : system_notifier:: ListAccountsResults ,
459485 ) -> capnp:: capability:: Promise < ( ) , capnp:: Error > {
460- let keyring = self . env . keyring . clone ( ) ;
486+ let values = self . env . credentials . list_all ( ) ;
461487
462488 Promise :: from_future ( async move {
463- let attrs = HashMap :: from ( [ ( "type" , "password" ) ] ) ;
464- let values = keyring
465- . search_items ( attrs)
466- . await
467- . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ?;
468-
469489 let mut list = results. get ( ) . init_list ( values. len ( ) as u32 ) ;
470- for ( i, item) in values. iter ( ) . enumerate ( ) {
471- let attrs = item
472- . attributes ( )
473- . await
474- . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ?;
490+ for ( i, item) in values. into_iter ( ) . enumerate ( ) {
475491 let mut acc = list. reborrow ( ) . get ( i as u32 ) ;
476- acc. set_username ( attrs [ "username" ] [ ..] . into ( ) ) ;
477- acc. set_server ( attrs [ "server" ] [ ..] . into ( ) ) ;
492+ acc. set_server ( item . 0 [ ..] . into ( ) ) ;
493+ acc. set_username ( item . 1 . username [ ..] . into ( ) ) ;
478494 }
479495 Ok ( ( ) )
480496 } )
481497 }
482498 fn add_account (
483499 & mut self ,
484500 params : system_notifier:: AddAccountParams ,
485- mut results : system_notifier:: AddAccountResults ,
501+ _ : system_notifier:: AddAccountResults ,
486502 ) -> capnp:: capability:: Promise < ( ) , capnp:: Error > {
487- let keyring = self . env . keyring . clone ( ) ;
503+ let credentials = self . env . credentials . clone ( ) ;
488504 let http = self . env . http . clone ( ) ;
505+ let refresh = self . refresh_all ( ) ;
489506 Promise :: from_future ( async move {
490507 let account = params. get ( ) ?. get_account ( ) ?;
491508 let username = account. get_username ( ) ?. to_str ( ) ?;
@@ -503,15 +520,11 @@ impl system_notifier::Server for SystemNotifier {
503520 . error_for_status ( )
504521 . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ?;
505522
506- let attrs = HashMap :: from ( [
507- ( "type" , "password" ) ,
508- ( "username" , username) ,
509- ( "server" , server) ,
510- ] ) ;
511- keyring
512- . create_item ( "Password" , attrs, password, true )
523+ credentials
524+ . insert ( server, username, password)
513525 . await
514526 . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ?;
527+ refresh. await ?;
515528
516529 info ! ( server = %server, username = %username, "added account" ) ;
517530
@@ -521,21 +534,16 @@ impl system_notifier::Server for SystemNotifier {
521534 fn remove_account (
522535 & mut self ,
523536 params : system_notifier:: RemoveAccountParams ,
524- mut results : system_notifier:: RemoveAccountResults ,
537+ _ : system_notifier:: RemoveAccountResults ,
525538 ) -> capnp:: capability:: Promise < ( ) , capnp:: Error > {
526- let keyring = self . env . keyring . clone ( ) ;
539+ let credentials = self . env . credentials . clone ( ) ;
527540 Promise :: from_future ( async move {
528541 let account = params. get ( ) ?. get_account ( ) ?;
529542 let username = account. get_username ( ) ?. to_str ( ) ?;
530543 let server = account. get_server ( ) ?. to_str ( ) ?;
531544
532- let attrs = HashMap :: from ( [
533- ( "type" , "password" ) ,
534- ( "username" , username) ,
535- ( "server" , server) ,
536- ] ) ;
537- keyring
538- . delete ( attrs)
545+ credentials
546+ . delete ( server)
539547 . await
540548 . map_err ( |e| capnp:: Error :: failed ( e. to_string ( ) ) ) ?;
541549
@@ -561,17 +569,13 @@ pub fn start(
561569 UnixListener :: bind ( & socket_path) . unwrap ( )
562570 } ) ;
563571
564- let keyring = rt. block_on ( async {
565- oo7:: Keyring :: new ( )
566- . await
567- . expect ( "Failed to start Secret Service" )
568- } ) ;
569-
570572 let dbpath = dbpath. to_owned ( ) ;
571573 let f = move || {
574+ let credentials =
575+ rt. block_on ( async { crate :: credentials:: Credentials :: new ( ) . await . unwrap ( ) } ) ;
572576 let local = tokio:: task:: LocalSet :: new ( ) ;
573577 let mut system_notifier =
574- SystemNotifier :: new ( & dbpath, notification_proxy, network_proxy, keyring ) ;
578+ SystemNotifier :: new ( & dbpath, notification_proxy, network_proxy, credentials ) ;
575579 local. spawn_local ( async move {
576580 system_notifier. watch_subscribed ( ) . await . unwrap ( ) ;
577581 let system_client: system_notifier:: Client = capnp_rpc:: new_client ( system_notifier) ;
0 commit comments