Skip to content

Commit

Permalink
Add OpenURI.SchemeSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Jan 9, 2025
1 parent b02cda9 commit 7d1007e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ The package `LinuxDesktopUtils.XDGDesktopPortals` makes the following [XDG Deskt
- [x] `OpenFile`
- [x] `SaveFile`
- [ ] `SaveFiles`
- [x] [OpenURI](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html) version 4
- [x] [OpenURI](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html) version 5
- [x] `OpenURI`
- [x] `OpenFile`
- [x] `OpenDirectory`
- [x] `SchemeSupported`
- [x] [Secret](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Secret.html) version 1
- [x] `RetrieveSecret`: Note that this method requires a static application ID, which can only be obtained correctly for sandboxed applications. As such, applications running directly on the host will likely get a new master secret with each restart. Applications running on the host should use `libsecret` directly.

Expand Down
1 change: 1 addition & 0 deletions examples/LinuxDesktopUtils.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ await openUriPortal.OpenFileAsync(
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ public async Task<Response> OpenFileInDirectoryAsync(
return await request.GetTask().ConfigureAwait(false);
}

/// <summary>
/// Checks if <see cref="OpenUriAsync"/> supports the protocol scheme.
/// </summary>
/// <param name="value">Uri or a scheme to check</param>
/// <param name="cancellationToken">CancellationToken to cancel the request.</param>
/// <exception cref="PortalVersionException">Thrown if the installed portal backend doesn't support this method.</exception>
public async Task<bool> IsSchemeSupportedAsync(
OneOf<Uri, string> value,
Optional<CancellationToken> cancellationToken = default)
{
const uint addedInVersion = 5;
PortalVersionException.ThrowIf(requiredVersion: addedInVersion, availableVersion: _version);
if (cancellationToken.HasValue) cancellationToken.Value.ThrowIfCancellationRequested();

var scheme = value.Match(
f0: uri => uri.Scheme,
f1: scheme => scheme
);

var handleToken = DBusHelper.CreateHandleToken();
var request = await _connectionManager.CreateRequestAsync(handleToken, cancellationToken).ConfigureAwait(false);
await using var _ = request.ConfigureAwait(false);

var isSupported = await _instance.SchemeSupportedAsync(
scheme: scheme,
options: DBusHelper.EmptyVarDict
).ConfigureAwait(false);

return isSupported;
}

private static string GetFilePath(OneOf<FilePath, Uri> file)
{
if (file.IsT0)
Expand Down

0 comments on commit 7d1007e

Please sign in to comment.