|
|
|
@ -20,27 +20,30 @@ namespace Avalonia.FreeDesktop |
|
|
|
return null; |
|
|
|
|
|
|
|
var dbusFileChooser = new OrgFreedesktopPortalFileChooser(DBusHelper.Connection, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"); |
|
|
|
uint version = 0; |
|
|
|
try |
|
|
|
{ |
|
|
|
await dbusFileChooser.GetVersionPropertyAsync(); |
|
|
|
version = await dbusFileChooser.GetVersionPropertyAsync(); |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return new DBusSystemDialog(DBusHelper.Connection, handle, dbusFileChooser); |
|
|
|
return new DBusSystemDialog(DBusHelper.Connection, handle, dbusFileChooser, version); |
|
|
|
} |
|
|
|
|
|
|
|
private readonly Connection _connection; |
|
|
|
private readonly OrgFreedesktopPortalFileChooser _fileChooser; |
|
|
|
private readonly IPlatformHandle _handle; |
|
|
|
private readonly uint _version; |
|
|
|
|
|
|
|
private DBusSystemDialog(Connection connection, IPlatformHandle handle, OrgFreedesktopPortalFileChooser fileChooser) |
|
|
|
private DBusSystemDialog(Connection connection, IPlatformHandle handle, OrgFreedesktopPortalFileChooser fileChooser, uint version) |
|
|
|
{ |
|
|
|
_connection = connection; |
|
|
|
_fileChooser = fileChooser; |
|
|
|
_handle = handle; |
|
|
|
_version = version; |
|
|
|
} |
|
|
|
|
|
|
|
public override bool CanOpen => true; |
|
|
|
@ -58,6 +61,8 @@ namespace Avalonia.FreeDesktop |
|
|
|
if (filters is not null) |
|
|
|
chooserOptions.Add("filters", filters); |
|
|
|
|
|
|
|
if (options.SuggestedStartLocation?.TryGetLocalPath() is { } folderPath && _version >= 4) |
|
|
|
chooserOptions.Add("current_folder", new DBusVariantItem("ay", new DBusByteArrayItem(Encoding.UTF8.GetBytes(folderPath + "\0")))); |
|
|
|
chooserOptions.Add("multiple", new DBusVariantItem("b", new DBusBoolItem(options.AllowMultiple))); |
|
|
|
|
|
|
|
objectPath = await _fileChooser.OpenFileAsync(parentWindow, options.Title ?? string.Empty, chooserOptions); |
|
|
|
@ -120,7 +125,9 @@ namespace Avalonia.FreeDesktop |
|
|
|
{ "directory", new DBusVariantItem("b", new DBusBoolItem(true)) }, |
|
|
|
{ "multiple", new DBusVariantItem("b", new DBusBoolItem(options.AllowMultiple)) } |
|
|
|
}; |
|
|
|
|
|
|
|
if (options.SuggestedStartLocation?.TryGetLocalPath() is { } folderPath && _version >= 4) |
|
|
|
chooserOptions.Add("current_folder", new DBusVariantItem("ay", new DBusByteArrayItem(Encoding.UTF8.GetBytes(folderPath + "\0")))); |
|
|
|
|
|
|
|
var objectPath = await _fileChooser.OpenFileAsync(parentWindow, options.Title ?? string.Empty, chooserOptions); |
|
|
|
var request = new OrgFreedesktopPortalRequest(_connection, "org.freedesktop.portal.Desktop", objectPath); |
|
|
|
var tsc = new TaskCompletionSource<string[]?>(); |
|
|
|
|