// Copyright 2023 System76 // SPDX-License-Identifier: MPL-2.0 //! Create asynchronous actions to be performed in the background. use iced::window; use iced::Task; use iced_core::window::Mode; use iced_runtime::{task, Action}; use std::future::Future; /// Yields a command which contains a batch of commands. pub fn batch, Y: Send + 'static>( commands: impl IntoIterator>, ) -> Task { Task::batch(commands).map(Into::into) } /// Yields a command which will run the future on the runtime executor. pub fn future, Y: 'static>(future: impl Future + Send + 'static) -> Task { Task::future(async move { future.await.into() }) } /// Yields a command which will return a message. pub fn message, Y: 'static>(message: X) -> Task { future(async move { message.into() }) } /// Initiates a window drag. pub fn drag(id: window::Id) -> Task { iced_runtime::window::drag(id) } /// Maximizes the window. pub fn maximize(id: window::Id, maximized: bool) -> Task { iced_runtime::window::maximize(id, maximized) } /// Minimizes the window. pub fn minimize(id: window::Id) -> 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) -> Task { Task::none() } /// Sets the window mode to windowed. pub fn set_windowed(id: window::Id) -> Task { iced_runtime::window::change_mode(id, Mode::Windowed) } /// Toggles the windows' maximize state. pub fn toggle_maximize(id: window::Id) -> Task { iced_runtime::window::toggle_maximize(id) }