@@ -11,7 +11,7 @@ use zbus::{
1111} ;
1212
1313#[ cfg( any( feature = "gnome_native_crypto" , feature = "gnome_openssl_crypto" ) ) ]
14- use crate :: gnome:: prompter:: { PrompterCallback , PrompterProxy } ;
14+ use crate :: gnome:: prompter:: { GNOMEPrompterCallback , GNOMEPrompterProxy } ;
1515#[ cfg( any( feature = "plasma_native_crypto" , feature = "plasma_openssl_crypto" ) ) ]
1616use crate :: plasma:: prompter:: { PlasmaPrompterCallback , in_plasma_environment} ;
1717use crate :: { error:: custom_service_error, service:: Service } ;
@@ -64,10 +64,10 @@ pub struct Prompt {
6464 collection : Option < crate :: collection:: Collection > ,
6565 /// GNOME Specific
6666 #[ cfg( any( feature = "gnome_native_crypto" , feature = "gnome_openssl_crypto" ) ) ]
67- callback : Arc < OnceCell < PrompterCallback > > ,
67+ gnome_callback : Arc < OnceCell < GNOMEPrompterCallback > > ,
6868 /// KDE Plasma Specific
6969 #[ cfg( any( feature = "plasma_native_crypto" , feature = "plasma_openssl_crypto" ) ) ]
70- callback_plasma : Arc < OnceCell < PlasmaPrompterCallback > > ,
70+ plasma_callback : Arc < OnceCell < PlasmaPrompterCallback > > ,
7171 /// The action to execute when the prompt completes
7272 action : Arc < Mutex < Option < PromptAction > > > ,
7373}
@@ -94,11 +94,10 @@ impl std::fmt::Debug for Prompt {
9494#[ interface( name = "org.freedesktop.Secret.Prompt" ) ]
9595impl Prompt {
9696 pub async fn prompt ( & self , window_id : Optional < & str > ) -> Result < ( ) , ServiceError > {
97+ let window_id = ( * window_id) . and_then ( |w| ashpd:: WindowIdentifierType :: from_str ( w) . ok ( ) ) ;
9798 #[ cfg( any( feature = "plasma_native_crypto" , feature = "plasma_openssl_crypto" ) ) ]
9899 if in_plasma_environment ( self . service . connection ( ) ) . await {
99- use ashpd:: WindowIdentifierType ;
100-
101- if self . callback_plasma . get ( ) . is_some ( ) {
100+ if self . plasma_callback . get ( ) . is_some ( ) {
102101 return Err ( custom_service_error (
103102 "A prompt callback is ongoing already." ,
104103 ) ) ;
@@ -108,7 +107,7 @@ impl Prompt {
108107 PlasmaPrompterCallback :: new ( self . service . clone ( ) , self . path . clone ( ) ) . await ;
109108 let path = OwnedObjectPath :: from ( callback. path ( ) . clone ( ) ) ;
110109
111- self . callback_plasma
110+ self . plasma_callback
112111 . set ( callback. clone ( ) )
113112 . expect ( "A prompt callback is only set once" ) ;
114113 self . service
@@ -117,36 +116,29 @@ impl Prompt {
117116 . await ?;
118117 tracing:: debug!( "Prompt `{}` created." , self . path) ;
119118
120- return callback
121- . start (
122- & self . role ,
123- WindowIdentifierType :: from_str ( window_id. unwrap_or ( "" ) ) . ok ( ) ,
124- & self . label ,
125- )
126- . await ;
119+ return callback. start ( & self . role , window_id, & self . label ) . await ;
127120 }
128121
129122 #[ cfg( any( feature = "gnome_native_crypto" , feature = "gnome_openssl_crypto" ) ) ]
130123 {
131- if self . callback . get ( ) . is_some ( ) {
124+ if self . gnome_callback . get ( ) . is_some ( ) {
132125 return Err ( custom_service_error (
133- "A prompt callback is ongoing already." ,
126+ "A GNOME prompt callback is ongoing already." ,
134127 ) ) ;
135128 } ;
136129
137- let callback = PrompterCallback :: new (
138- ( * window_id) . and_then ( |w| ashpd:: WindowIdentifierType :: from_str ( w) . ok ( ) ) ,
139- self . service . clone ( ) ,
140- self . path . clone ( ) ,
141- )
142- . await
143- . map_err ( |err| {
144- custom_service_error ( & format ! ( "Failed to create PrompterCallback {err}." ) )
145- } ) ?;
130+ let callback =
131+ GNOMEPrompterCallback :: new ( window_id, self . service . clone ( ) , self . path . clone ( ) )
132+ . await
133+ . map_err ( |err| {
134+ custom_service_error ( & format ! (
135+ "Failed to create GNOMEPrompterCallback {err}."
136+ ) )
137+ } ) ?;
146138
147139 let path = OwnedObjectPath :: from ( callback. path ( ) . clone ( ) ) ;
148140
149- self . callback
141+ self . gnome_callback
150142 . set ( callback. clone ( ) )
151143 . expect ( "A prompt callback is only set once" ) ;
152144
@@ -156,7 +148,7 @@ impl Prompt {
156148 // Starts GNOME System Prompting.
157149 // Spawned separately to avoid blocking the early return of the current
158150 // execution.
159- let prompter = PrompterProxy :: new ( self . service . connection ( ) ) . await ?;
151+ let prompter = GNOMEPrompterProxy :: new ( self . service . connection ( ) ) . await ?;
160152 tokio:: spawn ( async move { prompter. begin_prompting ( & path) . await } ) ;
161153
162154 return Ok ( ( ) ) ;
@@ -170,16 +162,16 @@ impl Prompt {
170162
171163 pub async fn dismiss ( & self ) -> Result < ( ) , ServiceError > {
172164 #[ cfg( any( feature = "plasma_native_crypto" , feature = "plasma_openssl_crypto" ) ) ]
173- if let Some ( callback_plasma ) = self . callback_plasma . get ( ) {
165+ if let Some ( callback ) = self . plasma_callback . get ( ) {
174166 let emitter = SignalEmitter :: from_parts (
175167 self . service . connection ( ) . clone ( ) ,
176- callback_plasma . path ( ) . clone ( ) ,
168+ callback . path ( ) . clone ( ) ,
177169 ) ;
178170 PlasmaPrompterCallback :: dismiss ( & emitter) . await ?;
179171 }
180172
181173 #[ cfg( any( feature = "gnome_native_crypto" , feature = "gnome_openssl_crypto" ) ) ]
182- if let Some ( _callback) = self . callback . get ( ) {
174+ if let Some ( _callback) = self . gnome_callback . get ( ) {
183175 // TODO: figure out if we should destroy the un-export the callback
184176 // here?
185177 }
@@ -217,9 +209,9 @@ impl Prompt {
217209 label,
218210 collection,
219211 #[ cfg( any( feature = "gnome_native_crypto" , feature = "gnome_openssl_crypto" ) ) ]
220- callback : Default :: default ( ) ,
212+ gnome_callback : Default :: default ( ) ,
221213 #[ cfg( any( feature = "plasma_native_crypto" , feature = "plasma_openssl_crypto" ) ) ]
222- callback_plasma : Default :: default ( ) ,
214+ plasma_callback : Default :: default ( ) ,
223215 action : Arc :: new ( Mutex :: new ( None ) ) ,
224216 }
225217 }
0 commit comments