@ebarooni/capacitor-calendar 8.3.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +179 -71
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +42 -7
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +31 -21
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +59 -15
  5. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CheckPermissionInput.kt +0 -4
  6. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateCalendarInput.kt +3 -1
  7. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteCalendarInput.kt +4 -1
  8. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetDefaultCalendarInput.kt +9 -0
  9. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyCalendarInput.kt +10 -1
  10. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/RequestPermissionInput.kt +3 -5
  11. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CheckAllPermissionsResult.kt +3 -2
  12. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/RequestAllPermissionsResult.kt +1 -1
  13. package/android/src/main/java/dev/barooni/capacitor/calendar/models/templates/PluginCompletion.kt +8 -0
  14. package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +68 -31
  15. package/dist/docs.json +439 -51
  16. package/dist/esm/index.d.ts +8 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +8 -0
  19. package/dist/esm/schemas/enums/calendar-permission-scope.js +8 -0
  20. package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
  21. package/dist/esm/schemas/interfaces/calendar-source.d.ts +3 -0
  22. package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -1
  23. package/dist/esm/schemas/interfaces/calendar.d.ts +12 -2
  24. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  25. package/dist/esm/schemas/interfaces/check-permission-options.d.ts +19 -0
  26. package/dist/esm/schemas/interfaces/check-permission-options.js +2 -0
  27. package/dist/esm/schemas/interfaces/check-permission-options.js.map +1 -0
  28. package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +16 -5
  29. package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
  30. package/dist/esm/schemas/interfaces/create-calendar-result.d.ts +12 -0
  31. package/dist/esm/schemas/interfaces/create-calendar-result.js +2 -0
  32. package/dist/esm/schemas/interfaces/create-calendar-result.js.map +1 -0
  33. package/dist/esm/schemas/interfaces/delete-calendar-options.d.ts +1 -0
  34. package/dist/esm/schemas/interfaces/delete-calendar-options.js.map +1 -1
  35. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.d.ts +13 -0
  36. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js +2 -0
  37. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js.map +1 -0
  38. package/dist/esm/schemas/interfaces/get-default-calendar-options.d.ts +13 -0
  39. package/dist/esm/schemas/interfaces/get-default-calendar-options.js +2 -0
  40. package/dist/esm/schemas/interfaces/get-default-calendar-options.js.map +1 -0
  41. package/dist/esm/schemas/interfaces/list-calendars-result.d.ts +13 -0
  42. package/dist/esm/schemas/interfaces/list-calendars-result.js +2 -0
  43. package/dist/esm/schemas/interfaces/list-calendars-result.js.map +1 -0
  44. package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +7 -2
  45. package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
  46. package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +8 -1
  47. package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
  48. package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +5 -1
  49. package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
  50. package/dist/esm/schemas/interfaces/request-permission-options.d.ts +16 -0
  51. package/dist/esm/schemas/interfaces/request-permission-options.js +2 -0
  52. package/dist/esm/schemas/interfaces/request-permission-options.js.map +1 -0
  53. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.d.ts +14 -0
  54. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js +2 -0
  55. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js.map +1 -0
  56. package/dist/esm/sub-definitions/calendar-access.d.ts +22 -10
  57. package/dist/esm/sub-definitions/calendar-access.js.map +1 -1
  58. package/dist/esm/sub-definitions/calendar-operations.d.ts +61 -14
  59. package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
  60. package/dist/esm/sub-definitions/event-operations.d.ts +15 -1
  61. package/dist/esm/sub-definitions/event-operations.js.map +1 -1
  62. package/dist/esm/sub-definitions/reminders-access.d.ts +4 -0
  63. package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
  64. package/dist/esm/web.d.ts +15 -21
  65. package/dist/esm/web.js +1 -1
  66. package/dist/esm/web.js.map +1 -1
  67. package/dist/plugin.cjs.js +9 -1
  68. package/dist/plugin.cjs.js.map +1 -1
  69. package/dist/plugin.js +9 -1
  70. package/dist/plugin.js.map +1 -1
  71. package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -16
  72. package/ios/Plugin/Implementation/CapacitorCalendar.swift +64 -34
  73. package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +4 -5
  74. package/ios/Plugin/Models/Inputs/DeleteCalendarInput.swift +1 -1
  75. package/ios/Plugin/Models/Inputs/GetDefaultCalendarInput.swift +13 -0
  76. package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +4 -1
  77. package/ios/Plugin/PluginError.swift +68 -56
  78. package/ios/Plugin/Utils/ImplementationHelper.swift +15 -12
  79. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  <img src="https://img.shields.io/npm/l/@ebarooni/capacitor-calendar?style=flat-square" />
7
7
  </a>
8
8
  <a href="https://www.npmjs.com/package/@ebarooni/capacitor-calendar">
9
- <img src="https://img.shields.io/npm/dw/@ebarooni/capacitor-calendar?style=flat-square" />
9
+ <img src="https://img.shields.io/npm/dm/@ebarooni/capacitor-calendar?style=flat-square" />
10
10
  </a>
