diff options
author | 2024-06-11 19:41:05 +0200 | |
---|---|---|
committer | 2024-06-11 19:41:05 +0200 | |
commit | 5d7dcf417c694853a606b8fb0a47a580277fc9c0 (patch) | |
tree | 8209e3787ee4f4b8ef028fafc9635b1acf777c75 /futures/src/event.rs | |
parent | 83296a73ebbb3c02ed63dfb4661056a8a8962267 (diff) | |
download | iced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.tar.gz iced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.tar.bz2 iced-5d7dcf417c694853a606b8fb0a47a580277fc9c0.zip |
Introduce `subscription::Event`
... and remove `PlatformSpecific` from `Event`
Diffstat (limited to 'futures/src/event.rs')
-rw-r--r-- | futures/src/event.rs | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/futures/src/event.rs b/futures/src/event.rs index 4f3342ca..72ea78ad 100644 --- a/futures/src/event.rs +++ b/futures/src/event.rs @@ -32,11 +32,17 @@ where #[derive(Hash)] struct EventsWith; - subscription::filter_map((EventsWith, f), move |event, status, window| { - match event { - Event::Window(window::Event::RedrawRequested(_)) => None, - _ => f(event, status, window), + subscription::filter_map((EventsWith, f), move |event| match event { + subscription::Event::Interaction { + event: Event::Window(window::Event::RedrawRequested(_)), + .. } + | subscription::Event::PlatformSpecific(_) => None, + subscription::Event::Interaction { + window, + event, + status, + } => f(event, status, window), }) } @@ -54,5 +60,32 @@ where #[derive(Hash)] struct RawEvents; - subscription::filter_map((RawEvents, f), f) + subscription::filter_map((RawEvents, f), move |event| match event { + subscription::Event::Interaction { + window, + event, + status, + } => f(event, status, window), + subscription::Event::PlatformSpecific(_) => None, + }) +} + +/// Creates a [`Subscription`] that notifies of custom application URL +/// received from the system. +/// +/// _**Note:** Currently, it only triggers on macOS and 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 +pub fn listen_url() -> Subscription<String> { + #[derive(Hash)] + struct ListenUrl; + + subscription::filter_map(ListenUrl, move |event| match event { + subscription::Event::PlatformSpecific( + subscription::PlatformSpecific::MacOS( + subscription::MacOS::ReceivedUrl(url), + ), + ) => Some(url), + _ => None, + }) } |