@ebarooni/capacitor-calendar 8.3.0 → 8.5.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 +225 -97
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +42 -7
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +31 -21
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +59 -15
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CheckPermissionInput.kt +0 -4
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateCalendarInput.kt +3 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteCalendarInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetDefaultCalendarInput.kt +9 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyCalendarInput.kt +10 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/RequestPermissionInput.kt +3 -5
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CheckAllPermissionsResult.kt +3 -2
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/RequestAllPermissionsResult.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/templates/PluginCompletion.kt +8 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +68 -31
- package/dist/docs.json +562 -70
- package/dist/esm/index.d.ts +12 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +8 -0
- package/dist/esm/schemas/enums/calendar-permission-scope.js +8 -0
- package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar-source.d.ts +3 -0
- package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar.d.ts +12 -2
- package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
- package/dist/esm/schemas/interfaces/check-permission-options.d.ts +19 -0
- package/dist/esm/schemas/interfaces/check-permission-options.js +2 -0
- package/dist/esm/schemas/interfaces/check-permission-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +16 -5
- package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-calendar-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/create-calendar-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-calendar-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +22 -13
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-result.d.ts +23 -0
- package/dist/esm/schemas/interfaces/create-event-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-event-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.d.ts +14 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/delete-calendar-options.d.ts +1 -0
- package/dist/esm/schemas/interfaces/delete-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js +2 -0
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.js +2 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.js +2 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +7 -2
- package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +8 -1
- package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +5 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/request-permission-options.d.ts +16 -0
- package/dist/esm/schemas/interfaces/request-permission-options.js +2 -0
- package/dist/esm/schemas/interfaces/request-permission-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.d.ts +14 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js +2 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-access.d.ts +22 -10
- package/dist/esm/sub-definitions/calendar-access.js.map +1 -1
- package/dist/esm/sub-definitions/calendar-operations.d.ts +61 -14
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/sub-definitions/event-operations.d.ts +35 -9
- package/dist/esm/sub-definitions/event-operations.js.map +1 -1
- package/dist/esm/sub-definitions/reminders-access.d.ts +4 -0
- package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
- package/dist/esm/web/download-ics-file.d.ts +18 -0
- package/dist/esm/web/download-ics-file.js +33 -0
- package/dist/esm/web/download-ics-file.js.map +1 -0
- package/dist/esm/web/ics.d.ts +21 -0
- package/dist/esm/web/ics.js +252 -0
- package/dist/esm/web/ics.js.map +1 -0
- package/dist/esm/web.d.ts +19 -27
- package/dist/esm/web.js +14 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +306 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +306 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -16
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +64 -34
- package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +4 -5
- package/ios/Plugin/Models/Inputs/DeleteCalendarInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/GetDefaultCalendarInput.swift +13 -0
- package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +4 -1
- package/ios/Plugin/PluginError.swift +68 -56
- package/ios/Plugin/Utils/ImplementationHelper.swift +15 -12
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ class CapacitorCalendar: NSObject {
|
|
|
8
8
|
private let eventStore = EKEventStore()
|
|
9
9
|
private var modifyEventWithPromptContinuation: CheckedContinuation<ModifyEventWithPromptResult, Error>?
|
|
10
10
|
private let plugin: CapacitorCalendarPlugin
|
|
11
|
-
private var
|
|
11
|
+
private var selectCalendarsWithPromptCompletion: ((SelectCalendarsWithPromptResult?, Error?) -> Void)?
|
|
12
12
|
|
|
13
13
|
init(plugin: CapacitorCalendarPlugin) {
|
|
14
14
|
self.plugin = plugin
|
|
@@ -276,25 +276,32 @@ class CapacitorCalendar: NSObject {
|
|
|
276
276
|
try eventStore.save(event, span: input.getSpan())
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
func selectCalendarsWithPrompt(
|
|
279
|
+
func selectCalendarsWithPrompt(
|
|
280
|
+
input: SelectCalendarsWithPromptInput,
|
|
281
|
+
completion: @escaping (SelectCalendarsWithPromptResult?, Error?) -> Void
|
|
282
|
+
) {
|
|
280
283
|
guard let viewController = plugin.bridge?.viewController else {
|
|
281
|
-
|
|
284
|
+
completion(nil, PluginError.viewControllerMissing)
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
guard selectCalendarsWithPromptCompletion == nil else {
|
|
288
|
+
completion(nil, PluginError.customError("Calendar chooser is already presented."))
|
|
289
|
+
return
|
|
282
290
|
}
|
|
283
|
-
return try await withCheckedThrowingContinuation { continuation in
|
|
284
|
-
Task { @MainActor in
|
|
285
|
-
let calendarChooser = EKCalendarChooser(
|
|
286
|
-
selectionStyle: input.getSelectionStyle(),
|
|
287
|
-
displayStyle: input.getDisplayStyle(),
|
|
288
|
-
eventStore: eventStore
|
|
289
|
-
)
|
|
290
|
-
calendarChooser.showsDoneButton = true
|
|
291
|
-
calendarChooser.showsCancelButton = true
|
|
292
|
-
calendarChooser.delegate = self
|
|
293
291
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
292
|
+
selectCalendarsWithPromptCompletion = completion
|
|
293
|
+
|
|
294
|
+
Task { @MainActor in
|
|
295
|
+
let calendarChooser = EKCalendarChooser(
|
|
296
|
+
selectionStyle: input.getSelectionStyle(),
|
|
297
|
+
displayStyle: input.getDisplayStyle(),
|
|
298
|
+
eventStore: eventStore
|
|
299
|
+
)
|
|
300
|
+
calendarChooser.showsDoneButton = true
|
|
301
|
+
calendarChooser.showsCancelButton = true
|
|
302
|
+
calendarChooser.delegate = self
|
|
303
|
+
|
|
304
|
+
viewController.present(UINavigationController(rootViewController: calendarChooser), animated: true)
|
|
298
305
|
}
|
|
299
306
|
}
|
|
300
307
|
|
|
@@ -302,8 +309,8 @@ class CapacitorCalendar: NSObject {
|
|
|
302
309
|
return FetchAllCalendarSourcesResult(eventStore.sources)
|
|
303
310
|
}
|
|
304
311
|
|
|
305
|
-
func listCalendars()
|
|
306
|
-
|
|
312
|
+
func listCalendars(completion: @escaping (ListCalendarsResult?, Error?) -> Void) {
|
|
313
|
+
completion(ListCalendarsResult(eventStore.calendars(for: .event)), nil)
|
|
307
314
|
}
|
|
308
315
|
|
|
309
316
|
func openReminders() async throws {
|
|
@@ -323,9 +330,6 @@ class CapacitorCalendar: NSObject {
|
|
|
323
330
|
guard let url = URL(string: "calshow:\(input.getDate())") else {
|
|
324
331
|
throw PluginError.invalidUrl
|
|
325
332
|
}
|
|
326
|
-
guard await UIApplication.shared.canOpenURL(url) else {
|
|
327
|
-
throw PluginError.unableToOpenUrl
|
|
328
|
-
}
|
|
329
333
|
let success = await UIApplication.shared.open(url, options: [:])
|
|
330
334
|
if !success {
|
|
331
335
|
throw PluginError.failedToLaunchCalendar
|
|
@@ -335,14 +339,37 @@ class CapacitorCalendar: NSObject {
|
|
|
335
339
|
func createCalendar(input: CreateCalendarInput) throws -> CreateCalendarResult {
|
|
336
340
|
let newCalendar = EKCalendar(for: .event, eventStore: eventStore)
|
|
337
341
|
newCalendar.title = input.getTitle()
|
|
338
|
-
newCalendar.cgColor = input.getColor()
|
|
339
|
-
|
|
342
|
+
newCalendar.cgColor = input.getColor()
|
|
343
|
+
|
|
344
|
+
let sources = eventStore.sources
|
|
345
|
+
if let sourceId = input.getSourceId() {
|
|
346
|
+
guard let customSource = sources.first(where: { $0.sourceIdentifier == sourceId }) else {
|
|
347
|
+
throw PluginError.calendarSourceNotFound
|
|
348
|
+
}
|
|
349
|
+
newCalendar.source = customSource
|
|
350
|
+
} else if let iCloudSource = sources.first(where: { $0.sourceType == .calDAV && $0.title == "iCloud" }) {
|
|
351
|
+
newCalendar.source = iCloudSource
|
|
352
|
+
} else if let localSource = sources.first(where: { $0.sourceType == .local }) {
|
|
353
|
+
newCalendar.source = localSource
|
|
354
|
+
}
|
|
355
|
+
|
|
340
356
|
try eventStore.saveCalendar(newCalendar, commit: true)
|
|
341
357
|
return try CreateCalendarResult(id: newCalendar.calendarIdentifier)
|
|
342
358
|
}
|
|
343
359
|
|
|
344
|
-
func getDefaultCalendar(
|
|
345
|
-
|
|
360
|
+
func getDefaultCalendar(
|
|
361
|
+
input: GetDefaultCalendarInput,
|
|
362
|
+
completion: @escaping (GetDefaultCalendarResult?, Error?) -> Void
|
|
363
|
+
) {
|
|
364
|
+
if let calendar = eventStore.defaultCalendarForNewEvents {
|
|
365
|
+
completion(GetDefaultCalendarResult(calendar: calendar), nil)
|
|
366
|
+
return
|
|
367
|
+
}
|
|
368
|
+
if input.getUseFallbackCalendar() {
|
|
369
|
+
completion(GetDefaultCalendarResult(calendar: eventStore.calendars(for: .event).first), nil)
|
|
370
|
+
return
|
|
371
|
+
}
|
|
372
|
+
completion(GetDefaultCalendarResult(calendar: nil), nil)
|
|
346
373
|
}
|
|
347
374
|
|
|
348
375
|
func getDefaultRemindersList() throws -> GetDefaultCalendarResult {
|
|
@@ -534,6 +561,9 @@ class CapacitorCalendar: NSObject {
|
|
|
534
561
|
guard let calendar = eventStore.calendar(withIdentifier: input.getId()) else {
|
|
535
562
|
throw PluginError.calendarNotFound
|
|
536
563
|
}
|
|
564
|
+
guard calendar.allowsContentModifications else {
|
|
565
|
+
throw PluginError.calendarNotModifiable
|
|
566
|
+
}
|
|
537
567
|
if let title = input.getTitle() {
|
|
538
568
|
calendar.title = title
|
|
539
569
|
}
|
|
@@ -600,17 +630,17 @@ class CapacitorCalendar: NSObject {
|
|
|
600
630
|
|
|
601
631
|
extension CapacitorCalendar: EKCalendarChooserDelegate {
|
|
602
632
|
func calendarChooserDidFinish(_ calendarChooser: EKCalendarChooser) {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
633
|
+
let completion = selectCalendarsWithPromptCompletion
|
|
634
|
+
selectCalendarsWithPromptCompletion = nil
|
|
635
|
+
completion?(SelectCalendarsWithPromptResult(calendarChooser.selectedCalendars), nil)
|
|
636
|
+
plugin.bridge?.viewController?.dismiss(animated: true)
|
|
607
637
|
}
|
|
608
638
|
|
|
609
639
|
func calendarChooserDidCancel(_ calendarChooser: EKCalendarChooser) {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
640
|
+
let completion = selectCalendarsWithPromptCompletion
|
|
641
|
+
selectCalendarsWithPromptCompletion = nil
|
|
642
|
+
completion?(SelectCalendarsWithPromptResult([]), nil)
|
|
643
|
+
plugin.bridge?.viewController?.dismiss(animated: true)
|
|
614
644
|
}
|
|
615
645
|
}
|
|
616
646
|
|
|
@@ -2,7 +2,7 @@ import Capacitor
|
|
|
2
2
|
|
|
3
3
|
struct CreateCalendarInput {
|
|
4
4
|
private let title: String
|
|
5
|
-
private var color: CGColor
|
|
5
|
+
private var color: CGColor
|
|
6
6
|
private var sourceId: String?
|
|
7
7
|
|
|
8
8
|
init(call: CAPPluginCall) throws {
|
|
@@ -10,9 +10,8 @@ struct CreateCalendarInput {
|
|
|
10
10
|
throw PluginError.titleMissing
|
|
11
11
|
}
|
|
12
12
|
self.title = title
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
let colorHex = call.getString("color") ?? ImplementationHelper.defaultCalendarColorHex
|
|
14
|
+
self.color = try UIColor.fromHex(colorHex).cgColor
|
|
16
15
|
if let sourceId = call.getString("sourceId") {
|
|
17
16
|
self.sourceId = sourceId
|
|
18
17
|
}
|
|
@@ -22,7 +21,7 @@ struct CreateCalendarInput {
|
|
|
22
21
|
return title
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
func getColor() -> CGColor
|
|
24
|
+
func getColor() -> CGColor {
|
|
26
25
|
return color
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
|
|
3
|
+
struct GetDefaultCalendarInput {
|
|
4
|
+
private let useFallbackCalendar: Bool
|
|
5
|
+
|
|
6
|
+
init(call: CAPPluginCall) {
|
|
7
|
+
self.useFallbackCalendar = call.getBool("useFallbackCalendar", false)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
func getUseFallbackCalendar() -> Bool {
|
|
11
|
+
return useFallbackCalendar
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -7,7 +7,7 @@ struct ModifyCalendarInput {
|
|
|
7
7
|
|
|
8
8
|
init(call: CAPPluginCall) throws {
|
|
9
9
|
guard let id = call.getString("id") else {
|
|
10
|
-
throw PluginError.
|
|
10
|
+
throw PluginError.calendarIdMissing
|
|
11
11
|
}
|
|
12
12
|
self.id = id
|
|
13
13
|
self.title = call.getString("title")
|
|
@@ -16,6 +16,9 @@ struct ModifyCalendarInput {
|
|
|
16
16
|
} else {
|
|
17
17
|
self.color = nil
|
|
18
18
|
}
|
|
19
|
+
if self.title == nil && self.color == nil {
|
|
20
|
+
throw PluginError.noFieldsToModify
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
func getId() -> String {
|
|
@@ -1,90 +1,102 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
3
|
enum PluginError: LocalizedError {
|
|
4
|
-
case
|
|
5
|
-
case
|
|
6
|
-
case
|
|
7
|
-
case
|
|
8
|
-
case
|
|
9
|
-
case idMissing
|
|
10
|
-
case listIdsMissing
|
|
11
|
-
case titleMissing
|
|
12
|
-
case messageMissing
|
|
13
|
-
case failedToRetrieveEventId
|
|
14
|
-
case failedToRetrieveCalendarId
|
|
4
|
+
case calendarIdMissing
|
|
5
|
+
case calendarNotFound
|
|
6
|
+
case calendarNotModifiable
|
|
7
|
+
case calendarSourceNotFound
|
|
8
|
+
case customError(String)
|
|
15
9
|
case eventNotFound
|
|
16
|
-
case reminderNotFound
|
|
17
|
-
case invalidUrl
|
|
18
|
-
case unableToOpenUrl
|
|
19
|
-
case failedToLaunchReminders
|
|
20
10
|
case failedToLaunchCalendar
|
|
11
|
+
case failedToLaunchReminders
|
|
12
|
+
case failedToRetrieveCalendarId
|
|
13
|
+
case failedToRetrieveEventId
|
|
14
|
+
case fromDateMissing
|
|
15
|
+
case idMissing
|
|
21
16
|
case invalidColor
|
|
22
|
-
case
|
|
17
|
+
case invalidScope
|
|
18
|
+
case invalidUrl
|
|
19
|
+
case listIdsMissing
|
|
23
20
|
case listNotFound
|
|
24
21
|
case listNotModifiable
|
|
22
|
+
case messageMissing
|
|
25
23
|
case missingFrequency
|
|
26
24
|
case missingInterval
|
|
27
|
-
case
|
|
25
|
+
case noFieldsToModify
|
|
26
|
+
case processFailed
|
|
27
|
+
case reminderNotFound
|
|
28
|
+
case scopeMissing
|
|
29
|
+
case titleMissing
|
|
28
30
|
case toDateMissing
|
|
31
|
+
case unableToOpenUrl
|
|
29
32
|
case unimplemented(String)
|
|
30
|
-
case
|
|
33
|
+
case unhandledPermissionState
|
|
34
|
+
case viewControllerMissing
|
|
31
35
|
|
|
32
36
|
var errorDescription: String? {
|
|
33
37
|
switch self {
|
|
34
|
-
case .
|
|
35
|
-
return NSLocalizedString("
|
|
36
|
-
case .
|
|
37
|
-
return NSLocalizedString("
|
|
38
|
-
case .
|
|
39
|
-
return NSLocalizedString("
|
|
40
|
-
case .
|
|
41
|
-
return NSLocalizedString("
|
|
38
|
+
case .calendarIdMissing:
|
|
39
|
+
return NSLocalizedString("Calendar ID must be provided.", comment: "Calendar ID missing error")
|
|
40
|
+
case .calendarNotFound:
|
|
41
|
+
return NSLocalizedString("Calendar not found.", comment: "Calendar not found error")
|
|
42
|
+
case .calendarNotModifiable:
|
|
43
|
+
return NSLocalizedString("Calendar is not modifiable.", comment: "Calendar not modifiable error")
|
|
44
|
+
case .calendarSourceNotFound:
|
|
45
|
+
return NSLocalizedString("Calendar source not found.", comment: "Calendar source not found error")
|
|
46
|
+
case .customError(let message):
|
|
47
|
+
return message
|
|
48
|
+
case .eventNotFound:
|
|
49
|
+
return NSLocalizedString("Event not found.", comment: "Event not found error")
|
|
50
|
+
case .failedToLaunchCalendar:
|
|
51
|
+
return NSLocalizedString("Failed to launch calendar app.", comment: "Failed to launch calendar app error")
|
|
52
|
+
case .failedToLaunchReminders:
|
|
53
|
+
return NSLocalizedString("Failed to launch reminders app.", comment: "Failed to launch reminders app error")
|
|
54
|
+
case .failedToRetrieveCalendarId:
|
|
55
|
+
return NSLocalizedString("Failed to retrieve calendar ID.", comment: "Failed to retrieve calendar ID error")
|
|
56
|
+
case .failedToRetrieveEventId:
|
|
57
|
+
return NSLocalizedString("Failed to retrieve event ID.", comment: "Failed to retrieve event ID error")
|
|
58
|
+
case .fromDateMissing:
|
|
59
|
+
return NSLocalizedString("From date must be provided.", comment: "From date missing error")
|
|
42
60
|
case .idMissing:
|
|
43
61
|
return NSLocalizedString("Event ID must be provided.", comment: "Event ID missing error")
|
|
62
|
+
case .invalidColor:
|
|
63
|
+
return NSLocalizedString("Invalid color format.", comment: "Invalid color format error")
|
|
64
|
+
case .invalidScope:
|
|
65
|
+
return NSLocalizedString("Invalid scope.", comment: "Invalid scope error")
|
|
66
|
+
case .invalidUrl:
|
|
67
|
+
return NSLocalizedString("Invalid URL.", comment: "Invalid URL error")
|
|
44
68
|
case .listIdsMissing:
|
|
45
69
|
return NSLocalizedString("List IDs must be provided.", comment: "List IDs missing error")
|
|
46
|
-
case .titleMissing:
|
|
47
|
-
return NSLocalizedString("Title must be provided.", comment: "Title missing error")
|
|
48
|
-
case .messageMissing:
|
|
49
|
-
return NSLocalizedString("Message must be provided.", comment: "Message missing error")
|
|
50
|
-
case .failedToRetrieveEventId:
|
|
51
|
-
return NSLocalizedString("Failed to retrieve event ID.", comment: "Failed to retrieve event ID error")
|
|
52
|
-
case .failedToRetrieveCalendarId:
|
|
53
|
-
return NSLocalizedString("Failed to retrieve calendar ID.", comment: "Failed to retrieve calendar ID error")
|
|
54
|
-
case .eventNotFound:
|
|
55
|
-
return NSLocalizedString("Event not found.", comment: "Event not found error")
|
|
56
|
-
case .reminderNotFound:
|
|
57
|
-
return NSLocalizedString("Reminder not found.", comment: "Reminder not found error")
|
|
58
|
-
case .calendarNotFound:
|
|
59
|
-
return NSLocalizedString("Calendar not found.", comment: "Calendar not found error")
|
|
60
70
|
case .listNotFound:
|
|
61
71
|
return NSLocalizedString("List not found.", comment: "List not found error")
|
|
62
72
|
case .listNotModifiable:
|
|
63
73
|
return NSLocalizedString("List is not modifiable.", comment: "List not modifiable error")
|
|
64
|
-
case .
|
|
65
|
-
return NSLocalizedString("
|
|
66
|
-
case .unableToOpenUrl:
|
|
67
|
-
return NSLocalizedString("Unable to open URL.", comment: "Unable to open URL error")
|
|
68
|
-
case .failedToLaunchReminders:
|
|
69
|
-
return NSLocalizedString("Failed to launch reminders app.", comment: "Failed to launch reminders app error")
|
|
70
|
-
case .failedToLaunchCalendar:
|
|
71
|
-
return NSLocalizedString("Failed to launch calendar app.", comment: "Failed to launch calendar app error")
|
|
72
|
-
case .invalidColor:
|
|
73
|
-
return NSLocalizedString("Invalid color format.", comment: "Invalid color format error")
|
|
74
|
-
case .processFailed:
|
|
75
|
-
return NSLocalizedString("Process failed.", comment: "Process failed error")
|
|
74
|
+
case .messageMissing:
|
|
75
|
+
return NSLocalizedString("Message must be provided.", comment: "Message missing error")
|
|
76
76
|
case .missingFrequency:
|
|
77
77
|
return NSLocalizedString("Frequency must be provided.", comment: "Frequency missing error")
|
|
78
78
|
case .missingInterval:
|
|
79
79
|
return NSLocalizedString("Interval must be provided.", comment: "Interval missing error")
|
|
80
|
-
case .
|
|
81
|
-
return NSLocalizedString("
|
|
80
|
+
case .noFieldsToModify:
|
|
81
|
+
return NSLocalizedString("At least one of title or color must be provided.", comment: "No fields to modify error")
|
|
82
|
+
case .processFailed:
|
|
83
|
+
return NSLocalizedString("Process failed.", comment: "Process failed error")
|
|
84
|
+
case .reminderNotFound:
|
|
85
|
+
return NSLocalizedString("Reminder not found.", comment: "Reminder not found error")
|
|
86
|
+
case .scopeMissing:
|
|
87
|
+
return NSLocalizedString("Scope must be provided.", comment: "Scope missing error")
|
|
88
|
+
case .titleMissing:
|
|
89
|
+
return NSLocalizedString("Title must be provided.", comment: "Title missing error")
|
|
82
90
|
case .toDateMissing:
|
|
83
91
|
return NSLocalizedString("To date must be provided.", comment: "To date missing error")
|
|
92
|
+
case .unableToOpenUrl:
|
|
93
|
+
return NSLocalizedString("Unable to open URL.", comment: "Unable to open URL error")
|
|
84
94
|
case .unimplemented(let methodName):
|
|
85
95
|
return NSLocalizedString("\(methodName) is not implemented on iOS.", comment: "\(methodName) is not implemented on iOS")
|
|
86
|
-
case .
|
|
87
|
-
return
|
|
96
|
+
case .unhandledPermissionState:
|
|
97
|
+
return NSLocalizedString("Unhandled permission state.", comment: "Unhandled permission state error")
|
|
98
|
+
case .viewControllerMissing:
|
|
99
|
+
return NSLocalizedString("Missing view controller.", comment: "View controller missing error")
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
}
|
|
@@ -2,6 +2,9 @@ import EventKit
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
|
|
4
4
|
struct ImplementationHelper {
|
|
5
|
+
/// Default calendar color when `color` is omitted: `#007AFF` (light-mode iOS system blue).
|
|
6
|
+
static let defaultCalendarColorHex = "#007AFF"
|
|
7
|
+
|
|
5
8
|
static func permissionStateToResult(state: EKAuthorizationStatus, scope: CalendarPermissionScope ) throws -> CAPPermissionState {
|
|
6
9
|
var result: CAPPermissionState
|
|
7
10
|
|
|
@@ -107,23 +110,23 @@ struct ImplementationHelper {
|
|
|
107
110
|
guard let components = color.components else { return nil }
|
|
108
111
|
|
|
109
112
|
if components.count == 2 {
|
|
110
|
-
let gray = Float(components[0])
|
|
111
|
-
let alpha = Float(components[1])
|
|
112
|
-
return alpha
|
|
113
|
-
? String(format: "#%02lX%02lX%02lX
|
|
114
|
-
: String(format: "#%02lX%02lX%02lX",
|
|
113
|
+
let gray = lroundf(Float(components[0]) * 255)
|
|
114
|
+
let alpha = lroundf(Float(components[1]) * 255)
|
|
115
|
+
return alpha == 255
|
|
116
|
+
? String(format: "#%02lX%02lX%02lX", gray, gray, gray)
|
|
117
|
+
: String(format: "#%02lX%02lX%02lX%02lX", gray, gray, gray, alpha)
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
guard components.count >= 3 else { return nil }
|
|
118
121
|
|
|
119
|
-
let red = Float(components[0])
|
|
120
|
-
let green = Float(components[1])
|
|
121
|
-
let blue = Float(components[2])
|
|
122
|
-
let alpha = components.count == 4 ? Float(components[3]) :
|
|
122
|
+
let red = lroundf(Float(components[0]) * 255)
|
|
123
|
+
let green = lroundf(Float(components[1]) * 255)
|
|
124
|
+
let blue = lroundf(Float(components[2]) * 255)
|
|
125
|
+
let alpha = components.count == 4 ? lroundf(Float(components[3]) * 255) : 255
|
|
123
126
|
|
|
124
|
-
return alpha
|
|
125
|
-
? String(format: "#%02lX%02lX%02lX
|
|
126
|
-
: String(format: "#%02lX%02lX%02lX",
|
|
127
|
+
return alpha == 255
|
|
128
|
+
? String(format: "#%02lX%02lX%02lX", red, green, blue)
|
|
129
|
+
: String(format: "#%02lX%02lX%02lX%02lX", red, green, blue, alpha)
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
static func deleteReminder(reminderId: String, eventStore: EKEventStore) throws {
|
package/package.json
CHANGED