@@ -73,14 +73,61 @@ private SecretServiceProxy(DBusConnection connection, string sessionPath)
7373 writer . WriteString ( alias ) ;
7474 buffer = writer . CreateMessage ( ) ;
7575 }
76- return await _connection . CallMethodAsync ( buffer , static ( Message m , object ? _ ) =>
76+ var path = await _connection . CallMethodAsync ( buffer , static ( Message m , object ? _ ) =>
7777 {
7878 var reader = m . GetBodyReader ( ) ;
7979 reader . AlignStruct ( ) ;
80- var collection = reader . ReadObjectPathAsString ( ) ;
81- reader . ReadObjectPath ( ) ; // prompt (ignored)
82- return collection ;
80+ return reader . ReadObjectPathAsString ( ) ;
8381 } , null ) ;
82+ if ( string . IsNullOrEmpty ( path ) || path == "/" )
83+ {
84+ if ( ! string . IsNullOrEmpty ( path ) && path != "/" )
85+ {
86+ return await PromptForObjectPathAsync ( path ) ;
87+ }
88+ return null ;
89+ }
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 ;
84131 }
85132
86133 internal async Task < bool > UnlockAsync ( string objectPath )
@@ -110,25 +157,21 @@ internal async Task<bool> UnlockAsync(string objectPath)
110157 private async Task < bool > PromptAsync ( string promptPath )
111158 {
112159 var tcs = new TaskCompletionSource < bool > ( ) ;
113- using var subscription = await _connection . WatchSignalAsync (
114- SecretsBus , promptPath , "org.freedesktop.Secret.Prompt" , "Completed" ,
115- static ( Message m , object ? _ ) =>
160+ using var subscription = await _connection . WatchSignalAsync ( SecretsBus , promptPath , "org.freedesktop.Secret.Prompt" , "Completed" , static ( Message m , object ? _ ) =>
161+ {
162+ var reader = m . GetBodyReader ( ) ;
163+ return reader . ReadBool ( ) ; // dismissed
164+ } , ( Exception ? ex , bool dismissed ) =>
165+ {
166+ if ( ex is not null )
116167 {
117- var reader = m . GetBodyReader ( ) ;
118- return reader . ReadBool ( ) ; // dismissed
119- } ,
120- ( Exception ? ex , bool dismissed ) =>
168+ tcs . TrySetException ( ex ) ;
169+ }
170+ else
121171 {
122- if ( ex is not null )
123- {
124- tcs . TrySetException ( ex ) ;
125- }
126- else
127- {
128- tcs . TrySetResult ( ! dismissed ) ;
129- }
130- } ,
131- null , /* emitOnCapturedContext */ false , ObserverFlags . None ) ;
172+ tcs . TrySetResult ( ! dismissed ) ;
173+ }
174+ } , null , false , ObserverFlags . None ) ;
132175 MessageBuffer buffer ;
133176 {
134177 using var writer = _connection . GetMessageWriter ( ) ;
0 commit comments