diff options
author | 2021-09-01 19:21:49 +0700 | |
---|---|---|
committer | 2021-09-02 13:29:34 +0700 | |
commit | 76698ff2b5753e637b14533650c0d28e681be3c5 (patch) | |
tree | 6b3376df6ac84598b03f2885598b7908e993fe4a /winit | |
parent | b7b7741578257bbf6a8b873c360182e2c9b920ab (diff) | |
download | iced-76698ff2b5753e637b14533650c0d28e681be3c5.tar.gz iced-76698ff2b5753e637b14533650c0d28e681be3c5.tar.bz2 iced-76698ff2b5753e637b14533650c0d28e681be3c5.zip |
Make `Command` implementations platform-specific
This allows us to introduce a platform-specific `Action` to both `iced_native`
and `iced_web` and remove the `Clipboard` from `Application::update` to maintain
purity.
Additionally, this should let us implement further actions to let users query
and modify the shell environment (e.g. window, clipboard, and more!)
Diffstat (limited to 'winit')
-rw-r--r-- | winit/src/application.rs | 28 | ||||
-rw-r--r-- | winit/src/window.rs | 7 |
2 files changed, 29 insertions, 6 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index b683e592..99118ad1 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -30,7 +30,7 @@ use std::mem::ManuallyDrop; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. -pub trait Application: Program<Clipboard = Clipboard> { +pub trait Application: Program { /// The data needed to initialize your [`Application`]. type Flags; @@ -143,7 +143,7 @@ where let subscription = application.subscription(); - runtime.spawn(init_command); + run_command(init_command, &mut runtime); runtime.track(subscription); let window = settings @@ -290,7 +290,6 @@ async fn run_instance<A, E, C>( &mut application, &mut runtime, &mut debug, - &mut clipboard, &mut messages, ); @@ -492,19 +491,36 @@ pub fn update<A: Application, E: Executor>( application: &mut A, runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>, debug: &mut Debug, - clipboard: &mut A::Clipboard, messages: &mut Vec<A::Message>, ) { for message in messages.drain(..) { debug.log_message(&message); debug.update_started(); - let command = runtime.enter(|| application.update(message, clipboard)); + let command = runtime.enter(|| application.update(message)); debug.update_finished(); - runtime.spawn(command); + run_command(command, runtime); } let subscription = application.subscription(); runtime.track(subscription); } + +/// Runs the actions of a [`Command`]. +pub fn run_command<Message: 'static + Send, E: Executor>( + command: Command<Message>, + runtime: &mut Runtime<E, Proxy<Message>, Message>, +) { + use iced_native::command; + + for action in command.actions() { + match action { + command::Action::Future(future) => { + runtime.spawn(future); + } + command::Action::Clipboard(_action) => unimplemented! {}, + command::Action::Window(_action) => unimplemented! {}, + } + } +} diff --git a/winit/src/window.rs b/winit/src/window.rs new file mode 100644 index 00000000..8ccb13ed --- /dev/null +++ b/winit/src/window.rs @@ -0,0 +1,7 @@ +pub use iced_native::window::*; + +/// The window of an [`Application`]. +/// +/// [`Application`]: crate::Application +#[derive(Debug)] +pub struct Window {} |