Changed cosmic::command module to cosmic::task and changed cosmic::Task to reexport cosmic::app::Task instead of iced::Task
This commit is contained in:
parent
525a14cfb1
commit
a64529af17
15 changed files with 34 additions and 34 deletions
|
|
@ -61,7 +61,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _flags: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let nav_model = nav_bar::Model::default();
|
let nav_model = nav_bar::Model::default();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let mut nav_model = nav_bar::Model::default();
|
let mut nav_model = nav_bar::Model::default();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let app = App {
|
let app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let mut nav_model = nav_bar::Model::default();
|
let mut nav_model = nav_bar::Model::default();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let id = core.main_window_id().unwrap();
|
let id = core.main_window_id().unwrap();
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
|
|
@ -109,7 +109,7 @@ impl cosmic::Application for App {
|
||||||
self.set_header_title(url.to_string());
|
self.set_header_title(url.to_string());
|
||||||
|
|
||||||
// Reads the selected file into memory.
|
// 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.
|
// Check if its a valid local file path.
|
||||||
let path = match url.scheme() {
|
let path = match url.scheme() {
|
||||||
"file" => url.to_file_path().unwrap(),
|
"file" => url.to_file_path().unwrap(),
|
||||||
|
|
@ -145,7 +145,7 @@ impl cosmic::Application for App {
|
||||||
|
|
||||||
// Creates a new open dialog.
|
// Creates a new open dialog.
|
||||||
Message::OpenFile => {
|
Message::OpenFile => {
|
||||||
return cosmic::command::future(async move {
|
return cosmic::task::future(async move {
|
||||||
eprintln!("opening new dialog");
|
eprintln!("opening new dialog");
|
||||||
|
|
||||||
#[cfg(feature = "rfd")]
|
#[cfg(feature = "rfd")]
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ impl cosmic::Application for App {
|
||||||
&mut self.core
|
&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>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, Task<Self::Message>) {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@ use super::Message;
|
||||||
/// Commands for COSMIC applications.
|
/// Commands for COSMIC applications.
|
||||||
pub type Task<M> = iced::Task<Message<M>>;
|
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> {
|
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.
|
/// Convenience methods for building message-based commands.
|
||||||
pub mod message {
|
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> {
|
pub fn app<M: Send + 'static>(message: M) -> crate::app::Task<M> {
|
||||||
super::message(super::Message::App(message))
|
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> {
|
pub fn cosmic<M: Send + 'static>(message: crate::app::cosmic::Message) -> crate::app::Task<M> {
|
||||||
super::message(super::Message::Cosmic(message))
|
super::message(super::Message::Cosmic(message))
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ impl crate::app::Core {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
return iced::Task::none();
|
||||||
};
|
};
|
||||||
crate::command::drag(id).map(Message::Cosmic)
|
crate::task::drag(id).map(Message::Cosmic)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maximize<M: Send + 'static>(
|
pub fn maximize<M: Send + 'static>(
|
||||||
|
|
@ -43,14 +43,14 @@ impl crate::app::Core {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
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>> {
|
pub fn minimize<M: Send + 'static>(&self, id: Option<window::Id>) -> iced::Task<Message<M>> {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
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>> {
|
pub fn set_scaling_factor<M: Send + 'static>(&self, factor: f32) -> iced::Task<Message<M>> {
|
||||||
|
|
@ -65,7 +65,7 @@ impl crate::app::Core {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
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>(
|
pub fn set_windowed<M: Send + 'static>(
|
||||||
|
|
@ -75,7 +75,7 @@ impl crate::app::Core {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
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>(
|
pub fn toggle_maximize<M: Send + 'static>(
|
||||||
|
|
@ -85,7 +85,7 @@ impl crate::app::Core {
|
||||||
let Some(id) = id.or(self.main_window) else {
|
let Some(id) = id.or(self.main_window) else {
|
||||||
return iced::Task::none();
|
return iced::Task::none();
|
||||||
};
|
};
|
||||||
crate::command::toggle_maximize(id).map(Message::Cosmic)
|
crate::task::toggle_maximize(id).map(Message::Cosmic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -452,7 +452,7 @@ where
|
||||||
/// Grants access to the COSMIC Core.
|
/// Grants access to the COSMIC Core.
|
||||||
fn core_mut(&mut self) -> &mut 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>);
|
fn init(core: Core, flags: Self::Flags) -> (Self, Task<Self::Message>);
|
||||||
|
|
||||||
/// Displays a context drawer on the side of the application window when `Some`.
|
/// Displays a context drawer on the side of the application window when `Some`.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
//! # Open a file
|
//! # Open a file
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! cosmic::command::future(async {
|
//! cosmic::task::future(async {
|
||||||
//! use cosmic::dialog::file_chooser;
|
//! use cosmic::dialog::file_chooser;
|
||||||
//!
|
//!
|
||||||
//! let dialog = file_chooser::open::Dialog::new()
|
//! let dialog = file_chooser::open::Dialog::new()
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
//! # Open multiple files
|
//! # Open multiple files
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! cosmic::command::future(async {
|
//! cosmic::task::future(async {
|
||||||
//! use cosmic::dialog::file_chooser;
|
//! use cosmic::dialog::file_chooser;
|
||||||
//!
|
//!
|
||||||
//! let dialog = file_chooser::open::Dialog::new()
|
//! let dialog = file_chooser::open::Dialog::new()
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
//! # Open a folder
|
//! # Open a folder
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! cosmic::command::future(async {
|
//! cosmic::task::future(async {
|
||||||
//! use cosmic::dialog::file_chooser;
|
//! use cosmic::dialog::file_chooser;
|
||||||
//!
|
//!
|
||||||
//! let dialog = file_chooser::open::Dialog::new()
|
//! let dialog = file_chooser::open::Dialog::new()
|
||||||
|
|
@ -68,7 +68,7 @@
|
||||||
//! # Open multiple folders
|
//! # Open multiple folders
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! cosmic::command::future(async {
|
//! cosmic::task::future(async {
|
||||||
//! use cosmic::dialog::file_chooser;
|
//! use cosmic::dialog::file_chooser;
|
||||||
//!
|
//!
|
||||||
//! let dialog = file_chooser::open::Dialog::new()
|
//! let dialog = file_chooser::open::Dialog::new()
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ pub use app::{Application, ApplicationExt};
|
||||||
#[cfg(feature = "applet")]
|
#[cfg(feature = "applet")]
|
||||||
pub mod applet;
|
pub mod applet;
|
||||||
|
|
||||||
pub use iced::Task;
|
pub use app::Task;
|
||||||
pub mod command;
|
pub mod task;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@ use iced_core::window::Mode;
|
||||||
use iced_runtime::{task, Action};
|
use iced_runtime::{task, Action};
|
||||||
use std::future::Future;
|
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>(
|
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<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> {
|
pub fn future<X: Into<Y>, Y: 'static>(future: impl Future<Output = X> + Send + 'static) -> Task<Y> {
|
||||||
Task::future(async move { future.await.into() })
|
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> {
|
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> Task<Y> {
|
||||||
future(async move { message.into() })
|
future(async move { message.into() })
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ impl<Message: Clone + Send + 'static> Toasts<Message> {
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
{
|
{
|
||||||
let on_close = self.on_close;
|
let on_close = self.on_close;
|
||||||
crate::command::future(async move {
|
crate::task::future(async move {
|
||||||
tokio::time::sleep(duration).await;
|
tokio::time::sleep(duration).await;
|
||||||
on_close(id)
|
on_close(id)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue