From 10260b9e73587b85c769791f5884c4c1ca61e24a Mon Sep 17 00:00:00 2001 From: Adam Cosner Date: Wed, 20 Nov 2024 16:32:37 -0800 Subject: [PATCH 1/2] Changed cosmic::command module to cosmic::task and changed cosmic::Task to reexport cosmic::app::Task instead of iced::Task --- examples/about/src/main.rs | 2 +- examples/application/src/main.rs | 2 +- examples/calendar/src/main.rs | 2 +- examples/context-menu/src/main.rs | 2 +- examples/image-button/src/main.rs | 2 +- examples/menu/src/main.rs | 2 +- examples/nav-context/src/main.rs | 2 +- examples/open-dialog/src/main.rs | 6 +++--- examples/text-input/src/main.rs | 2 +- src/app/command.rs | 20 ++++++++++---------- src/app/mod.rs | 2 +- src/dialog/file_chooser/mod.rs | 8 ++++---- src/lib.rs | 4 ++-- src/{command => task}/mod.rs | 10 +++++----- src/widget/toaster/mod.rs | 2 +- 15 files changed, 34 insertions(+), 34 deletions(-) rename src/{command => task}/mod.rs (84%) diff --git a/examples/about/src/main.rs b/examples/about/src/main.rs index 0625e152355..5450b47e87b 100644 --- a/examples/about/src/main.rs +++ b/examples/about/src/main.rs @@ -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) { let nav_model = nav_bar::Model::default(); diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index bf2b5a504b9..a77b9d74b93 100644 --- a/examples/application/src/main.rs +++ b/examples/application/src/main.rs @@ -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) { let mut nav_model = nav_bar::Model::default(); diff --git a/examples/calendar/src/main.rs b/examples/calendar/src/main.rs index 5306d9272d0..bfad5513c6a 100644 --- a/examples/calendar/src/main.rs +++ b/examples/calendar/src/main.rs @@ -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) { let now = Local::now(); diff --git a/examples/context-menu/src/main.rs b/examples/context-menu/src/main.rs index 5ade4966926..840cf865874 100644 --- a/examples/context-menu/src/main.rs +++ b/examples/context-menu/src/main.rs @@ -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) { let mut app = App { core, diff --git a/examples/image-button/src/main.rs b/examples/image-button/src/main.rs index 406f0d1926e..34d907e745c 100644 --- a/examples/image-button/src/main.rs +++ b/examples/image-button/src/main.rs @@ -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) { let mut app = App { core, diff --git a/examples/menu/src/main.rs b/examples/menu/src/main.rs index 1b564a1bedd..5b65732e033 100644 --- a/examples/menu/src/main.rs +++ b/examples/menu/src/main.rs @@ -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) { let app = App { core, diff --git a/examples/nav-context/src/main.rs b/examples/nav-context/src/main.rs index 2285292a742..58e20849269 100644 --- a/examples/nav-context/src/main.rs +++ b/examples/nav-context/src/main.rs @@ -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) { let mut nav_model = nav_bar::Model::default(); diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index a1958880cf3..5ae2df476c5 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -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) { let id = core.main_window_id().unwrap(); let mut app = App { @@ -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(), @@ -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")] diff --git a/examples/text-input/src/main.rs b/examples/text-input/src/main.rs index de6bbd9d2bb..573b9dc142d 100644 --- a/examples/text-input/src/main.rs +++ b/examples/text-input/src/main.rs @@ -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) { let mut app = App { core, diff --git a/src/app/command.rs b/src/app/command.rs index ff51a7d386b..b39118f531b 100644 --- a/src/app/command.rs +++ b/src/app/command.rs @@ -9,19 +9,19 @@ use super::Message; /// Commands for COSMIC applications. pub type Task = iced::Task>; -/// Creates a command which yields a [`crate::app::Message`]. +/// Creates a task which yields a [`crate::app::Message`]. pub fn message(message: Message) -> Task { - 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(message: M) -> crate::app::Task { 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(message: crate::app::cosmic::Message) -> crate::app::Task { super::message(super::Message::Cosmic(message)) } @@ -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( @@ -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(&self, id: Option) -> iced::Task> { 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(&self, factor: f32) -> iced::Task> { @@ -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( @@ -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( @@ -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) } } diff --git a/src/app/mod.rs b/src/app/mod.rs index 88dee959a61..eb53a67ecf2 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -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); /// Displays a context drawer on the side of the application window when `Some`. diff --git a/src/dialog/file_chooser/mod.rs b/src/dialog/file_chooser/mod.rs index 0f328e327df..186f7625db8 100644 --- a/src/dialog/file_chooser/mod.rs +++ b/src/dialog/file_chooser/mod.rs @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/src/lib.rs b/src/lib.rs index fc8758c8d5e..cc396144f8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,8 +22,8 @@ pub use app::{Application, ApplicationExt}; #[cfg(feature = "applet")] pub mod applet; -pub use iced::Task; -pub mod command; +pub use app::Task; +pub mod task; pub mod config; diff --git a/src/command/mod.rs b/src/task/mod.rs similarity index 84% rename from src/command/mod.rs rename to src/task/mod.rs index 2a509bce0e3..379ea19b8dc 100644 --- a/src/command/mod.rs +++ b/src/task/mod.rs @@ -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, Y: Send + 'static>( - commands: impl IntoIterator>, + tasks: impl IntoIterator>, ) -> Task { - 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, Y: 'static>(future: impl Future + Send + 'static) -> Task { 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, Y: 'static>(message: X) -> Task { future(async move { message.into() }) } diff --git a/src/widget/toaster/mod.rs b/src/widget/toaster/mod.rs index 7f7634cfc24..2ed8289e90d 100644 --- a/src/widget/toaster/mod.rs +++ b/src/widget/toaster/mod.rs @@ -193,7 +193,7 @@ impl Toasts { #[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) }) From d6df22e59b064477506ee0b018e8e7369b5a99f2 Mon Sep 17 00:00:00 2001 From: Adam Cosner Date: Wed, 20 Nov 2024 16:42:31 -0800 Subject: [PATCH 2/2] Made app::Task a winit-only feature Not exactly sure why, but the wayland feature disables cosmic::app so this is required --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index cc396144f8f..2b2c9b43b43 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,9 @@ pub use app::{Application, ApplicationExt}; #[cfg(feature = "applet")] pub mod applet; +#[cfg(feature = "winit")] pub use app::Task; + pub mod task; pub mod config;