diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 75a4eb1..e95c53c 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,5 +1,12 @@ use std::io; +#[cfg(target_os = "macos")] +use cocoa_foundation::base::id; +#[cfg(target_os = "macos")] +use cocoa_foundation::foundation::NSRunLoop; +#[cfg(target_os = "macos")] +use objc::{msg_send, sel, sel_impl}; + use tts::*; fn main() -> Result<(), Error> { @@ -42,6 +49,13 @@ fn main() -> Result<(), Error> { } tts.speak("Goodbye.", false)?; let mut _input = String::new(); + #[cfg(target_os = "macos")] + { + let run_loop: id = unsafe { NSRunLoop::currentRunLoop() }; + unsafe { + let _: () = msg_send![run_loop, run]; + } + } io::stdin().read_line(&mut _input)?; Ok(()) } diff --git a/src/backends/ns_speech_synthesizer.rs b/src/backends/ns_speech_synthesizer.rs index fbaf3a4..946d3d6 100644 --- a/src/backends/ns_speech_synthesizer.rs +++ b/src/backends/ns_speech_synthesizer.rs @@ -17,18 +17,24 @@ impl NSSpeechSynthesizerBackend { let mut obj: *mut Object = unsafe { msg_send![class!(NSSpeechSynthesizer), alloc] }; obj = unsafe { msg_send![obj, init] }; let mut decl = ClassDecl::new("MyNSSpeechSynthesizerDelegate", class!(NSObject)).unwrap(); - extern "C" fn speech_synthesizer_did_finish_speaking(_: &Object, _: Sel, _: BOOL) { + extern "C" fn speech_synthesizer_did_finish_speaking( + _: &Object, + _: Sel, + _: *const Object, + _: BOOL, + ) { println!("Got it"); } unsafe { decl.add_method( - sel!(didFinishSpeaking:), - speech_synthesizer_did_finish_speaking as extern "C" fn(&Object, Sel, BOOL) -> (), + sel!(speechSynthesizer:didFinishSpeaking:), + speech_synthesizer_did_finish_speaking + as extern "C" fn(&Object, Sel, *const Object, BOOL) -> (), ) }; let delegate_class = decl.register(); let delegate_obj: *mut Object = unsafe { msg_send![delegate_class, new] }; - let _: () = unsafe { msg_send![obj, setDelegate: delegate_obj] }; + let _: Object = unsafe { msg_send![obj, setDelegate: delegate_obj] }; NSSpeechSynthesizerBackend(obj, delegate_obj) } }