@ebarooni/capacitor-calendar 8.7.0 → 8.7.1
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.
- package/README.md +81 -42
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +2 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +54 -5
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +80 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,34 +21,56 @@
|
|
|
21
21
|
|
|
22
22
|

|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
`@ebarooni/capacitor-calendar` connects your Capacitor app to the native calendar. On iOS and Android, create, edit, and list events, and manage calendars and permissions. iOS also supports reminders. On the web, the plugin builds a downloadable `.ics` file; it does not write to a device calendar.
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Table of Contents
|
|
27
|
+
|
|
28
|
+
- [Features and Platforms](#features-and-platforms)
|
|
29
|
+
- [Demo](#demo)
|
|
30
|
+
- [Why this plugin?](#why-this-plugin)
|
|
31
|
+
- [MCP Server](#mcp-server)
|
|
32
|
+
- [Installation](#installation)
|
|
33
|
+
- [Setup](#setup)
|
|
34
|
+
- [Quick Start](#quick-start)
|
|
35
|
+
- [Usage Examples](#usage-examples)
|
|
36
|
+
- [Documentation](#documentation)
|
|
37
|
+
- [Changelog](#changelog)
|
|
38
|
+
- [Breaking Changes](#breaking-changes)
|
|
39
|
+
- [API](#api)
|
|
40
|
+
- [Contributing](#contributing)
|
|
41
|
+
- [License](#license)
|
|
42
|
+
|
|
43
|
+
## Features and Platforms
|
|
44
|
+
|
|
45
|
+
| Capability | iOS | Android | Web |
|
|
46
|
+
| :------------------------------------------------ | :-: | :-----: | :-----------: |
|
|
47
|
+
| Create, update, and delete events | ✅ | ✅ | Create only\* |
|
|
48
|
+
| Native prompts to create, edit, and delete events | ✅ | ✅ | – |
|
|
49
|
+
| List events in a date range | ✅ | ✅ | – |
|
|
50
|
+
| Request calendar permissions | ✅ | ✅ | – |
|
|
51
|
+
| List, create, modify, and delete calendars | ✅ | ✅ | – |
|
|
52
|
+
| Open the native Calendar app | ✅ | ✅ | – |
|
|
53
|
+
| Calendar sources and a calendar picker prompt | ✅ | – | – |
|
|
54
|
+
| Reminders and reminder lists | ✅ | – | – |
|
|
27
55
|
|
|
28
|
-
|
|
29
|
-
- ✅ **Native Prompts** – Built-in system dialogs for creating, editing, and deleting events
|
|
30
|
-
- ✅ **Permissions** – Granular control (full access, write-only, read-only)
|
|
31
|
-
- ✅ **Calendars** – List calendars, get default, create, modify, and delete custom calendars
|
|
32
|
-
- ✅ **Open Calendar App** – Launch the native Calendar app directly
|
|
33
|
-
- 📅 **Reminders** – Full create, read, update, delete support _(iOS only)_
|
|
34
|
-
- 🔍 **Advanced iOS Features** – Calendar sources, calendar selection prompts, default reminders list
|
|
56
|
+
\* On the web, `createEvent` returns a downloadable `.ics` file. It does not write to a device calendar. See [Create and download an event on the web](#create-and-download-an-event-on-the-web).
|
|
35
57
|
|
|
36
|
-
##
|
|
58
|
+
## Demo
|
|
37
59
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-
|
|
60
|
+
| iOS | Android |
|
|
61
|
+
| :-----------------------------: | :---------------------------------: |
|
|
62
|
+
|  |  |
|
|
41
63
|
|
|
42
64
|
## Why this plugin?
|
|
43
65
|
|
|
44
|
-
- **
|
|
45
|
-
- **Actively maintained
|
|
46
|
-
- **Fast support.** Questions
|
|
47
|
-
- **
|
|
66
|
+
- **Established.** Available since Capacitor 5, with years of real-world use behind it.
|
|
67
|
+
- **Actively maintained.** The original author still owns the codebase and ships fixes and features.
|
|
68
|
+
- **Fast support.** Questions and bug reports get quick answers.
|
|
69
|
+
- **Lower vendor risk.** Relying on one plugin author for everything is risky. Independent, focused maintainers keep your stack resilient.
|
|
48
70
|
|
|
49
71
|
## MCP Server
|
|
50
72
|
|
|
51
|
-
`@ebarooni/capacitor-calendar` ships an official [MCP](https://modelcontextprotocol.io) server
|
|
73
|
+
`@ebarooni/capacitor-calendar` ships an official [MCP](https://modelcontextprotocol.io) server. It gives AI coding assistants accurate, grounded knowledge of the plugin.
|
|
52
74
|
|
|
53
75
|
```bash
|
|
54
76
|
docker run --rm -d --name capacitor-calendar-mcp -p 8080:8080 ghcr.io/ebarooni/capacitor-calendar-mcp:1.1.0
|
|
@@ -56,20 +78,6 @@ docker run --rm -d --name capacitor-calendar-mcp -p 8080:8080 ghcr.io/ebarooni/c
|
|
|
56
78
|
|
|
57
79
|
See [`mcp/README.md`](mcp/README.md) for client configuration and full details.
|
|
58
80
|
|
|
59
|
-
## Table of Contents
|
|
60
|
-
|
|
61
|
-
- [Installation](#installation)
|
|
62
|
-
- [Demo](#demo)
|
|
63
|
-
- [Setup](#setup)
|
|
64
|
-
- [Quick Start](#quick-start)
|
|
65
|
-
- [Usage Examples](#usage-examples)
|
|
66
|
-
- [Documentation](#documentation)
|
|
67
|
-
- [Changelog](#changelog)
|
|
68
|
-
- [Breaking Changes](#breaking-changes)
|
|
69
|
-
- [API](#api)
|
|
70
|
-
- [Contributing](#contributing)
|
|
71
|
-
- [License](#license)
|
|
72
|
-
|
|
73
81
|
## Installation
|
|
74
82
|
|
|
75
83
|
```bash
|
|
@@ -77,15 +85,9 @@ npm install @ebarooni/capacitor-calendar
|
|
|
77
85
|
npx cap sync
|
|
78
86
|
```
|
|
79
87
|
|
|
80
|
-
## Demo
|
|
81
|
-
|
|
82
|
-
| iOS 26 | Android 17 |
|
|
83
|
-
| :-----------------------------: | :---------------------------------: |
|
|
84
|
-
|  |  |
|
|
85
|
-
|
|
86
88
|
## Setup
|
|
87
89
|
|
|
88
|
-
This plugin works with native calendar APIs, so you
|
|
90
|
+
This plugin works with native calendar APIs, so you need to configure permissions on each platform before you request access at runtime. After setup, see [Quick Start](#quick-start) to request permissions in code.
|
|
89
91
|
|
|
90
92
|
### Android
|
|
91
93
|
|
|
@@ -96,7 +98,7 @@ Add these permissions to `android/app/src/main/AndroidManifest.xml`:
|
|
|
96
98
|
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
|
97
99
|
```
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
Request the matching runtime permissions before you read from or write to the calendar.
|
|
100
102
|
|
|
101
103
|
### iOS
|
|
102
104
|
|
|
@@ -120,7 +122,7 @@ Add the appropriate usage description keys to `ios/App/App/Info.plist`. Starting
|
|
|
120
122
|
```
|
|
121
123
|
|
|
122
124
|
> [!IMPORTANT]
|
|
123
|
-
> Only include the keys your app actually needs. If you
|
|
125
|
+
> Only include the keys your app actually needs. If you only create events, you can omit the full access and reminders entries.
|
|
124
126
|
|
|
125
127
|
### Official References
|
|
126
128
|
|
|
@@ -129,7 +131,7 @@ Add the appropriate usage description keys to `ios/App/App/Info.plist`. Starting
|
|
|
129
131
|
|
|
130
132
|
## Quick Start
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
The sample below is for Android and iOS. For Web, see [Create and download an event on the web](#create-and-download-an-event-on-the-web).
|
|
133
135
|
|
|
134
136
|
```typescript
|
|
135
137
|
import { CapacitorCalendar } from '@ebarooni/capacitor-calendar';
|
|
@@ -160,6 +162,28 @@ console.log('Event created with ID:', id);
|
|
|
160
162
|
|
|
161
163
|
## Usage Examples
|
|
162
164
|
|
|
165
|
+
### Create and download an event on the web
|
|
166
|
+
|
|
167
|
+
On Web, `createEvent` builds an `.ics` file. It does not write to a calendar store. Use `downloadIcsFile` to start a browser download:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { CapacitorCalendar, downloadIcsFile } from '@ebarooni/capacitor-calendar';
|
|
171
|
+
|
|
172
|
+
const startDate = Date.now() + 60 * 60 * 1000;
|
|
173
|
+
const endDate = startDate + 60 * 60 * 1000;
|
|
174
|
+
|
|
175
|
+
const { ics } = await CapacitorCalendar.createEvent({
|
|
176
|
+
title: 'Team standup',
|
|
177
|
+
startDate,
|
|
178
|
+
endDate,
|
|
179
|
+
icsFileName: 'team-standup.ics',
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (ics) {
|
|
183
|
+
await downloadIcsFile(ics);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
163
187
|
### Open the native event editor
|
|
164
188
|
|
|
165
189
|
Use the system calendar UI to let users create or edit events:
|
|
@@ -176,6 +200,21 @@ await CapacitorCalendar.createEventWithPrompt({
|
|
|
176
200
|
> [!NOTE]
|
|
177
201
|
> On Android, this method always returns null. If you need the event ID, call `listEventsInRange(...)` afterward.
|
|
178
202
|
|
|
203
|
+
### Modify or delete an event
|
|
204
|
+
|
|
205
|
+
The sample below is for Android and iOS. Use an `id` from `createEvent` or `listEventsInRange`:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
await CapacitorCalendar.modifyEvent({
|
|
209
|
+
id: eventId,
|
|
210
|
+
title: 'Updated title',
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
await CapacitorCalendar.deleteEvent({
|
|
214
|
+
id: eventId,
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
179
218
|
### List events in a range
|
|
180
219
|
|
|
181
220
|
`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.
|
|
@@ -17,6 +17,8 @@ sealed class PluginError(
|
|
|
17
17
|
val details: String,
|
|
18
18
|
) : PluginError(details)
|
|
19
19
|
|
|
20
|
+
data object EventNotFound : PluginError("Event not found.")
|
|
21
|
+
|
|
20
22
|
data object FailedToDelete : PluginError("Failed to delete.")
|
|
21
23
|
|
|
22
24
|
data object FailedToModify : PluginError("Failed to modify.")
|
package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt
CHANGED
|
@@ -87,16 +87,24 @@ class CapacitorCalendar(
|
|
|
87
87
|
fun createEvent(input: CreateEventInput): CreateEventResult {
|
|
88
88
|
val cr = plugin.context.contentResolver
|
|
89
89
|
val calendarId: Long = input.calendarId ?: ImplementationHelper.getDefaultCalendarId(cr)
|
|
90
|
+
val isAllDay = input.isAllDay == 1
|
|
91
|
+
val (startDate, endDate) =
|
|
92
|
+
if (isAllDay) {
|
|
93
|
+
ImplementationHelper.normalizeAllDayTimes(input.startDate, input.endDate)
|
|
94
|
+
} else {
|
|
95
|
+
Pair(input.startDate, input.endDate)
|
|
96
|
+
}
|
|
97
|
+
val timezoneId = if (isAllDay) "UTC" else input.timezoneId
|
|
90
98
|
|
|
91
99
|
val values =
|
|
92
100
|
ContentValues().apply {
|
|
93
101
|
put(CalendarContract.Events.TITLE, input.title)
|
|
94
102
|
put(CalendarContract.Events.CALENDAR_ID, calendarId)
|
|
95
|
-
put(CalendarContract.Events.EVENT_TIMEZONE,
|
|
103
|
+
put(CalendarContract.Events.EVENT_TIMEZONE, timezoneId)
|
|
96
104
|
input.isAllDay?.let { put(CalendarContract.Events.ALL_DAY, it) }
|
|
97
105
|
input.location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
startDate?.let { put(CalendarContract.Events.DTSTART, it) }
|
|
107
|
+
endDate?.let { put(CalendarContract.Events.DTEND, it) }
|
|
100
108
|
input.description?.let { put(CalendarContract.Events.DESCRIPTION, it) }
|
|
101
109
|
input.availability?.let { put(CalendarContract.Events.AVAILABILITY, it) }
|
|
102
110
|
input.organizer?.let { put(CalendarContract.Events.ORGANIZER, it) }
|
|
@@ -113,14 +121,55 @@ class CapacitorCalendar(
|
|
|
113
121
|
|
|
114
122
|
fun modifyEvent(input: ModifyEvent) {
|
|
115
123
|
val cr = plugin.context.contentResolver
|
|
124
|
+
val updatingDates = input.startDate != null || input.endDate != null
|
|
125
|
+
val settingAllDay = input.isAllDay == 1
|
|
126
|
+
// Normalize when setting all-day, or when editing dates on an existing all-day event
|
|
127
|
+
// without re-sending isAllDay. Reading ALL_DAY fails closed (EventNotFound) so a missed
|
|
128
|
+
// row cannot silently skip normalization and reintroduce the wrong-day bug.
|
|
129
|
+
val treatAsAllDay =
|
|
130
|
+
when {
|
|
131
|
+
input.isAllDay == 1 -> true
|
|
132
|
+
input.isAllDay == 0 -> false
|
|
133
|
+
updatingDates -> ImplementationHelper.isEventAllDay(cr, input.id)
|
|
134
|
+
else -> false
|
|
135
|
+
}
|
|
136
|
+
// Explicit isAllDay + startDate shares create's contract (inclusive local days; omitted
|
|
137
|
+
// endDate → one-day exclusive DTEND). Date-only patches on an existing all-day event
|
|
138
|
+
// normalize only the fields the caller sent, so a start-only update cannot truncate a
|
|
139
|
+
// multi-day span.
|
|
140
|
+
val (startDate, endDate) =
|
|
141
|
+
when {
|
|
142
|
+
!treatAsAllDay -> {
|
|
143
|
+
Pair(input.startDate, input.endDate)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
settingAllDay && input.startDate != null -> {
|
|
147
|
+
ImplementationHelper.normalizeAllDayTimes(input.startDate, input.endDate)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
else -> {
|
|
151
|
+
Pair(
|
|
152
|
+
input.startDate?.let { ImplementationHelper.utcMidnightForLocalDay(it) },
|
|
153
|
+
input.endDate?.let { ImplementationHelper.exclusiveUtcEndForInclusiveLocalDay(it) },
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
val writeDefaultAllDayEnd = settingAllDay && input.startDate != null && input.endDate == null
|
|
116
158
|
val values =
|
|
117
159
|
ContentValues().apply {
|
|
118
160
|
input.title?.let { put(CalendarContract.Events.TITLE, it) }
|
|
119
161
|
input.calendarId?.let { put(CalendarContract.Events.CALENDAR_ID, it) }
|
|
120
162
|
input.location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
|
|
121
|
-
input.startDate
|
|
122
|
-
|
|
163
|
+
if (input.startDate != null) {
|
|
164
|
+
startDate?.let { put(CalendarContract.Events.DTSTART, it) }
|
|
165
|
+
}
|
|
166
|
+
if (input.endDate != null || writeDefaultAllDayEnd) {
|
|
167
|
+
endDate?.let { put(CalendarContract.Events.DTEND, it) }
|
|
168
|
+
}
|
|
123
169
|
input.isAllDay?.let { put(CalendarContract.Events.ALL_DAY, it) }
|
|
170
|
+
if (treatAsAllDay) {
|
|
171
|
+
put(CalendarContract.Events.EVENT_TIMEZONE, "UTC")
|
|
172
|
+
}
|
|
124
173
|
input.description?.let { put(CalendarContract.Events.DESCRIPTION, it) }
|
|
125
174
|
input.availability?.let { put(CalendarContract.Events.AVAILABILITY, it) }
|
|
126
175
|
input.organizer?.let { put(CalendarContract.Events.ORGANIZER, it) }
|
|
@@ -26,6 +26,86 @@ class ImplementationHelper {
|
|
|
26
26
|
timeInMillis = timestamp ?: System.currentTimeMillis()
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Maps a timestamp to UTC midnight of its local calendar day.
|
|
31
|
+
* Required for [CalendarContract.Events] all-day rows (`EVENT_TIMEZONE` = UTC).
|
|
32
|
+
*/
|
|
33
|
+
fun utcMidnightForLocalDay(timestamp: Long): Long {
|
|
34
|
+
val local = Calendar.getInstance().apply { timeInMillis = timestamp }
|
|
35
|
+
return Calendar
|
|
36
|
+
.getInstance(TimeZone.getTimeZone("UTC"))
|
|
37
|
+
.apply {
|
|
38
|
+
clear()
|
|
39
|
+
set(
|
|
40
|
+
local.get(Calendar.YEAR),
|
|
41
|
+
local.get(Calendar.MONTH),
|
|
42
|
+
local.get(Calendar.DAY_OF_MONTH),
|
|
43
|
+
)
|
|
44
|
+
}.timeInMillis
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Inclusive local-day end → exclusive UTC midnight `DTEND` for all-day rows.
|
|
49
|
+
*/
|
|
50
|
+
fun exclusiveUtcEndForInclusiveLocalDay(timestamp: Long): Long =
|
|
51
|
+
Calendar
|
|
52
|
+
.getInstance(TimeZone.getTimeZone("UTC"))
|
|
53
|
+
.apply {
|
|
54
|
+
timeInMillis = utcMidnightForLocalDay(timestamp)
|
|
55
|
+
add(Calendar.DAY_OF_MONTH, 1)
|
|
56
|
+
}.timeInMillis
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Plugin all-day dates use local calendar days with an inclusive end (same as iOS).
|
|
60
|
+
* [CalendarContract] needs UTC midnight boundaries and an exclusive `DTEND`.
|
|
61
|
+
* When [endDate] is omitted, uses a one-day span from [startDate].
|
|
62
|
+
*/
|
|
63
|
+
fun normalizeAllDayTimes(
|
|
64
|
+
startDate: Long?,
|
|
65
|
+
endDate: Long?,
|
|
66
|
+
): Pair<Long?, Long?> {
|
|
67
|
+
val start = startDate?.let { utcMidnightForLocalDay(it) }
|
|
68
|
+
val exclusiveEnd =
|
|
69
|
+
when {
|
|
70
|
+
endDate != null -> {
|
|
71
|
+
exclusiveUtcEndForInclusiveLocalDay(endDate)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
start != null -> {
|
|
75
|
+
Calendar
|
|
76
|
+
.getInstance(TimeZone.getTimeZone("UTC"))
|
|
77
|
+
.apply {
|
|
78
|
+
timeInMillis = start
|
|
79
|
+
add(Calendar.DAY_OF_MONTH, 1)
|
|
80
|
+
}.timeInMillis
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
else -> {
|
|
84
|
+
null
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return Pair(start, exclusiveEnd)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Reads [CalendarContract.Events.ALL_DAY] for an existing event.
|
|
92
|
+
* Throws [PluginError.EventNotFound] when the row is missing or unreadable,
|
|
93
|
+
* so callers that need the flag cannot silently skip all-day normalization.
|
|
94
|
+
*/
|
|
95
|
+
fun isEventAllDay(
|
|
96
|
+
cr: ContentResolver,
|
|
97
|
+
eventId: Long,
|
|
98
|
+
): Boolean {
|
|
99
|
+
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId)
|
|
100
|
+
val projection = arrayOf(CalendarContract.Events.ALL_DAY)
|
|
101
|
+
cr.query(uri, projection, null, null, null)?.use { cursor ->
|
|
102
|
+
if (cursor.moveToFirst()) {
|
|
103
|
+
return cursor.getInt(0) == 1
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw PluginError.EventNotFound
|
|
107
|
+
}
|
|
108
|
+
|
|
29
109
|
fun jsArrayToComaSeparatedString(array: JSArray?): String? {
|
|
30
110
|
val list = array?.toList<Any>() ?: return null
|
|
31
111
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebarooni/capacitor-calendar",
|
|
3
|
-
"version": "8.7.
|
|
4
|
-
"description": "A Capacitor plugin for
|
|
3
|
+
"version": "8.7.1",
|
|
4
|
+
"description": "A Capacitor plugin for native calendar events on iOS and Android (with reminders on iOS), and .ics event creation on the web.",
|
|
5
5
|
"author": "Ehsan Barooni",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://ebarooni.github.io/capacitor-calendar",
|