@@ -9,7 +9,7 @@ use crate::MaybeSend;
99/// This subscription will notify your application of any [`Event`] that was
1010/// not captured by any widget.
1111pub fn listen ( ) -> Subscription < Event > {
12- listen_with ( |event, status| match status {
12+ listen_with ( |event, status, _window | match status {
1313 event:: Status :: Ignored => Some ( event) ,
1414 event:: Status :: Captured => None ,
1515 } )
@@ -24,21 +24,26 @@ pub fn listen() -> Subscription<Event> {
2424/// - Returns `None`, the [`Event`] will be discarded.
2525/// - Returns `Some` message, the `Message` will be produced.
2626pub fn listen_with < Message > (
27- f : fn ( Event , event:: Status ) -> Option < Message > ,
27+ f : fn ( Event , event:: Status , window :: Id ) -> Option < Message > ,
2828) -> Subscription < Message >
2929where
3030 Message : ' static + MaybeSend ,
3131{
3232 #[ derive( Hash ) ]
3333 struct EventsWith ;
3434
35- subscription:: filter_map (
36- ( EventsWith , f) ,
37- move |event, status| match event {
38- Event :: Window ( _, window:: Event :: RedrawRequested ( _) ) => None ,
39- _ => f ( event, status) ,
40- } ,
41- )
35+ subscription:: filter_map ( ( EventsWith , f) , move |event| match event {
36+ subscription:: Event :: Interaction {
37+ event : Event :: Window ( window:: Event :: RedrawRequested ( _) ) ,
38+ ..
39+ }
40+ | subscription:: Event :: PlatformSpecific ( _) => None ,
41+ subscription:: Event :: Interaction {
42+ window,
43+ event,
44+ status,
45+ } => f ( event, status, window) ,
46+ } )
4247}
4348
4449/// Creates a [`Subscription`] that produces a message for every runtime event,
@@ -47,13 +52,40 @@ where
4752/// **Warning:** This [`Subscription`], if unfiltered, may produce messages in
4853/// an infinite loop.
4954pub fn listen_raw < Message > (
50- f : fn ( Event , event:: Status ) -> Option < Message > ,
55+ f : fn ( Event , event:: Status , window :: Id ) -> Option < Message > ,
5156) -> Subscription < Message >
5257where
5358 Message : ' static + MaybeSend ,
5459{
5560 #[ derive( Hash ) ]
5661 struct RawEvents ;
5762
58- subscription:: filter_map ( ( RawEvents , f) , f)
63+ subscription:: filter_map ( ( RawEvents , f) , move |event| match event {
64+ subscription:: Event :: Interaction {
65+ window,
66+ event,
67+ status,
68+ } => f ( event, status, window) ,
69+ subscription:: Event :: PlatformSpecific ( _) => None ,
70+ } )
71+ }
72+
73+ /// Creates a [`Subscription`] that notifies of custom application URL
74+ /// received from the system.
75+ ///
76+ /// _**Note:** Currently, it only triggers on macOS and the executable needs to be properly [bundled]!_
77+ ///
78+ /// [bundled]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19
79+ pub fn listen_url ( ) -> Subscription < String > {
80+ #[ derive( Hash ) ]
81+ struct ListenUrl ;
82+
83+ subscription:: filter_map ( ListenUrl , move |event| match event {
84+ subscription:: Event :: PlatformSpecific (
85+ subscription:: PlatformSpecific :: MacOS (
86+ subscription:: MacOS :: ReceivedUrl ( url) ,
87+ ) ,
88+ ) => Some ( url) ,
89+ _ => None ,
90+ } )
5991}
0 commit comments