Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make context aware #32

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
// Notification.cc represents the top level of the module.
// C++ constructs that are exposed to javascript are exported here

#if NODE_MAJOR_VERSION >= 10
NAN_MODULE_WORKER_ENABLED(Notification, MacNotification::Init)
#else
NODE_MODULE(Notification, MacNotification::Init)
#endif
14 changes: 14 additions & 0 deletions mac_notification.mm
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@
NotificationCenterDelegate *delegate = [[NotificationCenterDelegate alloc] initWithActivationCallback:activated];
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
center.delegate = delegate;

#if NODE_MAJOR_VERSION >= 10
node::AddEnvironmentCleanupHook(
v8::Isolate::GetCurrent(),
[](void *arg) {
auto our_delegate = static_cast<NotificationCenterDelegate*>(arg);
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
if (center.delegate == our_delegate) {
center.delegate = nil;
}
},
const_cast<void*>(static_cast<const void*>(delegate))
);
#endif
}

Nan::Utf8String* MacNotification::StringFromObjectOrNull(Local<Object> object, const char *key) {
Expand Down
3 changes: 2 additions & 1 deletion notification_center_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ static void AsyncSendHandler(uv_async_t *handle) {
Nan::New(info->id).ToLocalChecked()
};

info->callback->Call(3, argv);
Nan::AsyncResource async_resource("NodeMacNotifier:AsyncSendHandler");
info->callback->Call(3, argv, &async_resource);

delete info;
info = nullptr;
Expand Down
Loading