|
3 | 3 |
|
4 | 4 | use crate::{platform::macos::ActivationPolicy, platform_impl::platform::app_state::AppState};
|
5 | 5 |
|
6 |
| -use cocoa::base::id; |
| 6 | +use cocoa::{ |
| 7 | + base::{id, YES}, |
| 8 | + foundation::NSString, |
| 9 | +}; |
7 | 10 | use objc::{
|
8 | 11 | declare::ClassDecl,
|
9 | 12 | runtime::{Class, Object, Sel},
|
10 | 13 | };
|
11 | 14 | use std::{
|
12 | 15 | cell::{RefCell, RefMut},
|
| 16 | + ffi::CStr, |
13 | 17 | os::raw::c_void,
|
| 18 | + path::PathBuf, |
14 | 19 | };
|
15 | 20 |
|
16 | 21 | static AUX_DELEGATE_STATE_NAME: &str = "auxState";
|
@@ -44,6 +49,10 @@ lazy_static! {
|
44 | 49 | sel!(applicationWillTerminate:),
|
45 | 50 | application_will_terminate as extern "C" fn(&Object, Sel, id),
|
46 | 51 | );
|
| 52 | + decl.add_method( |
| 53 | + sel!(application:openFile:), |
| 54 | + application_open_file as extern "C" fn(&Object, Sel, id, id) -> i8, |
| 55 | + ); |
47 | 56 | decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME);
|
48 | 57 |
|
49 | 58 | AppDelegateClass(decl.register())
|
@@ -92,3 +101,17 @@ extern "C" fn application_will_terminate(_: &Object, _: Sel, _: id) {
|
92 | 101 | AppState::exit();
|
93 | 102 | trace!("Completed `applicationWillTerminate`");
|
94 | 103 | }
|
| 104 | + |
| 105 | +extern "C" fn application_open_file(_: &Object, _: Sel, _: id, file: id) -> i8 { |
| 106 | + let path_string = unsafe { CStr::from_ptr(file.UTF8String()).to_string_lossy() }; |
| 107 | + |
| 108 | + let path = PathBuf::from(path_string.as_ref()); |
| 109 | + trace!("Trigger `application:openFile:` with path: {}", path_string); |
| 110 | + AppState::open_file(path); |
| 111 | + trace!( |
| 112 | + "Completed `application:openFile:` with path: {}", |
| 113 | + &path_string |
| 114 | + ); |
| 115 | + |
| 116 | + return YES; |
| 117 | +} |
0 commit comments