feat(dnd_destination): xdg file transfer portal support
Requires the `xdg-portal` feature to be enabled to use these features. - Adds `DndDestination::on_file_transfer` method to handle `application/vnd.portal.filetransfer` drop requests - Adds `command::file_transfer_receive` function to handle the file transfer request messages - Adds `command::file_transfer_send` to initiate a file transfer from the application
This commit is contained in:
parent
ae1f15f37e
commit
21c5a4f34a
2 changed files with 55 additions and 0 deletions
|
|
@ -1,6 +1,9 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#[cfg(feature = "xdg-portal")]
|
||||
use std::os::fd::AsFd;
|
||||
|
||||
use iced::window;
|
||||
|
||||
/// Initiates a window drag.
|
||||
|
|
@ -43,3 +46,24 @@ pub fn set_windowed<M>(id: window::Id) -> iced::Task<crate::Action<M>> {
|
|||
pub fn toggle_maximize<M>(id: window::Id) -> iced::Task<crate::Action<M>> {
|
||||
iced_runtime::window::toggle_maximize(id)
|
||||
}
|
||||
|
||||
#[cfg(feature = "xdg-portal")]
|
||||
pub fn file_transfer_send(writeable: bool, auto_stop: bool, files: Vec<impl AsFd + Send + Sync + 'static>) -> iced::Task<ashpd::Result<String>> {
|
||||
iced::Task::future(async move {
|
||||
let file_transfer = ashpd::documents::FileTransfer::new().await?;
|
||||
let key = file_transfer.start_transfer(writeable, auto_stop).await?;
|
||||
file_transfer.add_files(&key, &files).await?;
|
||||
Ok(key)
|
||||
})
|
||||
}
|
||||
|
||||
/// Receive the files offered over the xdg share portal using the `key`.
|
||||
/// Returns a list of file paths.
|
||||
#[cfg(feature = "xdg-portal")]
|
||||
pub fn file_transfer_receive(key: String) -> iced::Task<ashpd::Result<Vec<String>>> {
|
||||
dbg!(&key);
|
||||
iced::Task::future(async move {
|
||||
let file_transfer = ashpd::documents::FileTransfer::new().await?;
|
||||
file_transfer.retrieve_files(&key).await
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue