Skip to content

Commit

Permalink
feat(macos): fire LoopDestroyed when the dock's Quit item is clic…
Browse files Browse the repository at this point in the history
…ked (#351)
  • Loading branch information
lucasfernog authored Mar 28, 2022
1 parent 5ecbac1 commit 34257a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/application-will-terminate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Fire `Event::LoopDestroyed` when the macOS dock `Quit` menu item is clicked.
10 changes: 10 additions & 0 deletions src/platform_impl/macos/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ lazy_static! {
sel!(applicationDidFinishLaunching:),
did_finish_launching as extern "C" fn(&Object, Sel, id),
);
decl.add_method(
sel!(applicationWillTerminate:),
application_will_terminate as extern "C" fn(&Object, Sel, id),
);
decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME);

AppDelegateClass(decl.register())
Expand Down Expand Up @@ -82,3 +86,9 @@ extern "C" fn did_finish_launching(this: &Object, _: Sel, _: id) {
AppState::launched(this);
trace!("Completed `applicationDidFinishLaunching`");
}

extern "C" fn application_will_terminate(_: &Object, _: Sel, _: id) {
trace!("Triggered `applicationWillTerminate`");
AppState::exit();
trace!("Completed `applicationWillTerminate`");
}

0 comments on commit 34257a7

Please sign in to comment.