@@ -73,61 +73,24 @@ private SecretServiceProxy(DBusConnection connection, string sessionPath)
7373 writer . WriteString ( alias ) ;
7474 buffer = writer . CreateMessage ( ) ;
7575 }
76- var path = await _connection . CallMethodAsync ( buffer , static ( Message m , object ? _ ) =>
76+ var ( collectionPath , promptPath ) = await _connection . CallMethodAsync ( buffer , static ( Message m , object ? _ ) =>
7777 {
7878 var reader = m . GetBodyReader ( ) ;
7979 reader . AlignStruct ( ) ;
80- return reader . ReadObjectPathAsString ( ) ;
80+ var collection = reader . ReadObjectPathAsString ( ) ;
81+ var prompt = reader . ReadObjectPathAsString ( ) ;
82+ return ( collection , prompt ) ;
8183 } , null ) ;
82- if ( string . IsNullOrEmpty ( path ) || path == "/" )
84+ if ( string . IsNullOrEmpty ( collectionPath ) || collectionPath == "/" )
8385 {
84- if ( ! string . IsNullOrEmpty ( path ) && path != "/" )
86+ if ( ! string . IsNullOrEmpty ( promptPath ) && promptPath != "/" )
8587 {
86- return await PromptForObjectPathAsync ( path ) ;
88+ var result = await PromptAsync ( promptPath ) ;
89+ return result . Dismissed ? null : result . Path ;
8790 }
8891 return null ;
8992 }
90- return path ;
91- }
92-
93- private async Task < string ? > PromptForObjectPathAsync ( string promptPath )
94- {
95- var tcs = new TaskCompletionSource < string ? > ( ) ;
96- using var subscription = await _connection . WatchSignalAsync ( SecretsBus , promptPath , "org.freedesktop.Secret.Prompt" , "Completed" , static ( Message m , object ? _ ) =>
97- {
98- var reader = m . GetBodyReader ( ) ;
99- var dismissed = reader . ReadBool ( ) ;
100- if ( dismissed )
101- {
102- return ( Dismissed : true , Path : ( string ? ) null ) ;
103- }
104- var variant = reader . ReadVariantValue ( ) ;
105- var path = variant . Type == VariantValueType . ObjectPath ? variant . GetObjectPath ( ) . ToString ( ) : null ;
106- return ( Dismissed : false , Path : path ) ;
107- } , ( Exception ? ex , ( bool Dismissed , string ? Path ) result ) =>
108- {
109- if ( ex is not null )
110- {
111- tcs . TrySetException ( ex ) ;
112- }
113- else if ( result . Dismissed )
114- {
115- tcs . TrySetResult ( null ) ;
116- }
117- else
118- {
119- tcs . TrySetResult ( result . Path ) ;
120- }
121- } , null , false , ObserverFlags . None ) ;
122- MessageBuffer buffer ;
123- {
124- using var writer = _connection . GetMessageWriter ( ) ;
125- writer . WriteMethodCallHeader ( SecretsBus , promptPath , "org.freedesktop.Secret.Prompt" , "Prompt" , "s" , MessageFlags . None ) ;
126- writer . WriteString ( "" ) ; // no parent window-id
127- buffer = writer . CreateMessage ( ) ;
128- }
129- await _connection . CallMethodAsync ( buffer ) ;
130- return await tcs . Task ;
93+ return collectionPath ;
13194 }
13295
13396 internal async Task < bool > UnlockAsync ( string objectPath )
@@ -151,25 +114,32 @@ internal async Task<bool> UnlockAsync(string objectPath)
151114 // Object was already unlocked, no user prompt required
152115 return true ;
153116 }
154- return await PromptAsync ( promptPath ) ;
117+ return ! ( await PromptAsync ( promptPath ) ) . Dismissed ;
155118 }
156119
157- private async Task < bool > PromptAsync ( string promptPath )
120+ private async Task < ( bool Dismissed , string ? Path ) > PromptAsync ( string promptPath )
158121 {
159- var tcs = new TaskCompletionSource < bool > ( ) ;
122+ var tcs = new TaskCompletionSource < ( bool Dismissed , string ? Path ) > ( ) ;
160123 using var subscription = await _connection . WatchSignalAsync ( SecretsBus , promptPath , "org.freedesktop.Secret.Prompt" , "Completed" , static ( Message m , object ? _ ) =>
161124 {
162125 var reader = m . GetBodyReader ( ) ;
163- return reader . ReadBool ( ) ; // dismissed
164- } , ( Exception ? ex , bool dismissed ) =>
126+ var dismissed = reader . ReadBool ( ) ;
127+ if ( dismissed )
128+ {
129+ return ( Dismissed : true , Path : ( string ? ) null ) ;
130+ }
131+ var variant = reader . ReadVariantValue ( ) ;
132+ var path = variant . Type == VariantValueType . ObjectPath ? variant . GetObjectPath ( ) . ToString ( ) : null ;
133+ return ( Dismissed : false , Path : path ) ;
134+ } , ( Exception ? ex , ( bool Dismissed , string ? Path ) result ) =>
165135 {
166136 if ( ex is not null )
167137 {
168138 tcs . TrySetException ( ex ) ;
169139 }
170140 else
171141 {
172- tcs . TrySetResult ( ! dismissed ) ;
142+ tcs . TrySetResult ( result ) ;
173143 }
174144 } , null , false , ObserverFlags . None ) ;
175145 MessageBuffer buffer ;
0 commit comments