@ebarooni/capacitor-calendar 8.10.0 → 8.12.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.
- package/README.md +372 -156
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +55 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +4 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CalendarChangeObserver.kt +181 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +184 -8
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +6 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventRecurrenceRule.kt +4 -3
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetEventByIdInput.kt +13 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ListEventsInRangeInput.kt +5 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/StartListeningInput.kt +20 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetEventByIdResult.kt +15 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListEventsInRangeResult.kt +47 -43
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +123 -69
- package/dist/docs.json +1594 -989
- package/dist/esm/definitions.d.ts +2 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +15 -2
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar-changed-event.d.ts +52 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js.map +1 -0
- package/dist/esm/schemas/interfaces/calendar-links.d.ts +32 -0
- package/dist/esm/schemas/interfaces/calendar-links.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-links.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +18 -0
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-ics-file-options.d.ts +20 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/delete-event-options.d.ts +2 -1
- package/dist/esm/schemas/interfaces/delete-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.d.ts +2 -1
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/get-event-by-id-options.d.ts +11 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-options.js +2 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.js +2 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +8 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-event-options.d.ts +11 -0
- package/dist/esm/schemas/interfaces/modify-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +10 -0
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/share-ics-file-options.d.ts +17 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/start-listening-options.d.ts +46 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js +2 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js.map +1 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.d.ts +7 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js.map +1 -0
- package/dist/esm/schemas/types/calendar-link-provider.d.ts +6 -0
- package/dist/esm/schemas/types/calendar-link-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-link-provider.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-listening.d.ts +49 -0
- package/dist/esm/sub-definitions/calendar-listening.js +2 -0
- package/dist/esm/sub-definitions/calendar-listening.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-operations.d.ts +2 -1
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/sub-definitions/event-operations.d.ts +33 -0
- package/dist/esm/sub-definitions/event-operations.js.map +1 -1
- package/dist/esm/web/calendar-links.d.ts +26 -0
- package/dist/esm/web/calendar-links.js +114 -0
- package/dist/esm/web/calendar-links.js.map +1 -0
- package/dist/esm/web/create-ics-file.d.ts +21 -0
- package/dist/esm/web/create-ics-file.js +30 -0
- package/dist/esm/web/create-ics-file.js.map +1 -0
- package/dist/esm/web/ics.d.ts +11 -0
- package/dist/esm/web/ics.js +48 -32
- package/dist/esm/web/ics.js.map +1 -1
- package/dist/esm/web/share-ics-file.d.ts +21 -0
- package/dist/esm/web/share-ics-file.js +46 -0
- package/dist/esm/web/share-ics-file.js.map +1 -0
- package/dist/esm/web.d.ts +7 -1
- package/dist/esm/web.js +21 -4
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +295 -72
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +295 -72
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +36 -1
- package/ios/Plugin/Implementation/CalendarChangeObserver.swift +259 -0
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +56 -8
- package/ios/Plugin/Models/Inputs/CreateEventInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/CreateEventWithPromptInput.swift +61 -70
- package/ios/Plugin/Models/Inputs/DeleteEventInput.swift +7 -0
- package/ios/Plugin/Models/Inputs/DeleteEventWithPromptInput.swift +7 -0
- package/ios/Plugin/Models/Inputs/DeleteReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteReminderWithPromptInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/GetEventByIdInput.swift +16 -0
- package/ios/Plugin/Models/Inputs/GetReminderByIdInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/ListEventsInRangeInput.swift +20 -0
- package/ios/Plugin/Models/Inputs/ModifyEventInput.swift +13 -23
- package/ios/Plugin/Models/Inputs/ModifyEventWithPromptInput.swift +10 -5
- package/ios/Plugin/Models/Inputs/ModifyReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/StartListeningInput.swift +26 -0
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +1 -1
- package/ios/Plugin/Models/Results/GetEventByIdResult.swift +27 -0
- package/ios/Plugin/Models/Structs/RecurrenceInput.swift +14 -0
- package/ios/Plugin/PluginConfig.swift +3 -0
- package/ios/Plugin/PluginError.swift +32 -3
- package/ios/Plugin/Utils/ImplementationHelper.swift +49 -32
- package/ios/Plugin/Utils/PluginCallRejecter.swift +13 -0
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import Capacitor
|
|
2
|
+
import EventKit
|
|
2
3
|
|
|
3
4
|
struct ListEventsInRangeInput {
|
|
4
5
|
private var from: Double
|
|
5
6
|
private var to: Double
|
|
7
|
+
private var calendarIds: [String]?
|
|
6
8
|
|
|
7
9
|
init(call: CAPPluginCall) throws {
|
|
8
10
|
guard let from = call.getDouble("from") else {
|
|
@@ -13,6 +15,12 @@ struct ListEventsInRangeInput {
|
|
|
13
15
|
throw PluginError.toDateMissing
|
|
14
16
|
}
|
|
15
17
|
self.to = to
|
|
18
|
+
if let rawIds = call.getArray("calendarIds") {
|
|
19
|
+
guard let ids = rawIds as? [String] else {
|
|
20
|
+
throw PluginError.calendarNotFound
|
|
21
|
+
}
|
|
22
|
+
self.calendarIds = ids
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
func getFrom() -> Date {
|
|
@@ -22,4 +30,16 @@ struct ListEventsInRangeInput {
|
|
|
22
30
|
func getTo() -> Date {
|
|
23
31
|
return ImplementationHelper.dateFromTimestamp(to)
|
|
24
32
|
}
|
|
33
|
+
|
|
34
|
+
func getCalendars(from eventStore: EKEventStore) throws -> [EKCalendar]? {
|
|
35
|
+
guard let ids = calendarIds, !ids.isEmpty else {
|
|
36
|
+
return nil
|
|
37
|
+
}
|
|
38
|
+
return try ids.map { id in
|
|
39
|
+
guard let calendar = eventStore.calendar(withIdentifier: id) else {
|
|
40
|
+
throw PluginError.calendarNotFound
|
|
41
|
+
}
|
|
42
|
+
return calendar
|
|
43
|
+
}
|
|
44
|
+
}
|
|
25
45
|
}
|
|
@@ -8,6 +8,7 @@ struct ModifyEventInput {
|
|
|
8
8
|
private var description: String?
|
|
9
9
|
private var endDate: Double?
|
|
10
10
|
private let id: String
|
|
11
|
+
private let instanceDate: Double?
|
|
11
12
|
private var isAllDay: Bool?
|
|
12
13
|
private var location: String?
|
|
13
14
|
private let recurrence: RecurrenceInput?
|
|
@@ -36,13 +37,14 @@ struct ModifyEventInput {
|
|
|
36
37
|
throw PluginError.idMissing
|
|
37
38
|
}
|
|
38
39
|
self.id = id
|
|
40
|
+
self.instanceDate = call.getDouble("instanceDate")
|
|
39
41
|
if let isAllDay = call.getBool("isAllDay") as Bool? {
|
|
40
42
|
self.isAllDay = isAllDay
|
|
41
43
|
}
|
|
42
44
|
if let location = call.getString("location") {
|
|
43
45
|
self.location = location
|
|
44
46
|
}
|
|
45
|
-
self.recurrence = CreateEventWithPromptInput.getRecurrence(from: call)
|
|
47
|
+
self.recurrence = try CreateEventWithPromptInput.getRecurrence(from: call)
|
|
46
48
|
if let spanInt = call.getInt("span"), let span = EKSpan(rawValue: spanInt) {
|
|
47
49
|
self.span = span
|
|
48
50
|
} else {
|
|
@@ -72,10 +74,8 @@ struct ModifyEventInput {
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
func getEvent(from eventStore: EKEventStore) throws -> EKEvent {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
return event
|
|
77
|
+
let occurrenceStart = instanceDate.map { ImplementationHelper.dateFromTimestamp($0) }
|
|
78
|
+
return try ImplementationHelper.findEvent(id: id, instanceDate: occurrenceStart, eventStore: eventStore)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
func getTitle() -> String? {
|
|
@@ -90,24 +90,9 @@ struct ModifyEventInput {
|
|
|
90
90
|
return location
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let rule = EKRecurrenceRule(
|
|
99
|
-
recurrenceWith: recurrence.frequency.toEKFrequency(),
|
|
100
|
-
interval: recurrence.interval,
|
|
101
|
-
daysOfTheWeek: recurrence.byWeekDay,
|
|
102
|
-
daysOfTheMonth: recurrence.byMonthDay,
|
|
103
|
-
monthsOfTheYear: recurrence.byMonth,
|
|
104
|
-
weeksOfTheYear: recurrence.weeksOfTheYear,
|
|
105
|
-
daysOfTheYear: recurrence.daysOfTheYear,
|
|
106
|
-
setPositions: nil,
|
|
107
|
-
end: recurrence.end
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
return [rule]
|
|
93
|
+
/// Returns nil when `recurrence` is omitted, so the event keeps its existing rules.
|
|
94
|
+
func getRecurrenceRule() -> [EKRecurrenceRule]? {
|
|
95
|
+
return recurrence.map { [$0.toEKRecurrenceRule()] }
|
|
111
96
|
}
|
|
112
97
|
|
|
113
98
|
func getStartDate() -> Date? {
|
|
@@ -133,6 +118,11 @@ struct ModifyEventInput {
|
|
|
133
118
|
return availability
|
|
134
119
|
}
|
|
135
120
|
|
|
121
|
+
/// True when `instanceDate` selects one occurrence of a series.
|
|
122
|
+
func targetsOccurrence() -> Bool {
|
|
123
|
+
return instanceDate != nil
|
|
124
|
+
}
|
|
125
|
+
|
|
136
126
|
func getSpan() -> EKSpan {
|
|
137
127
|
return span
|
|
138
128
|
}
|
|
@@ -4,17 +4,19 @@ import EventKit
|
|
|
4
4
|
struct ModifyEventWithPromptInput {
|
|
5
5
|
private let input: CreateEventWithPromptInput
|
|
6
6
|
private let id: String
|
|
7
|
+
private let instanceDate: Double?
|
|
7
8
|
private var title: String?
|
|
8
9
|
private var isAllDay: Bool?
|
|
9
10
|
private var alerts: [Double]?
|
|
10
11
|
private var calendarId: String?
|
|
11
12
|
|
|
12
13
|
init(call: CAPPluginCall) throws {
|
|
13
|
-
self.input = CreateEventWithPromptInput(call: call)
|
|
14
|
+
self.input = try CreateEventWithPromptInput(call: call)
|
|
14
15
|
guard let id = call.getString("id") else {
|
|
15
16
|
throw PluginError.idMissing
|
|
16
17
|
}
|
|
17
18
|
self.id = id
|
|
19
|
+
self.instanceDate = call.getDouble("instanceDate")
|
|
18
20
|
let title = input.getTitle()
|
|
19
21
|
if !title.isEmpty {
|
|
20
22
|
self.title = title
|
|
@@ -31,10 +33,8 @@ struct ModifyEventWithPromptInput {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
func getEvent(from eventStore: EKEventStore) throws -> EKEvent {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return event
|
|
36
|
+
let occurrenceStart = instanceDate.map { ImplementationHelper.dateFromTimestamp($0) }
|
|
37
|
+
return try ImplementationHelper.findEvent(id: id, instanceDate: occurrenceStart, eventStore: eventStore)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
func getTitle() -> String? {
|
|
@@ -61,6 +61,11 @@ struct ModifyEventWithPromptInput {
|
|
|
61
61
|
return isAllDay
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/// Returns nil when `recurrence` is omitted, so the event keeps its existing rules.
|
|
65
|
+
func getRecurrenceRule() -> [EKRecurrenceRule]? {
|
|
66
|
+
return input.getRecurrenceRuleIfPresent()
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
func getAlerts() -> [EKAlarm]? {
|
|
65
70
|
if self.alerts != nil {
|
|
66
71
|
return input.getAlerts()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import EventKit
|
|
3
|
+
|
|
4
|
+
struct StartListeningInput {
|
|
5
|
+
private let range: ListEventsInRangeInput
|
|
6
|
+
private let includeEvents: Bool
|
|
7
|
+
private let includeReminders: Bool
|
|
8
|
+
|
|
9
|
+
init(call: CAPPluginCall) throws {
|
|
10
|
+
self.range = try ListEventsInRangeInput(call: call)
|
|
11
|
+
self.includeEvents = call.getBool("includeEvents") ?? true
|
|
12
|
+
self.includeReminders = call.getBool("includeReminders") ?? false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func getRange() -> ListEventsInRangeInput {
|
|
16
|
+
return range
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func getIncludeEvents() -> Bool {
|
|
20
|
+
return includeEvents
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func getIncludeReminders() -> Bool {
|
|
24
|
+
return includeReminders
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import EventKit
|
|
3
|
+
|
|
4
|
+
struct GetEventByIdResult: JSResult {
|
|
5
|
+
private let event: EKEvent?
|
|
6
|
+
private let eventStore: EKEventStore
|
|
7
|
+
|
|
8
|
+
init(_ event: EKEvent?, eventStore: EKEventStore) {
|
|
9
|
+
self.event = event
|
|
10
|
+
self.eventStore = eventStore
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func toJSON() -> JSObject {
|
|
14
|
+
var result = JSObject()
|
|
15
|
+
if let event = event {
|
|
16
|
+
var seriesStartDateCache: [String: Double] = [:]
|
|
17
|
+
result["event"] = ImplementationHelper.eventToJSObject(
|
|
18
|
+
event,
|
|
19
|
+
eventStore: eventStore,
|
|
20
|
+
seriesStartDateCache: &seriesStartDateCache
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
result["event"] = NSNull()
|
|
24
|
+
}
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -38,4 +38,18 @@ struct RecurrenceInput {
|
|
|
38
38
|
|
|
39
39
|
let weeksOfTheYear: [NSNumber]?
|
|
40
40
|
let daysOfTheYear: [NSNumber]?
|
|
41
|
+
|
|
42
|
+
func toEKRecurrenceRule() -> EKRecurrenceRule {
|
|
43
|
+
return EKRecurrenceRule(
|
|
44
|
+
recurrenceWith: frequency.toEKFrequency(),
|
|
45
|
+
interval: interval,
|
|
46
|
+
daysOfTheWeek: byWeekDay,
|
|
47
|
+
daysOfTheMonth: byMonthDay,
|
|
48
|
+
monthsOfTheYear: byMonth,
|
|
49
|
+
weeksOfTheYear: weeksOfTheYear,
|
|
50
|
+
daysOfTheYear: daysOfTheYear,
|
|
51
|
+
setPositions: nil,
|
|
52
|
+
end: end
|
|
53
|
+
)
|
|
54
|
+
}
|
|
41
55
|
}
|
|
@@ -24,6 +24,7 @@ struct PluginConfig {
|
|
|
24
24
|
CAPPluginMethod(name: "fetchAllRemindersSources", returnType: CAPPluginReturnPromise),
|
|
25
25
|
CAPPluginMethod(name: "getDefaultCalendar", returnType: CAPPluginReturnPromise),
|
|
26
26
|
CAPPluginMethod(name: "getDefaultRemindersList", returnType: CAPPluginReturnPromise),
|
|
27
|
+
CAPPluginMethod(name: "getEventById", returnType: CAPPluginReturnPromise),
|
|
27
28
|
CAPPluginMethod(name: "getReminderById", returnType: CAPPluginReturnPromise),
|
|
28
29
|
CAPPluginMethod(name: "getRemindersFromLists", returnType: CAPPluginReturnPromise),
|
|
29
30
|
CAPPluginMethod(name: "getRemindersLists", returnType: CAPPluginReturnPromise),
|
|
@@ -42,6 +43,8 @@ struct PluginConfig {
|
|
|
42
43
|
CAPPluginMethod(name: "requestReadOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
43
44
|
CAPPluginMethod(name: "requestWriteOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
44
45
|
CAPPluginMethod(name: "selectCalendarsWithPrompt", returnType: CAPPluginReturnPromise),
|
|
46
|
+
CAPPluginMethod(name: "startListening", returnType: CAPPluginReturnPromise),
|
|
47
|
+
CAPPluginMethod(name: "stopListening", returnType: CAPPluginReturnPromise),
|
|
45
48
|
CAPPluginMethod(name: "updateRemindersList", returnType: CAPPluginReturnPromise)
|
|
46
49
|
]
|
|
47
50
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
3
|
enum PluginError: LocalizedError {
|
|
4
|
+
case calendarChooserAlreadyPresented
|
|
4
5
|
case calendarIdMissing
|
|
5
6
|
case calendarNotFound
|
|
6
7
|
case calendarNotModifiable
|
|
@@ -18,6 +19,7 @@ enum PluginError: LocalizedError {
|
|
|
18
19
|
case invalidScope
|
|
19
20
|
case invalidUrl
|
|
20
21
|
case ioError(String)
|
|
22
|
+
case listIdMissing
|
|
21
23
|
case listIdsMissing
|
|
22
24
|
case listNotFound
|
|
23
25
|
case listNotModifiable
|
|
@@ -26,7 +28,10 @@ enum PluginError: LocalizedError {
|
|
|
26
28
|
case missingFrequency
|
|
27
29
|
case missingInterval
|
|
28
30
|
case noFieldsToModify
|
|
31
|
+
case permissionDenied(String)
|
|
29
32
|
case processFailed
|
|
33
|
+
case recurrenceNotChangeableForOccurrence
|
|
34
|
+
case reminderIdMissing
|
|
30
35
|
case reminderNotFound
|
|
31
36
|
case scopeMissing
|
|
32
37
|
case titleMissing
|
|
@@ -38,6 +43,8 @@ enum PluginError: LocalizedError {
|
|
|
38
43
|
|
|
39
44
|
var errorDescription: String? {
|
|
40
45
|
switch self {
|
|
46
|
+
case .calendarChooserAlreadyPresented:
|
|
47
|
+
return NSLocalizedString("Calendar chooser is already presented.", comment: "Calendar chooser already presented error")
|
|
41
48
|
case .calendarIdMissing:
|
|
42
49
|
return NSLocalizedString("Calendar ID must be provided.", comment: "Calendar ID missing error")
|
|
43
50
|
case .calendarNotFound:
|
|
@@ -72,6 +79,8 @@ enum PluginError: LocalizedError {
|
|
|
72
79
|
return NSLocalizedString("Invalid URL.", comment: "Invalid URL error")
|
|
73
80
|
case .ioError(let message):
|
|
74
81
|
return message
|
|
82
|
+
case .listIdMissing:
|
|
83
|
+
return NSLocalizedString("List ID must be provided.", comment: "List ID missing error")
|
|
75
84
|
case .listIdsMissing:
|
|
76
85
|
return NSLocalizedString("List IDs must be provided.", comment: "List IDs missing error")
|
|
77
86
|
case .listNotFound:
|
|
@@ -88,8 +97,17 @@ enum PluginError: LocalizedError {
|
|
|
88
97
|
return NSLocalizedString("Interval must be provided.", comment: "Interval missing error")
|
|
89
98
|
case .noFieldsToModify:
|
|
90
99
|
return NSLocalizedString("At least one of title or color must be provided.", comment: "No fields to modify error")
|
|
100
|
+
case .permissionDenied(let message):
|
|
101
|
+
return message
|
|
91
102
|
case .processFailed:
|
|
92
103
|
return NSLocalizedString("Process failed.", comment: "Process failed error")
|
|
104
|
+
case .recurrenceNotChangeableForOccurrence:
|
|
105
|
+
return NSLocalizedString(
|
|
106
|
+
"Recurrence cannot be changed for a single occurrence. Use THIS_AND_FUTURE_EVENTS.",
|
|
107
|
+
comment: "Recurrence not changeable for occurrence error"
|
|
108
|
+
)
|
|
109
|
+
case .reminderIdMissing:
|
|
110
|
+
return NSLocalizedString("Reminder ID must be provided.", comment: "Reminder ID missing error")
|
|
93
111
|
case .reminderNotFound:
|
|
94
112
|
return NSLocalizedString("Reminder not found.", comment: "Reminder not found error")
|
|
95
113
|
case .scopeMissing:
|
|
@@ -119,11 +137,14 @@ enum PluginError: LocalizedError {
|
|
|
119
137
|
.invalidFrequency,
|
|
120
138
|
.invalidScope,
|
|
121
139
|
.invalidUrl,
|
|
140
|
+
.listIdMissing,
|
|
122
141
|
.listIdsMissing,
|
|
123
142
|
.messageMissing,
|
|
124
143
|
.missingFrequency,
|
|
125
144
|
.missingInterval,
|
|
126
145
|
.noFieldsToModify,
|
|
146
|
+
.recurrenceNotChangeableForOccurrence,
|
|
147
|
+
.reminderIdMissing,
|
|
127
148
|
.scopeMissing,
|
|
128
149
|
.titleMissing,
|
|
129
150
|
.toDateMissing:
|
|
@@ -137,15 +158,23 @@ enum PluginError: LocalizedError {
|
|
|
137
158
|
case .failedToRetrieveCalendarId,
|
|
138
159
|
.failedToRetrieveEventId,
|
|
139
160
|
.ioError,
|
|
140
|
-
.processFailed
|
|
161
|
+
.processFailed,
|
|
162
|
+
.unhandledPermissionState:
|
|
141
163
|
return "EB-CLDR-0004"
|
|
142
164
|
case .failedToLaunchCalendar,
|
|
143
165
|
.failedToLaunchReminders,
|
|
144
|
-
.unableToOpenUrl
|
|
166
|
+
.unableToOpenUrl,
|
|
167
|
+
.calendarChooserAlreadyPresented,
|
|
168
|
+
.viewControllerMissing:
|
|
145
169
|
return "EB-CLDR-0005"
|
|
170
|
+
case .permissionDenied:
|
|
171
|
+
return "EB-CLDR-0020"
|
|
146
172
|
case .missingDeclaration:
|
|
147
173
|
return "EB-CLDR-0100"
|
|
148
|
-
|
|
174
|
+
case .calendarNotModifiable,
|
|
175
|
+
.customError,
|
|
176
|
+
.listNotModifiable,
|
|
177
|
+
.unimplemented:
|
|
149
178
|
return nil
|
|
150
179
|
}
|
|
151
180
|
}
|
|
@@ -47,18 +47,22 @@ struct ImplementationHelper {
|
|
|
47
47
|
return result
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
let permissionState: CAPPermissionState = granted ? .granted : .denied
|
|
59
|
-
continuation.resume(returning: permissionState)
|
|
50
|
+
/// Resolves an EventKit access request. An authorization denial resolves `denied` and does not throw.
|
|
51
|
+
private static func accessRequestHandler(
|
|
52
|
+
_ continuation: CheckedContinuation<CAPPermissionState, Error>
|
|
53
|
+
) -> (Bool, Error?) -> Void {
|
|
54
|
+
return { granted, error in
|
|
55
|
+
if let error = error, !PluginCallRejecter.isPermissionDenied(error) {
|
|
56
|
+
continuation.resume(throwing: error)
|
|
60
57
|
return
|
|
61
58
|
}
|
|
59
|
+
continuation.resume(returning: granted ? .granted : .denied)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static func requestWriteOnlyCalendarAccess(eventStore: EKEventStore) async throws -> CAPPermissionState {
|
|
64
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
65
|
+
let requestAccessHandler = accessRequestHandler(continuation)
|
|
62
66
|
|
|
63
67
|
if #available(iOS 17.0, *) {
|
|
64
68
|
eventStore.requestWriteOnlyAccessToEvents(completion: requestAccessHandler)
|
|
@@ -70,16 +74,7 @@ struct ImplementationHelper {
|
|
|
70
74
|
|
|
71
75
|
static func requestFullCalendarAccess(eventStore: EKEventStore) async throws -> CAPPermissionState {
|
|
72
76
|
return try await withCheckedThrowingContinuation { continuation in
|
|
73
|
-
let requestAccessHandler
|
|
74
|
-
if let error = error {
|
|
75
|
-
continuation.resume(throwing: error)
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let permissionState: CAPPermissionState = granted ? .granted : .denied
|
|
80
|
-
continuation.resume(returning: permissionState)
|
|
81
|
-
return
|
|
82
|
-
}
|
|
77
|
+
let requestAccessHandler = accessRequestHandler(continuation)
|
|
83
78
|
|
|
84
79
|
if #available(iOS 17.0, *) {
|
|
85
80
|
eventStore.requestFullAccessToEvents(completion: requestAccessHandler)
|
|
@@ -91,16 +86,7 @@ struct ImplementationHelper {
|
|
|
91
86
|
|
|
92
87
|
static func requestFullRemindersAccess(eventStore: EKEventStore) async throws -> CAPPermissionState {
|
|
93
88
|
return try await withCheckedThrowingContinuation { continuation in
|
|
94
|
-
let requestAccessHandler
|
|
95
|
-
if let error = error {
|
|
96
|
-
continuation.resume(throwing: error)
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let permissionState: CAPPermissionState = granted ? .granted : .denied
|
|
101
|
-
continuation.resume(returning: permissionState)
|
|
102
|
-
return
|
|
103
|
-
}
|
|
89
|
+
let requestAccessHandler = accessRequestHandler(continuation)
|
|
104
90
|
|
|
105
91
|
if #available(iOS 17.0, *) {
|
|
106
92
|
eventStore.requestFullAccessToReminders(completion: requestAccessHandler)
|
|
@@ -197,10 +183,41 @@ struct ImplementationHelper {
|
|
|
197
183
|
try eventStore.remove(reminder, commit: commit)
|
|
198
184
|
}
|
|
199
185
|
|
|
200
|
-
|
|
201
|
-
|
|
186
|
+
/// Finds the event for `id`.
|
|
187
|
+
/// Without `instanceDate`, a recurring series resolves to its first occurrence.
|
|
188
|
+
/// With `instanceDate`, resolves to the occurrence that starts at that time.
|
|
189
|
+
static func findEvent(id: String, instanceDate: Date?, eventStore: EKEventStore) throws -> EKEvent {
|
|
190
|
+
guard let instanceDate = instanceDate else {
|
|
191
|
+
guard let event = eventStore.event(withIdentifier: id) else {
|
|
192
|
+
throw PluginError.eventNotFound
|
|
193
|
+
}
|
|
194
|
+
return event
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let toleranceInSeconds: TimeInterval = 1
|
|
198
|
+
let predicate = eventStore.predicateForEvents(
|
|
199
|
+
withStart: instanceDate.addingTimeInterval(-toleranceInSeconds),
|
|
200
|
+
end: instanceDate.addingTimeInterval(toleranceInSeconds),
|
|
201
|
+
calendars: nil
|
|
202
|
+
)
|
|
203
|
+
let occurrence = eventStore.events(matching: predicate).first { candidate in
|
|
204
|
+
candidate.eventIdentifier == id
|
|
205
|
+
&& abs(candidate.startDate.timeIntervalSince(instanceDate)) < toleranceInSeconds
|
|
206
|
+
}
|
|
207
|
+
guard let occurrence = occurrence else {
|
|
202
208
|
throw PluginError.eventNotFound
|
|
203
209
|
}
|
|
210
|
+
return occurrence
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static func deleteEvent(
|
|
214
|
+
commit: Bool,
|
|
215
|
+
_ id: String,
|
|
216
|
+
_ span: EventSpan,
|
|
217
|
+
_ eventStore: EKEventStore,
|
|
218
|
+
instanceDate: Date? = nil
|
|
219
|
+
) throws {
|
|
220
|
+
let event = try findEvent(id: id, instanceDate: instanceDate, eventStore: eventStore)
|
|
204
221
|
switch span {
|
|
205
222
|
case .thisEvent:
|
|
206
223
|
try eventStore.remove(event, span: .thisEvent, commit: commit)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Capacitor
|
|
2
|
+
import EventKit
|
|
2
3
|
import Foundation
|
|
3
4
|
|
|
4
5
|
/// Maps thrown errors to `PluginError` and rejects the Capacitor call.
|
|
@@ -14,6 +15,11 @@ enum PluginCallRejecter {
|
|
|
14
15
|
if let error = error as? PluginError {
|
|
15
16
|
return error
|
|
16
17
|
} else if let error = error {
|
|
18
|
+
if isPermissionDenied(error) {
|
|
19
|
+
return .permissionDenied(
|
|
20
|
+
wrapSystemError("Calendar access was denied.", error.localizedDescription)
|
|
21
|
+
)
|
|
22
|
+
}
|
|
17
23
|
return .ioError(
|
|
18
24
|
wrapSystemError(
|
|
19
25
|
"An I/O error occurred while accessing the calendar.",
|
|
@@ -25,6 +31,13 @@ enum PluginCallRejecter {
|
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
/// True when EventKit rejects the call because the app has no calendar or reminders access.
|
|
35
|
+
static func isPermissionDenied(_ error: Error) -> Bool {
|
|
36
|
+
let nsError = error as NSError
|
|
37
|
+
return nsError.domain == EKErrorDomain
|
|
38
|
+
&& nsError.code == EKError.Code.eventStoreNotAuthorized.rawValue
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
/// Lead with the stable plugin sentence; append a different non-blank OS message in parentheses.
|
|
29
42
|
static func wrapSystemError(_ canonicalMessage: String, _ systemMessage: String?) -> String {
|
|
30
43
|
let detail = systemMessage?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebarooni/capacitor-calendar",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.12.0",
|
|
4
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",
|