summaryrefslogtreecommitdiffstats
path: root/futures/src/subscription
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-06-11 19:41:05 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-06-11 19:41:05 +0200
commit5d7dcf417c694853a606b8fb0a47a580277fc9c0 (patch)
tree8209e3787ee4f4b8ef028fafc9635b1acf777c75 /futures/src/subscription
parent83296a73ebbb3c02ed63dfb4661056a8a8962267 (diff)
downloadiced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.tar.gz
iced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.tar.bz2
iced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.zip
Introduce `subscription::Event`
... and remove `PlatformSpecific` from `Event`
Diffstat (limited to '')
-rw-r--r--futures/src/subscription.rs50
-rw-r--r--futures/src/subscription/tracker.rs19
2 files changed, 46 insertions, 23 deletions
diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs
index 79cea6ed..316fc44d 100644
--- a/futures/src/subscription.rs
+++ b/futures/src/subscription.rs
@@ -3,7 +3,7 @@ mod tracker;
pub use tracker::Tracker;
-use crate::core::event::{self, Event};
+use crate::core::event;
use crate::core::window;
use crate::futures::{Future, Stream};
use crate::{BoxStream, MaybeSend};
@@ -13,10 +13,48 @@ use futures::never::Never;
use std::any::TypeId;
use std::hash::Hash;
+/// A subscription event.
+#[derive(Debug, Clone, PartialEq)]
+pub enum Event {
+ /// A user interacted with a user interface in a window.
+ Interaction {
+ /// The window holding the interface of the interaction.
+ window: window::Id,
+ /// The [`Event`] describing the interaction.
+ ///
+ /// [`Event`]: event::Event
+ event: event::Event,
+
+ /// The [`event::Status`] of the interaction.
+ status: event::Status,
+ },
+
+ /// A platform specific event.
+ PlatformSpecific(PlatformSpecific),
+}
+
+/// A platform specific event
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum PlatformSpecific {
+ /// A MacOS specific event
+ MacOS(MacOS),
+}
+
+/// Describes an event specific to MacOS
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum MacOS {
+ /// Triggered when the app receives an URL from the system
+ ///
+ /// _**Note:** For this event to be triggered, the executable needs to be properly [bundled]!_
+ ///
+ /// [bundled]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19
+ ReceivedUrl(String),
+}
+
/// A stream of runtime events.
///
/// It is the input of a [`Subscription`].
-pub type EventStream = BoxStream<(Event, event::Status, window::Id)>;
+pub type EventStream = BoxStream<Event>;
/// The hasher used for identifying subscriptions.
pub type Hasher = rustc_hash::FxHasher;
@@ -290,9 +328,7 @@ where
pub(crate) fn filter_map<I, F, Message>(id: I, f: F) -> Subscription<Message>
where
I: Hash + 'static,
- F: Fn(Event, event::Status, window::Id) -> Option<Message>
- + MaybeSend
- + 'static,
+ F: Fn(Event) -> Option<Message> + MaybeSend + 'static,
Message: 'static + MaybeSend,
{
Subscription::from_recipe(Runner {
@@ -301,9 +337,7 @@ where
use futures::future;
use futures::stream::StreamExt;
- events.filter_map(move |(event, status, window)| {
- future::ready(f(event, status, window))
- })
+ events.filter_map(move |event| future::ready(f(event)))
},
})
}
diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs
index 086b0f09..f17e3ea3 100644
--- a/futures/src/subscription/tracker.rs
+++ b/futures/src/subscription/tracker.rs
@@ -1,6 +1,4 @@
-use crate::core::event::{self, Event};
-use crate::core::window;
-use crate::subscription::{Hasher, Recipe};
+use crate::subscription::{Event, Hasher, Recipe};
use crate::{BoxFuture, MaybeSend};
use futures::channel::mpsc;
@@ -24,9 +22,7 @@ pub struct Tracker {
#[derive(Debug)]
pub struct Execution {
_cancel: futures::channel::oneshot::Sender<()>,
- listener: Option<
- futures::channel::mpsc::Sender<(Event, event::Status, window::Id)>,
- >,
+ listener: Option<futures::channel::mpsc::Sender<Event>>,
}
impl Tracker {
@@ -142,19 +138,12 @@ impl Tracker {
/// currently open.
///
/// [`Recipe::stream`]: crate::subscription::Recipe::stream
- pub fn broadcast(
- &mut self,
- event: Event,
- status: event::Status,
- window: window::Id,
- ) {
+ pub fn broadcast(&mut self, event: Event) {
self.subscriptions
.values_mut()
.filter_map(|connection| connection.listener.as_mut())
.for_each(|listener| {
- if let Err(error) =
- listener.try_send((event.clone(), status, window))
- {
+ if let Err(error) = listener.try_send(event.clone()) {
log::warn!(
"Error sending event to subscription: {error:?}"
);