11
11
  <a href="https://www.npmjs.com/package/@ebarooni/capacitor-calendar">
12
12
  <img src="https://img.shields.io/npm/v/@ebarooni/capacitor-calendar?style=flat-square" />
@@ -175,7 +175,9 @@ await CapacitorCalendar.createEventWithPrompt({
175
175
  > [!NOTE]
176
176
  > On Android, this method always returns null. If you need the event ID, call `listEventsInRange(...)` afterward.
177
177
 
178
- ### List upcoming events
178
+ ### List events in a range
179
+
180
+ `listEventsInRange` returns events that overlap the given range, not only events that start or end inside it. Multi-day events that span the interval are included.
179
181
 
180
182
  ```typescript
181
183
  const now = Date.now();
@@ -189,6 +191,20 @@ const { result: events } = await CapacitorCalendar.listEventsInRange({
189
191
  console.log('Upcoming events:', events);
190
192
  ```
191
193
 
194
+ To list events on a single day, use that day's bounds:
195
+
196
+ ```typescript
197
+ const startOfDay = new Date();
198
+ startOfDay.setHours(0, 0, 0, 0);
199
+ const startOfNextDay = new Date(startOfDay);
200
+ startOfNextDay.setDate(startOfNextDay.getDate() + 1);
201
+
202
+ const { result: todaysEvents } = await CapacitorCalendar.listEventsInRange({
203
+ from: startOfDay.getTime(),
204
+ to: startOfNextDay.getTime(),
205
+ });
206
+ ```
207
+
192
208
  ### Working with Calendars
193
209
 
194
210
  ```typescript
@@ -252,7 +268,7 @@ See [CHANGELOG.md](CHANGELOG.md) for the latest updates and release history.
252
268
  * [`selectCalendarsWithPrompt(...)`](#selectcalendarswithprompt)
253
269
  * [`fetchAllCalendarSources()`](#fetchallcalendarsources)
254
270
  * [`listCalendars()`](#listcalendars)
255
- * [`getDefaultCalendar()`](#getdefaultcalendar)
271
+ * [`getDefaultCalendar(...)`](#getdefaultcalendar)
256
272
  * [`openCalendar(...)`](#opencalendar)
257
273
  * [`createCalendar(...)`](#createcalendar)
258
274
  * [`deleteCalendar(...)`](#deletecalendar)
@@ -283,14 +299,15 @@ See [CHANGELOG.md](CHANGELOG.md) for the latest updates and release history.
283
299
  ### checkPermission(...)
284
300
 
285
301
  ```typescript
286
- checkPermission(options: { scope: CalendarPermissionScope; }) => Promise<{ result: PermissionState; }>
302
+ checkPermission(options: CheckPermissionOptions) => Promise<{ result: PermissionState; }>
287
303
  ```
288
304
 
289
305
  Retrieves the current permission state for a given scope.
306
+ On Android, `readReminders` and `writeReminders` resolve to `"prompt"`.
290
307
 
291
- | Param | Type |
292
- | ------------- | --------------------------------------------------------------------------------------- |
293
- | **`options`** | <code>{ scope: <a href="#calendarpermissionscope">CalendarPermissionScope</a>; }</code> |
308
+ | Param | Type |
309
+ | ------------- | ------------------------------------------------------------------------- |
310
+ | **`options`** | <code><a href="#checkpermissionoptions">CheckPermissionOptions</a></code> |
294
311
 
295
312
  **Returns:** <code>Promise&lt;{ result: <a href="#permissionstate">PermissionState</a>; }&gt;</code>
296
313
 
@@ -308,6 +325,7 @@ checkAllPermissions() => Promise<{ result: CheckAllPermissionsResult; }>
308
325
  ```
309
326
 
310
327
  Retrieves the current state of all permissions.
328
+ On Android, reminder keys always resolve to `"prompt"`.
311
329
 
312
330
  **Returns:** <code>Promise&lt;{ result: <a href="#checkallpermissionsresult">CheckAllPermissionsResult</a>; }&gt;</code>
313
331
 
@@ -321,14 +339,15 @@ Retrieves the current state of all permissions.
321
339
  ### requestPermission(...)
322
340
 
323
341
  ```typescript
324
- requestPermission(options: { scope: CalendarPermissionScope; }) => Promise<{ result: PermissionState; }>
342
+ requestPermission(options: RequestPermissionOptions) => Promise<{ result: PermissionState; }>
325
343
  ```
326
344
 
327
345
  Requests permission for a given scope.
346
+ On Android, `readReminders` and `writeReminders` reject with `Invalid scope.`
328
347
 
329
- | Param | Type |
330
- | ------------- | --------------------------------------------------------------------------------------- |
331
- | **`options`** | <code>{ scope: <a href="#calendarpermissionscope">CalendarPermissionScope</a>; }</code> |
348
+ | Param | Type |
349
+ | ------------- | ----------------------------------------------------------------------------- |
350
+ | **`options`** | <code><a href="#requestpermissionoptions">RequestPermissionOptions</a></code> |
332
351
 
333
352
  **Returns:** <code>Promise&lt;{ result: <a href="#permissionstate">PermissionState</a>; }&gt;</code>
334
353
 
@@ -346,6 +365,7 @@ requestAllPermissions() => Promise<{ result: RequestAllPermissionsResult; }>
346
365
  ```
347
366
 
348
367
  Requests permission for all calendar and reminder permissions.
368
+ On Android, only calendar permissions are requested; reminder keys stay `"prompt"`.
349
369
 
350
370
  **Returns:** <code>Promise&lt;{ result: <a href="#checkallpermissionsresult">CheckAllPermissionsResult</a>; }&gt;</code>
351
371
 
@@ -414,6 +434,8 @@ requestFullRemindersAccess() => Promise<{ result: PermissionState; }>
414
434
  ```
415
435
 
416
436
  Requests read and write access to the reminders.
437
+ Resolves with `"granted"` or `"denied"` (never `"prompt"`).
438
+ A grant covers both `readReminders` and `writeReminders`.
417
439
 
418
440
  **Returns:** <code>Promise&lt;{ result: <a href="#permissionstate">PermissionState</a>; }&gt;</code>
419
441
 
@@ -576,7 +598,10 @@ Opens a dialog to delete an event.
576
598
  listEventsInRange(options: ListEventsInRangeOptions) => Promise<{ result: CalendarEvent[]; }>
577
599
  ```
578
600
 
579
- Retrieves the events within a date range.
601
+ Retrieves events that overlap a date range.
602
+
603
+ An event is included when its time interval intersects `[from, to]`, including
604
+ multi-day events that span the range without starting or ending inside it.
580
605
 
581
606
  | Param | Type |
582
607
  | ------------- | ----------------------------------------------------------------------------- |
@@ -609,16 +634,25 @@ Saves pending calendar changes.
609
634
  ### selectCalendarsWithPrompt(...)
610
635
 
611
636
  ```typescript
612
- selectCalendarsWithPrompt(options?: SelectCalendarsWithPromptOptions | undefined) => Promise<{ result: Calendar[]; }>
637
+ selectCalendarsWithPrompt(options?: SelectCalendarsWithPromptOptions | undefined) => Promise<SelectCalendarsWithPromptResult>
613
638
  ```
614
639
 
615
640
  Opens a system interface to choose one or multiple calendars.
616
641
 
642
+ Calendar access is expected. Call `requestFullCalendarAccess()` first.
643
+ Without authorization the chooser can look empty.
644
+
645
+ On confirm, `result` contains the calendars the user selected.
646
+ On cancel, `result` is an empty array.
647
+
648
+ If a chooser is already presented, a new call is rejected; the in-flight
649
+ call continues until the user confirms or cancels.
650
+
617
651
  | Param | Type |
618
652
  | ------------- | --------------------------------------------------------------------------------------------- |
619
653
  | **`options`** | <code><a href="#selectcalendarswithpromptoptions">SelectCalendarsWithPromptOptions</a></code> |
620
654
 
621
- **Returns:** <code>Promise&lt;{ result: Calendar[]; }&gt;</code>
655
+ **Returns:** <code>Promise&lt;<a href="#selectcalendarswithpromptresult">SelectCalendarsWithPromptResult</a>&gt;</code>
622
656
 
623
657
  **Since:** 0.2.0
624
658
 
@@ -630,12 +664,15 @@ Opens a system interface to choose one or multiple calendars.
630
664
  ### fetchAllCalendarSources()
631
665
 
632
666
  ```typescript
633
- fetchAllCalendarSources() => Promise<{ result: CalendarSource[]; }>
667
+ fetchAllCalendarSources() => Promise<FetchAllCalendarSourcesResult>
634
668
  ```
635
669
 
636
670
  Retrieves a list of calendar sources.
637
671
 
638
- **Returns:** <code>Promise&lt;{ result: CalendarSource[]; }&gt;</code>
672
+ Requires calendar access. Without authorization, `result` is typically
673
+ an empty array. This method does not reject solely for missing permission.
674
+
675
+ **Returns:** <code>Promise&lt;<a href="#fetchallcalendarsourcesresult">FetchAllCalendarSourcesResult</a>&gt;</code>
639
676
 
640
677
  **Since:** 6.6.0
641
678
 
@@ -647,12 +684,15 @@ Retrieves a list of calendar sources.
647
684
  ### listCalendars()
648
685
 
649
686
  ```typescript
650
- listCalendars() => Promise<{ result: Calendar[]; }>
687
+ listCalendars() => Promise<ListCalendarsResult>
651
688
  ```
652
689
 
653
690
  Retrieves a list of all available calendars.
654
691
 
655
- **Returns:** <code>Promise&lt;{ result: Calendar[]; }&gt;</code>
692
+ Requires calendar read access. On Android, missing permission typically
693
+ rejects. On iOS, missing authorization typically returns an empty `result`.
694
+
695
+ **Returns:** <code>Promise&lt;<a href="#listcalendarsresult">ListCalendarsResult</a>&gt;</code>
656
696
 
657
697
  **Since:** 7.1.0
658
698
 
@@ -661,14 +701,26 @@ Retrieves a list of all available calendars.
661
701
  --------------------
662
702
 
663
703
 
664
- ### getDefaultCalendar()
704
+ ### getDefaultCalendar(...)
665
705
 
666
706
  ```typescript
667
- getDefaultCalendar() => Promise<{ result: Calendar | null; }>
707
+ getDefaultCalendar(options?: GetDefaultCalendarOptions | undefined) => Promise<{ result: Calendar | null; }>
668
708
  ```
669
709
 
670
710
  Retrieves the default calendar.
671
711
 
712
+ Requires calendar read access. On Android, missing permission typically
713
+ rejects. On iOS, missing authorization typically yields `result: null`.
714
+
715
+ The system default is the primary calendar on Android and
716
+ `defaultCalendarForNewEvents` on iOS. When neither exists and
717
+ `useFallbackCalendar` is true, the first available calendar is returned.
718
+ Otherwise the method returns `null` when there is no system default.
719
+
720
+ | Param | Type |
721
+ | ------------- | ------------------------------------------------------------------------------- |
722
+ | **`options`** | <code><a href="#getdefaultcalendaroptions">GetDefaultCalendarOptions</a></code> |
723
+
672
724
  **Returns:** <code>Promise&lt;{ result: <a href="#calendar">Calendar</a> | null; }&gt;</code>
673
725
 
674
726
  **Since:** 0.3.0
@@ -700,16 +752,19 @@ Opens the calendar app.
700
752
  ### createCalendar(...)
701
753
 
702
754
  ```typescript
703
- createCalendar(options: CreateCalendarOptions) => Promise<{ id: string; }>
755
+ createCalendar(options: CreateCalendarOptions) => Promise<CreateCalendarResult>
704
756
  ```
705
757
 
706
758
  Creates a calendar.
707
759
 
760
+ `title` is required. `color` is optional and defaults to `#007AFF`.
761
+ On Android, `accountName` and `ownerAccount` are required at runtime.
762
+
708
763
  | Param | Type |
709
764
  | ------------- | ----------------------------------------------------------------------- |
710
765
  | **`options`** | <code><a href="#createcalendaroptions">CreateCalendarOptions</a></code> |
711
766
 
712
- **Returns:** <code>Promise&lt;{ id: string; }&gt;</code>
767
+ **Returns:** <code>Promise&lt;<a href="#createcalendarresult">CreateCalendarResult</a>&gt;</code>
713
768
 
714
769
  **Since:** 5.2.0
715
770
 
@@ -1029,6 +1084,24 @@ Update a reminders list with options.
1029
1084
  ### Interfaces
1030
1085
 
1031
1086
 
1087
+ #### CheckPermissionOptions
1088
+
1089
+ Options for {@link CalendarAccess#checkPermission}.
1090
+
1091
+ | Prop | Type | Description | Since | Platform |
1092
+ | ----------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----- | ------------ |
1093
+ | **`scope`** | <code><a href="#calendarpermissionscope">CalendarPermissionScope</a></code> | The permission scope to check. On Android, `readReminders` and `writeReminders` resolve to `"prompt"` (reminders are not supported on Android). | 8.3.1 | Android, iOS |
1094
+
1095
+
1096
+ #### RequestPermissionOptions
1097
+
1098
+ Options for {@link CalendarAccess#requestPermission}.
1099
+
1100
+ | Prop | Type | Description | Since | Platform |
1101
+ | ----------- | --------------------------------------------------------------------------- | -------------------------------- | ----- | ------------ |
1102
+ | **`scope`** | <code><a href="#calendarpermissionscope">CalendarPermissionScope</a></code> | The permission scope to request. | 8.3.1 | Android, iOS |
1103
+
1104
+
1032
1105
  #### CreateEventWithPromptOptions
1033
1106
 
1034
1107
  | Prop | Type | Description | Since | Platform |
@@ -1204,39 +1277,46 @@ Update a reminders list with options.
1204
1277
 
1205
1278
  #### ListEventsInRangeOptions
1206
1279
 
1207
- | Prop | Type | Description | Since |
1208
- | ---------- | ------------------- | ------------------------------ | ----- |
1209
- | **`from`** | <code>number</code> | The timestamp in milliseconds. | 7.1.0 |
1210
- | **`to`** | <code>number</code> | The timestamp in milliseconds. | 7.1.0 |
1280
+ | Prop | Type | Description | Since |
1281
+ | ---------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
1282
+ | **`from`** | <code>number</code> | The start of the range, in milliseconds since the epoch. Events still in progress at this time are included. | 7.1.0 |
1283
+ | **`to`** | <code>number</code> | The end of the range, in milliseconds since the epoch. Events that begin at or after this time are typically excluded; prefer the next day's start when querying a single calendar day. | 7.1.0 |
1284
+
1285
+
1286
+ #### SelectCalendarsWithPromptResult
1287
+
1288
+ | Prop | Type | Description | Since | Platform |
1289
+ | ------------ | ----------------------- | ------------------------------------------------------------------------- | ----- | -------- |
1290
+ | **`result`** | <code>Calendar[]</code> | Calendars the user confirmed in the chooser. Empty when the user cancels. | 8.4.0 | iOS |
1211
1291
 
1212
1292
 
1213
1293
  #### Calendar
1214
1294
 
1215
- | Prop | Type | Description | Since | Platform |
1216
- | -------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------ | ----- | ------------ |
1217
- | **`id`** | <code>string</code> | | 7.1.0 | Android, iOS |
1218
- | **`title`** | <code>string</code> | | 7.1.0 | Android, iOS |
1219
- | **`internalTitle`** | <code>string \| null</code> | Internal name of the calendar (`CalendarContract.Calendars.NAME`). | 7.1.0 | Android |
1220
- | **`color`** | <code>string</code> | | 7.1.0 | Android, iOS |
1221
- | **`isImmutable`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1222
- | **`allowsContentModifications`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1223
- | **`type`** | <code><a href="#calendartype">CalendarType</a> \| null</code> | | 7.1.0 | iOS |
1224
- | **`isSubscribed`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1225
- | **`source`** | <code><a href="#calendarsource">CalendarSource</a> \| null</code> | | 7.1.0 | iOS |
1226
- | **`visible`** | <code>boolean \| null</code> | Indicates if the events from this calendar should be shown. | 7.1.0 | Android |
1227
- | **`accountName`** | <code>string \| null</code> | The account under which the calendar is registered. | 7.1.0 | Android |
1228
- | **`ownerAccount`** | <code>string \| null</code> | The owner of the calendar. | 7.1.0 | Android |
1229
- | **`maxReminders`** | <code>number \| null</code> | Maximum number of reminders allowed per event. | 7.1.0 | Android |
1230
- | **`location`** | <code>string \| null</code> | | 7.1.0 | Android |
1295
+ | Prop | Type | Description | Since | Platform |
1296
+ | -------------------------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | ------------ |
1297
+ | **`id`** | <code>string</code> | | 7.1.0 | Android, iOS |
1298
+ | **`title`** | <code>string \| null</code> | Display title of the calendar. May be `null` when the platform does not provide a title. | 7.1.0 | Android, iOS |
1299
+ | **`internalTitle`** | <code>string \| null</code> | Internal name of the calendar (`CalendarContract.Calendars.NAME`). | 7.1.0 | Android |
1300
+ | **`color`** | <code>string \| null</code> | <a href="#calendar">Calendar</a> color as a hex string. Format: `#RRGGBB` when opaque; `#RRGGBBAA` when alpha is below fully opaque. May be `null` when the platform does not provide a color. | 7.1.0 | Android, iOS |
1301
+ | **`isImmutable`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1302
+ | **`allowsContentModifications`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1303
+ | **`type`** | <code><a href="#calendartype">CalendarType</a> \| null</code> | | 7.1.0 | iOS |
1304
+ | **`isSubscribed`** | <code>boolean \| null</code> | | 7.1.0 | iOS |
1305
+ | **`source`** | <code><a href="#calendarsource">CalendarSource</a> \| null</code> | | 7.1.0 | iOS |
1306
+ | **`visible`** | <code>boolean \| null</code> | Indicates if the events from this calendar should be shown. | 7.1.0 | Android |
1307
+ | **`accountName`** | <code>string \| null</code> | The account under which the calendar is registered. | 7.1.0 | Android |
1308
+ | **`ownerAccount`** | <code>string \| null</code> | The owner of the calendar. | 7.1.0 | Android |
1309
+ | **`maxReminders`** | <code>number \| null</code> | Maximum number of reminders allowed per event. | 7.1.0 | Android |
1310
+ | **`location`** | <code>string \| null</code> | | 7.1.0 | Android |
1231
1311
 
1232
1312
 
1233
1313
  #### CalendarSource
1234
1314
 
1235
- | Prop | Type | Since |
1236
- | ----------- | ----------------------------------------------------------------- | ----- |
1237
- | **`type`** | <code><a href="#calendarsourcetype">CalendarSourceType</a></code> | 7.1.0 |
1238
- | **`id`** | <code>string</code> | 7.1.0 |
1239
- | **`title`** | <code>string</code> | 7.1.0 |
1315
+ | Prop | Type | Since | Platform |
1316
+ | ----------- | ----------------------------------------------------------------- | ----- | -------- |
1317
+ | **`type`** | <code><a href="#calendarsourcetype">CalendarSourceType</a></code> | 7.1.0 | iOS |
1318
+ | **`id`** | <code>string</code> | 7.1.0 | iOS |
1319
+ | **`title`** | <code>string</code> | 7.1.0 | iOS |
1240
1320
 
1241
1321
 
1242
1322
  #### SelectCalendarsWithPromptOptions
@@ -1247,38 +1327,66 @@ Update a reminders list with options.
1247
1327
  | **`multiple`** | <code>boolean</code> | Allow multiple selections. | <code>false</code> | 7.1.0 |
1248
1328
 
1249
1329
 
1330
+ #### FetchAllCalendarSourcesResult
1331
+
1332
+ | Prop | Type | Description | Since | Platform |
1333
+ | ------------ | ----------------------------- | -------------------------------------------------- | ----- | -------- |
1334
+ | **`result`** | <code>CalendarSource[]</code> | All calendar sources (accounts) known to EventKit. | 8.4.0 | iOS |
1335
+
1336
+
1337
+ #### ListCalendarsResult
1338
+
1339
+ | Prop | Type | Description | Since | Platform |
1340
+ | ------------ | ----------------------- | ------------------------ | ----- | ------------ |
1341
+ | **`result`** | <code>Calendar[]</code> | All available calendars. | 8.4.0 | Android, iOS |
1342
+
1343
+
1344
+ #### GetDefaultCalendarOptions
1345
+
1346
+ | Prop | Type | Description | Default | Since | Platform |
1347
+ | ------------------------- | -------------------- | --------------------------------------------------------------------------- | ------------------ | ----- | ------------ |
1348
+ | **`useFallbackCalendar`** | <code>boolean</code> | When there is no system default calendar, use the first available calendar. | <code>false</code> | 8.4.0 | Android, iOS |
1349
+
1350
+
1250
1351
  #### OpenCalendarOptions
1251
1352
 
1252
- | Prop | Type | Default | Since |
1253
- | ---------- | ------------------- | ----------------------- | ----- |
1254
- | **`date`** | <code>number</code> | <code>Date.now()</code> | 7.1.0 |
1353
+ | Prop | Type | Description | Default | Since | Platform |
1354
+ | ---------- | ------------------- | ------------------------------------------------------------------ | ----------------------- | ----- | ------------ |
1355
+ | **`date`** | <code>number</code> | The date to open the calendar at, in milliseconds since the epoch. | <code>Date.now()</code> | 7.1.0 | Android, iOS |
1356
+
1357
+
1358
+ #### CreateCalendarResult
1359
+
1360
+ | Prop | Type | Description | Since | Platform |
1361
+ | -------- | ------------------- | ----------------------------------------- | ----- | ------------ |
1362
+ | **`id`** | <code>string</code> | Identifier of the newly created calendar. | 8.4.0 | Android, iOS |
1255
1363
 
1256
1364
 
1257
1365
  #### CreateCalendarOptions
1258
1366
 
1259
- | Prop | Type | Description | Since | Platform |
1260
- | ------------------ | ------------------- | ---------------------------------------------------------- | ----- | ------------ |
1261
- | **`title`** | <code>string</code> | | 5.2.0 | Android, iOS |
1262
- | **`color`** | <code>string</code> | The color of the calendar. Should be provided on Android. | 5.2.0 | Android, iOS |
1263
- | **`sourceId`** | <code>string</code> | | 5.2.0 | iOS |
1264
- | **`accountName`** | <code>string</code> | Only needed on Android. Typically set to an email address. | 7.1.0 | Android |
1265
- | **`ownerAccount`** | <code>string</code> | Only needed on Android. Typically set to an email address. | 7.1.0 | Android |
1367
+ | Prop | Type | Description | Default | Since | Platform |
1368
+ | ------------------ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ----- | ------------ |
1369
+ | **`title`** | <code>string</code> | | | 5.2.0 | Android, iOS |
1370
+ | **`color`** | <code>string</code> | The color of the calendar as `#RRGGBB` or `#RRGGBBAA`. When omitted, Android and iOS use `#007AFF` (light-mode iOS system blue). | <code>#007AFF</code> | 5.2.0 | Android, iOS |
1371
+ | **`sourceId`** | <code>string</code> | The EventKit source (account) where the calendar should be created. If provided, it must match an existing source from `fetchAllCalendarSources()`. If omitted, iCloud is used when available, otherwise the local source. | | 5.2.0 | iOS |
1372
+ | **`accountName`** | <code>string</code> | The account under which the calendar is registered. Required on Android. Typically an email address. | | 7.1.0 | Android |
1373
+ | **`ownerAccount`** | <code>string</code> | The owner of the calendar. Required on Android. Typically an email address. | | 7.1.0 | Android |
1266
1374
 
1267
1375
 
1268
1376
  #### DeleteCalendarOptions
1269
1377
 
1270
- | Prop | Type | Since |
1271
- | -------- | ------------------- | ----- |
1272
- | **`id`** | <code>string</code> | 7.1.0 |
1378
+ | Prop | Type | Since | Platform |
1379
+ | -------- | ------------------- | ----- | ------------ |
1380
+ | **`id`** | <code>string</code> | 7.1.0 | Android, iOS |
1273
1381
 
1274
1382
 
1275
1383
  #### ModifyCalendarOptions
1276
1384
 
1277
- | Prop | Type | Since | Platform |
1278
- | ----------- | ------------------- | ----- | ------------ |
1279
- | **`id`** | <code>string</code> | 7.2.0 | Android, iOS |
1280
- | **`title`** | <code>string</code> | 7.2.0 | Android, iOS |
1281
- | **`color`** | <code>string</code> | 7.2.0 | Android, iOS |
1385
+ | Prop | Type | Description | Since | Platform |
1386
+ | ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----- | ------------ |
1387
+ | **`id`** | <code>string</code> | | 7.2.0 | Android, iOS |
1388
+ | **`title`** | <code>string</code> | Display title of the calendar. On Android this updates both `CALENDAR_DISPLAY_NAME` (`title`) and `Calendars.NAME` (`internalTitle`). | 7.2.0 | Android, iOS |
1389
+ | **`color`** | <code>string</code> | The color of the calendar as `#RRGGBB` or `#RRGGBBAA`. | 7.2.0 | Android, iOS |
1282
1390
 
1283
1391
 
1284
1392
  #### CreateRemindersListResult
@@ -1480,12 +1588,12 @@ Construct a type with a set of properties K of type T
1480
1588
 
1481
1589
  #### CalendarPermissionScope
1482
1590
 
1483
- | Members | Value | Description | Since | Platform |
1484
- | --------------------- | ----------------------------- | ------------------------------------------------------------ | ----- | ------------ |
1485
- | **`READ_CALENDAR`** | <code>'readCalendar'</code> | Permission required for reading calendar events. | 7.1.0 | Android, iOS |
1486
- | **`READ_REMINDERS`** | <code>'readReminders'</code> | Permission required for reading reminders. | 7.1.0 | iOS |
1487
- | **`WRITE_CALENDAR`** | <code>'writeCalendar'</code> | Permission required for adding or modifying calendar events. | 7.1.0 | Android, iOS |
1488
- | **`WRITE_REMINDERS`** | <code>'writeReminders'</code> | Permission required for adding or modifying reminders. | 7.1.0 | iOS |
1591
+ | Members | Value | Description | Since | Platform |
1592
+ | --------------------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | ------------ |
1593
+ | **`READ_CALENDAR`** | <code>'readCalendar'</code> | Permission required for reading calendar events. | 7.1.0 | Android, iOS |
1594
+ | **`READ_REMINDERS`** | <code>'readReminders'</code> | Permission required for reading reminders. On Android, reminders are not supported. `checkPermission` and `checkAllPermissions` return `"prompt"` for this scope. `requestPermission` rejects with `Invalid scope.`. | 7.1.0 | iOS |
1595
+ | **`WRITE_CALENDAR`** | <code>'writeCalendar'</code> | Permission required for adding or modifying calendar events. | 7.1.0 | Android, iOS |
1596
+ | **`WRITE_REMINDERS`** | <code>'writeReminders'</code> | Permission required for adding or modifying reminders. On Android, reminders are not supported. `checkPermission` and `checkAllPermissions` return `"prompt"` for this scope. `requestPermission` rejects with `Invalid scope.`. | 7.1.0 | iOS |
1489
1597
 
1490
1598
 
1491
1599
  #### EventAvailability
@@ -19,6 +19,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteCalendarInput
19
19
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
20
20
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
21
21
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
22
+ import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
22
23
  import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
23
24
  import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
24
25
  import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
@@ -30,6 +31,7 @@ import dev.barooni.capacitor.calendar.models.results.CreateEventWithPromptResult
30
31
  import dev.barooni.capacitor.calendar.models.results.ModifyEventWithPromptResult
31
32
  import dev.barooni.capacitor.calendar.models.results.RequestAllPermissionsResult
32
33
  import dev.barooni.capacitor.calendar.models.results.RequestPermissionResult
34
+ import dev.barooni.capacitor.calendar.models.templates.JSResult
33
35
 
34
36
  @CapacitorPlugin(
35
37
  name = "CapacitorCalendar",
@@ -284,13 +286,18 @@ class CapacitorCalendarPlugin : Plugin() {
284
286
  call.unimplemented(PluginError.Unimplemented(::fetchAllCalendarSources.name).message)
285
287
  }
286
288
 
287
- @PluginMethod
289
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
288
290
  fun listCalendars(call: PluginCall) {
289
291
  try {
290
- val result = implementation.listCalendars()
291
- call.resolve(result.toJSON())
292
+ implementation.listCalendars { result, error ->
293
+ if (error != null) {
294
+ rejectCall(call, error)
295
+ return@listCalendars
296
+ }
297
+ resolveCall(call, result)
298
+ }
292
299
  } catch (error: Exception) {
293
- call.reject(error.message)
300
+ rejectCall(call, error)
294
301
  }
295
302
  }
296
303
 
@@ -307,10 +314,16 @@ class CapacitorCalendarPlugin : Plugin() {
307
314
  @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
308
315
  fun getDefaultCalendar(call: PluginCall) {
309
316
  try {
310
- val result = implementation.getDefaultCalendar()
311
- call.resolve(result.toJSON())
317
+ val input = GetDefaultCalendarInput(call)
318
+ implementation.getDefaultCalendar(input) { result, error ->
319
+ if (error != null) {
320
+ rejectCall(call, error)
321
+ return@getDefaultCalendar
322
+ }
323
+ resolveCall(call, result)
324
+ }
312
325
  } catch (error: Exception) {
313
- call.reject(error.message)
326
+ rejectCall(call, error)
314
327
  }
315
328
  }
316
329
 
@@ -455,4 +468,26 @@ class CapacitorCalendarPlugin : Plugin() {
455
468
  fun updateRemindersList(call: PluginCall) {
456
469
  call.unimplemented(PluginError.Unimplemented(::updateRemindersList.name).message)
457
470
  }
471
+
472
+ private fun rejectCall(
473
+ call: PluginCall,
474
+ error: Exception?,
475
+ ) {
476
+ call.reject(error?.message ?: PluginError.CustomError("An unknown error has occurred.").message)
477
+ }
478
+
479
+ private fun resolveCall(call: PluginCall) {
480
+ resolveCall(call, null)
481
+ }
482
+
483
+ private fun resolveCall(
484
+ call: PluginCall,
485
+ result: JSResult?,
486
+ ) {
487
+ if (result != null) {
488
+ call.resolve(result.toJSON())
489
+ } else {
490
+ call.resolve()
491
+ }
492
+ }
458
493
  }
@@ -3,51 +3,61 @@ package dev.barooni.capacitor.calendar
3
3
  sealed class PluginError(
4
4
  localizedDescription: String,
5
5
  ) : Exception(localizedDescription) {
6
- data object MissingScope : PluginError("Scope Must be provided.")
6
+ data object AccountNameMissing : PluginError("Account name must be provided.")
7
7
 
8
- data object InvalidScope : PluginError("Invalid scope.")
8
+ data object AttendeeEmailMissing : PluginError("Attendee email must be provided.")
9
9
 
10
- data object UnhandledPermissionState : PluginError("Unhandled permission state.")
10
+ data object CalendarIdMissing : PluginError("Calendar ID must be provided.")
11
11
 
12
- data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.")
12
+ data object CalendarNotFound : PluginError("Calendar not found.")
13
13
 
14
- data object MissingId : PluginError("Event ID must be provided.")
14
+ data object ColorMissing : PluginError("Color must be provided.")
15
+
16
+ data class CustomError(
17
+ val details: String,
18
+ ) : PluginError(details)
19
+
20
+ data object FailedToDelete : PluginError("Failed to delete.")
21
+
22
+ data object FailedToModify : PluginError("Failed to modify.")
23
+
24
+ data object FailedToRetrieveCalendarId : PluginError("Failed to retrieve calendar ID.")
25
+
26
+ data object FailedToRetrieveEventId : PluginError("Failed to retrieve event ID.")
27
+
28
+ data object FromDateMissing : PluginError("From date must be provided.")
15
29
 
16
30
  data object InstanceDateMissing : PluginError(
17
31
  "Instance date must be provided for this span on recurring events.",
18
32
  )
19
33
 
20
- data object TitleMissing : PluginError("Title must be provided.")
34
+ data object InvalidCalendarId : PluginError("Invalid calendar ID.")
21
35
 
22
- data object FailedToRetrieveEventId : PluginError("Failed to retrieve event ID.")
36
+ data object InvalidColor : PluginError("Invalid color format.")
23
37
 
24
- data object FailedToRetrieveCalendarId : PluginError("Failed to retrieve calendar ID.")
38
+ data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.")
25
39
 
26
- data object AttendeeEmailMissing : PluginError("Attendee email must be provided.")
40
+ data object InvalidScope : PluginError("Invalid scope.")
27
41
 
28
- data object NoCalendarsAvailable : PluginError("No calendars available.")
42
+ data object MessageMissing : PluginError("Message must be provided.")
29
43
 
30
- data object ColorMissing : PluginError("Color must be provided.")
44
+ data object MissingId : PluginError("Event ID must be provided.")
31
45
 
32
- data object AccountNameMissing : PluginError("Account name must be provided.")
46
+ data object MissingScope : PluginError("Scope must be provided.")
33
47
 
34
- data object OwnerAccountMissing : PluginError("Owner account must be provided.")
48
+ data object NoCalendarsAvailable : PluginError("No calendars available.")
35
49
 
36
- data object FailedToDelete : PluginError("Failed to delete.")
50
+ data object NoFieldsToModify : PluginError("At least one of title or color must be provided.")
37
51
 
38
- data object MessageMissing : PluginError("Message must be provided.")
52
+ data object OwnerAccountMissing : PluginError("Owner account must be provided.")
39
53
 
40
- data object FromDateMissing : PluginError("From date must be provided.")
54
+ data object TitleMissing : PluginError("Title must be provided.")
41
55
 
42
56
  data object ToDateMissing : PluginError("To date must be provided.")
43
57
 
44
- data object FailedToModify : PluginError("Failed to modify.")
58
+ data object UnhandledPermissionState : PluginError("Unhandled permission state.")
45
59
 
46
60
  data class Unimplemented(
47
61
  val methodName: String,
48
62
  ) : PluginError("$methodName is not implemented on Android.")
49
-
50
- data class CustomError(
51
- val details: String,
52
- ) : PluginError(details)
53
63
  }