@@ -510,17 +510,38 @@ bool HasOpenSystemPreferencesDialog() {
510510 env, Napi::Function::New (env, NoOp), " calendarCallback" , 0 , 1 );
511511
512512 __block Napi::ThreadSafeFunction tsfn = ts_fn;
513- [[EKEventStore new ]
514- requestAccessToEntityType: EKEntityTypeEvent
515- completion: ^(BOOL granted, NSError *error) {
516- auto callback = [=](Napi::Env env, Napi::Function js_cb,
517- const char *granted) {
518- deferred.Resolve (Napi::String::New (env, granted));
519- };
520- tsfn.BlockingCall (granted ? " authorized" : " denied" ,
521- callback);
522- tsfn.Release ();
523- }];
513+ if (@available (macOS 14.0 , *)) {
514+ const std::string type = info[0 ].As <Napi::String>().Utf8Value ();
515+
516+ EKEventStoreRequestAccessCompletionHandler handler =
517+ ^(BOOL granted, NSError *error) {
518+ auto callback = [=](Napi::Env env, Napi::Function js_cb,
519+ const char *granted) {
520+ deferred.Resolve (Napi::String::New (env, granted));
521+ };
522+ tsfn.BlockingCall (granted ? " authorized" : " denied" , callback);
523+ tsfn.Release ();
524+ };
525+
526+ if (type == " full" ) {
527+ [[EKEventStore new ] requestFullAccessToEventsWithCompletion: handler];
528+ } else {
529+ [[EKEventStore new ] requestWriteOnlyAccessToEventsWithCompletion: handler];
530+ }
531+ } else {
532+ [[EKEventStore new ]
533+ requestAccessToEntityType: EKEntityTypeEvent
534+ completion: ^(BOOL granted, NSError *error) {
535+ auto callback = [=](Napi::Env env,
536+ Napi::Function js_cb,
537+ const char *granted) {
538+ deferred.Resolve (Napi::String::New (env, granted));
539+ };
540+ tsfn.BlockingCall (granted ? " authorized" : " denied" ,
541+ callback);
542+ tsfn.Release ();
543+ }];
544+ }
524545
525546 return deferred.Promise ();
526547}
@@ -533,18 +554,23 @@ bool HasOpenSystemPreferencesDialog() {
533554 env, Napi::Function::New (env, NoOp), " remindersCallback" , 0 , 1 );
534555
535556 __block Napi::ThreadSafeFunction tsfn = ts_fn;
536- [[EKEventStore new ]
537- requestAccessToEntityType: EKEntityTypeReminder
538- completion: ^(BOOL granted, NSError *error) {
539- auto callback = [=](Napi::Env env,
540- Napi::Function prom_cb,
541- const char *granted) {
542- deferred.Resolve (Napi::String::New (env, granted));
543- };
544- tsfn.BlockingCall (granted ? " authorized" : " denied" ,
545- callback);
546- tsfn.Release ();
547- }];
557+
558+ EKEventStoreRequestAccessCompletionHandler handler =
559+ ^(BOOL granted, NSError *error) {
560+ auto callback = [=](Napi::Env env, Napi::Function prom_cb,
561+ const char *granted) {
562+ deferred.Resolve (Napi::String::New (env, granted));
563+ };
564+ tsfn.BlockingCall (granted ? " authorized" : " denied" , callback);
565+ tsfn.Release ();
566+ };
567+
568+ if (@available (macOS 14.0 , *)) {
569+ [[EKEventStore new ] requestFullAccessToRemindersWithCompletion: handler];
570+ } else {
571+ [[EKEventStore new ] requestAccessToEntityType: EKEntityTypeReminder
572+ completion: handler];
573+ }
548574
549575 return deferred.Promise ();
550576}
0 commit comments