// Copyright 2023 System76 // SPDX-License-Identifier: MPL-2.0 #[cfg(feature = "xdg-portal")] use std::os::fd::AsFd; use iced::window; /// Initiates a window drag. pub fn drag(id: window::Id) -> iced::Task> { iced_runtime::window::drag(id) } /// Maximizes the window. pub fn maximize(id: window::Id, maximized: bool) -> iced::Task> { iced_runtime::window::maximize(id, maximized) } /// Minimizes the window. pub fn minimize(id: window::Id) -> iced::Task> { iced_runtime::window::minimize(id, true) } /// Sets the title of a window. #[allow(unused_variables, clippy::needless_pass_by_value)] pub fn set_title(id: window::Id, title: String) -> iced::Task> { iced::Task::none() } #[cfg(feature = "winit")] pub fn set_scaling_factor(factor: f32) -> iced::Task> { iced::Task::done(crate::app::Action::ScaleFactor(factor)).map(crate::Action::Cosmic) } #[cfg(feature = "winit")] pub fn set_theme(theme: crate::Theme) -> iced::Task> { iced::Task::done(crate::app::Action::AppThemeChange(theme)).map(crate::Action::Cosmic) } /// Sets the window mode to windowed. pub fn set_windowed(id: window::Id) -> iced::Task> { iced_runtime::window::set_mode(id, window::Mode::Windowed) } /// Toggles the windows' maximize state. pub fn toggle_maximize(id: window::Id) -> iced::Task> { iced_runtime::window::toggle_maximize(id) } #[cfg(feature = "xdg-portal")] pub fn file_transfer_send( writeable: bool, auto_stop: bool, files: Vec, ) -> iced::Task> { 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>> { dbg!(&key); iced::Task::future(async move { let file_transfer = ashpd::documents::FileTransfer::new().await?; file_transfer.retrieve_files(&key).await }) }