Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed cosmic::command to cosmic::task, and made cosmic::Task consistent with cosmic::app::Task #728

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/about/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _flags: Self::Flags) -> (Self, Task<Self::Message>) {
let nav_model = nav_bar::Model::default();

Expand Down
2 changes: 1 addition & 1 deletion examples/application/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, input: Self::Flags) -> (Self, Task<Self::Message>) {
let mut nav_model = nav_bar::Model::default();

Expand Down
2 changes: 1 addition & 1 deletion examples/calendar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let now = Local::now();

Expand Down
2 changes: 1 addition & 1 deletion examples/context-menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let mut app = App {
core,
Expand Down
2 changes: 1 addition & 1 deletion examples/image-button/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let mut app = App {
core,
Expand Down
2 changes: 1 addition & 1 deletion examples/menu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let app = App {
core,
Expand Down
2 changes: 1 addition & 1 deletion examples/nav-context/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, input: Self::Flags) -> (Self, Task<Self::Message>) {
let mut nav_model = nav_bar::Model::default();

Expand Down
6 changes: 3 additions & 3 deletions examples/open-dialog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let id = core.main_window_id().unwrap();
let mut app = App {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl cosmic::Application for App {
self.set_header_title(url.to_string());

// Reads the selected file into memory.
return cosmic::command::future(async move {
return cosmic::task::future(async move {
// Check if its a valid local file path.
let path = match url.scheme() {
"file" => url.to_file_path().unwrap(),
Expand Down Expand Up @@ -145,7 +145,7 @@ impl cosmic::Application for App {

// Creates a new open dialog.
Message::OpenFile => {
return cosmic::command::future(async move {
return cosmic::task::future(async move {
eprintln!("opening new dialog");

#[cfg(feature = "rfd")]
Expand Down
2 changes: 1 addition & 1 deletion examples/text-input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl cosmic::Application for App {
&mut self.core
}

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
let mut app = App {
core,
Expand Down
20 changes: 10 additions & 10 deletions src/app/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ use super::Message;
/// Commands for COSMIC applications.
pub type Task<M> = iced::Task<Message<M>>;

/// Creates a command which yields a [`crate::app::Message`].
/// Creates a task which yields a [`crate::app::Message`].
pub fn message<M: Send + 'static>(message: Message<M>) -> Task<M> {
crate::command::message(message)
crate::task::message(message)
}

/// Convenience methods for building message-based commands.
pub mod message {
/// Creates a command which yields an application message.
/// Creates a task which yields an application message.
pub fn app<M: Send + 'static>(message: M) -> crate::app::Task<M> {
super::message(super::Message::App(message))
}

/// Creates a command which yields a cosmic message.
/// Creates a task which yields a cosmic message.
pub fn cosmic<M: Send + 'static>(message: crate::app::cosmic::Message) -> crate::app::Task<M> {
super::message(super::Message::Cosmic(message))
}
Expand All @@ -32,7 +32,7 @@ impl crate::app::Core {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::drag(id).map(Message::Cosmic)
crate::task::drag(id).map(Message::Cosmic)
}

pub fn maximize<M: Send + 'static>(
Expand All @@ -43,14 +43,14 @@ impl crate::app::Core {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::maximize(id, maximized).map(Message::Cosmic)
crate::task::maximize(id, maximized).map(Message::Cosmic)
}

pub fn minimize<M: Send + 'static>(&self, id: Option<window::Id>) -> iced::Task<Message<M>> {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::minimize(id).map(Message::Cosmic)
crate::task::minimize(id).map(Message::Cosmic)
}

pub fn set_scaling_factor<M: Send + 'static>(&self, factor: f32) -> iced::Task<Message<M>> {
Expand All @@ -65,7 +65,7 @@ impl crate::app::Core {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::set_title(id, title).map(Message::Cosmic)
crate::task::set_title(id, title).map(Message::Cosmic)
}

pub fn set_windowed<M: Send + 'static>(
Expand All @@ -75,7 +75,7 @@ impl crate::app::Core {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::set_windowed(id).map(Message::Cosmic)
crate::task::set_windowed(id).map(Message::Cosmic)
}

pub fn toggle_maximize<M: Send + 'static>(
Expand All @@ -85,7 +85,7 @@ impl crate::app::Core {
let Some(id) = id.or(self.main_window) else {
return iced::Task::none();
};
crate::command::toggle_maximize(id).map(Message::Cosmic)
crate::task::toggle_maximize(id).map(Message::Cosmic)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ where
/// Grants access to the COSMIC Core.
fn core_mut(&mut self) -> &mut Core;

/// Creates the application, and optionally emits command on initialize.
/// Creates the application, and optionally emits task on initialize.
fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>);

/// Displays a context drawer on the side of the application window when `Some`.
Expand Down
8 changes: 4 additions & 4 deletions src/dialog/file_chooser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! # Open a file
//!
//! ```no_run
//! cosmic::command::future(async {
//! cosmic::task::future(async {
//! use cosmic::dialog::file_chooser;
//!
//! let dialog = file_chooser::open::Dialog::new()
Expand All @@ -30,7 +30,7 @@
//! # Open multiple files
//!
//! ```no_run
//! cosmic::command::future(async {
//! cosmic::task::future(async {
//! use cosmic::dialog::file_chooser;
//!
//! let dialog = file_chooser::open::Dialog::new()
Expand All @@ -49,7 +49,7 @@
//! # Open a folder
//!
//! ```no_run
//! cosmic::command::future(async {
//! cosmic::task::future(async {
//! use cosmic::dialog::file_chooser;
//!
//! let dialog = file_chooser::open::Dialog::new()
Expand All @@ -68,7 +68,7 @@
//! # Open multiple folders
//!
//! ```no_run
//! cosmic::command::future(async {
//! cosmic::task::future(async {
//! use cosmic::dialog::file_chooser;
//!
//! let dialog = file_chooser::open::Dialog::new()
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pub use app::{Application, ApplicationExt};
#[cfg(feature = "applet")]
pub mod applet;

pub use iced::Task;
pub mod command;
#[cfg(feature = "winit")]
pub use app::Task;

pub mod task;

pub mod config;

Expand Down
10 changes: 5 additions & 5 deletions src/command/mod.rs → src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ use iced_core::window::Mode;
use iced_runtime::{task, Action};
use std::future::Future;

/// Yields a command which contains a batch of commands.
/// Yields a task which contains a batch of tasks.
pub fn batch<X: Send + 'static + Into<Y>, Y: Send + 'static>(
commands: impl IntoIterator<Item = Task<X>>,
tasks: impl IntoIterator<Item = Task<X>>,
) -> Task<Y> {
Task::batch(commands).map(Into::into)
Task::batch(tasks).map(Into::into)
}

/// Yields a command which will run the future on the runtime executor.
/// Yields a task which will run the future on the runtime executor.
pub fn future<X: Into<Y>, Y: 'static>(future: impl Future<Output = X> + Send + 'static) -> Task<Y> {
Task::future(async move { future.await.into() })
}

/// Yields a command which will return a message.
/// Yields a task which will return a message.
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> Task<Y> {
future(async move { message.into() })
}
Expand Down
2 changes: 1 addition & 1 deletion src/widget/toaster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<Message: Clone + Send + 'static> Toasts<Message> {
#[cfg(feature = "tokio")]
{
let on_close = self.on_close;
crate::command::future(async move {
crate::task::future(async move {
tokio::time::sleep(duration).await;
on_close(id)
})
Expand Down
Loading