2023-08-02 11:54:07 +02:00
|
|
|
// Copyright 2023 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2023-08-15 10:58:46 +02:00
|
|
|
//! Create asynchronous actions to be performed in the background.
|
|
|
|
|
|
2023-08-02 11:54:07 +02:00
|
|
|
use iced::window;
|
2024-10-16 20:36:46 -04:00
|
|
|
use iced::Task;
|
2023-08-02 11:54:07 +02:00
|
|
|
use iced_core::window::Mode;
|
2024-10-16 20:36:46 -04:00
|
|
|
use iced_runtime::{task, Action};
|
2023-08-02 11:54:07 +02:00
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
|
|
/// Yields a command which contains a batch of commands.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn batch<X: Send + 'static + Into<Y>, Y: Send + 'static>(
|
|
|
|
|
commands: impl IntoIterator<Item = Task<X>>,
|
|
|
|
|
) -> Task<Y> {
|
|
|
|
|
Task::batch(commands).map(Into::into)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-15 17:20:19 +02:00
|
|
|
/// Yields a command which will run the future on the runtime executor.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn future<X: Into<Y>, Y: 'static>(future: impl Future<Output = X> + Send + 'static) -> Task<Y> {
|
|
|
|
|
Task::future(async move { future.await.into() })
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Yields a command which will return a message.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> Task<Y> {
|
2024-05-21 05:12:41 +02:00
|
|
|
future(async move { message.into() })
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Initiates a window drag.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn drag<M>(id: window::Id) -> Task<M> {
|
|
|
|
|
iced_runtime::window::drag(id)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 09:53:59 -07:00
|
|
|
/// Maximizes the window.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn maximize<M>(id: window::Id, maximized: bool) -> Task<M> {
|
|
|
|
|
iced_runtime::window::maximize(id, maximized)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Minimizes the window.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn minimize<M>(id: window::Id) -> Task<M> {
|
|
|
|
|
iced_runtime::window::minimize(id, true)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets the title of a window.
|
|
|
|
|
#[allow(unused_variables, clippy::needless_pass_by_value)]
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn set_title<M>(id: window::Id, title: String) -> Task<M> {
|
|
|
|
|
Task::none()
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets the window mode to windowed.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn set_windowed<M>(id: window::Id) -> Task<M> {
|
|
|
|
|
iced_runtime::window::change_mode(id, Mode::Windowed)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-12 09:53:59 -07:00
|
|
|
/// Toggles the windows' maximize state.
|
2024-10-16 20:36:46 -04:00
|
|
|
pub fn toggle_maximize<M>(id: window::Id) -> Task<M> {
|
|
|
|
|
iced_runtime::window::toggle_maximize(id)
|
2023-08-02 11:54:07 +02:00
|
|
|
}
|