5
5
use crate :: { platform:: macos:: ActivationPolicy , platform_impl:: platform:: app_state:: AppState } ;
6
6
7
7
use cocoa:: base:: id;
8
+ use cocoa:: foundation:: NSString ;
8
9
use objc:: {
9
10
declare:: ClassDecl ,
10
11
runtime:: { Class , Object , Sel } ,
@@ -14,6 +15,10 @@ use std::{
14
15
os:: raw:: c_void,
15
16
} ;
16
17
18
+ use cocoa:: foundation:: NSArray ;
19
+ use cocoa:: foundation:: NSURL ;
20
+ use std:: ffi:: CStr ;
21
+
17
22
static AUX_DELEGATE_STATE_NAME : & str = "auxState" ;
18
23
19
24
pub struct AuxDelegateState {
@@ -34,7 +39,7 @@ unsafe impl Sync for AppDelegateClass {}
34
39
lazy_static ! {
35
40
pub static ref APP_DELEGATE_CLASS : AppDelegateClass = unsafe {
36
41
let superclass = class!( NSResponder ) ;
37
- let mut decl = ClassDecl :: new( "TaoAppDelegate " , superclass) . unwrap( ) ;
42
+ let mut decl = ClassDecl :: new( "TaoAppDelegateParent " , superclass) . unwrap( ) ;
38
43
39
44
decl. add_class_method( sel!( new) , new as extern "C" fn ( & Class , Sel ) -> id) ;
40
45
decl. add_method( sel!( dealloc) , dealloc as extern "C" fn ( & Object , Sel ) ) ;
@@ -47,6 +52,10 @@ lazy_static! {
47
52
sel!( applicationWillTerminate: ) ,
48
53
application_will_terminate as extern "C" fn ( & Object , Sel , id) ,
49
54
) ;
55
+ decl. add_method(
56
+ sel!( application: openURLs: ) ,
57
+ application_open_urls as extern "C" fn ( & Object , Sel , id, id) ,
58
+ ) ;
50
59
decl. add_ivar:: <* mut c_void>( AUX_DELEGATE_STATE_NAME ) ;
51
60
52
61
AppDelegateClass ( decl. register( ) )
@@ -81,7 +90,7 @@ extern "C" fn dealloc(this: &Object, _: Sel) {
81
90
let state_ptr: * mut c_void = * ( this. get_ivar ( AUX_DELEGATE_STATE_NAME ) ) ;
82
91
// As soon as the box is constructed it is immediately dropped, releasing the underlying
83
92
// memory
84
- Box :: from_raw ( state_ptr as * mut RefCell < AuxDelegateState > ) ;
93
+ drop ( Box :: from_raw ( state_ptr as * mut RefCell < AuxDelegateState > ) ) ;
85
94
}
86
95
}
87
96
@@ -96,3 +105,21 @@ extern "C" fn application_will_terminate(_: &Object, _: Sel, _: id) {
96
105
AppState :: exit ( ) ;
97
106
trace ! ( "Completed `applicationWillTerminate`" ) ;
98
107
}
108
+
109
+ extern "C" fn application_open_urls ( _: & Object , _: Sel , _: id , urls : id ) -> ( ) {
110
+ trace ! ( "Trigger `application:openURLs:`" ) ;
111
+
112
+ let urls = unsafe {
113
+ ( 0 ..urls. count ( ) )
114
+ . map ( |i| {
115
+ url:: Url :: parse (
116
+ & CStr :: from_ptr ( urls. objectAtIndex ( i) . absoluteString ( ) . UTF8String ( ) ) . to_string_lossy ( ) ,
117
+ )
118
+ } )
119
+ . flatten ( )
120
+ . collect :: < Vec < _ > > ( )
121
+ } ;
122
+ trace ! ( "Get `application:openURLs:` URLs: {:?}" , urls) ;
123
+ AppState :: open_urls ( urls) ;
124
+ trace ! ( "Completed `application:openURLs:`" ) ;
125
+ }
0 commit comments