Skip to content

Commit a39e03a

Browse files
committed
fix: SecretService on KDE
1 parent b587927 commit a39e03a

3 files changed

Lines changed: 66 additions & 23 deletions

File tree

Nickvision.Desktop/FreeDesktop/SecretServiceProxy.cs

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

Nickvision.Desktop/Nickvision.Desktop.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<EnableWindowsTargeting>true</EnableWindowsTargeting>
1010
<PackageId>Nickvision.Desktop</PackageId>
11-
<Version>2026.4.6</Version>
11+
<Version>2026.4.7</Version>
1212
<Company>Nickvision</Company>
1313
<Authors>Nickvision</Authors>
1414
<Description>A cross-platform base for Nickvision desktop applications.</Description>

Nickvision.Desktop/System/SecretService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public async Task<bool> AddAsync(Secret secret)
114114
{
115115
collPath = await svc.CreateCollectionAsync("Default keyring", "default");
116116
}
117-
if (string.IsNullOrEmpty(collPath))
117+
if (string.IsNullOrEmpty(collPath) || collPath == "/")
118118
{
119119
_logger.LogError($"Failed to add system secret ({secret.Name}) as the keyring collection could not be accessed.");
120120
return false;

0 commit comments

Comments
 (0)