@ebarooni/capacitor-calendar 0.1.0 → 0.2.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 +61 -29
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +12 -11
- package/dist/docs.json +110 -19
- package/dist/esm/definitions.d.ts +60 -11
- package/dist/esm/definitions.js +28 -10
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -2
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +31 -10
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +31 -10
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Calendar.swift +14 -0
- package/ios/Plugin/CapacitorCalendar.swift +162 -138
- package/ios/Plugin/CapacitorCalendarPlugin.m +1 -0
- package/ios/Plugin/CapacitorCalendarPlugin.swift +106 -7
- package/ios/Plugin/CapacitorCalendarPluginError.swift +17 -0
- package/ios/Plugin/PermissionState.swift +16 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import EventKit
|
|
2
3
|
import Capacitor
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -7,27 +8,125 @@ import Capacitor
|
|
|
7
8
|
*/
|
|
8
9
|
@objc(CapacitorCalendarPlugin)
|
|
9
10
|
public class CapacitorCalendarPlugin: CAPPlugin {
|
|
10
|
-
private
|
|
11
|
+
private let eventStore = EKEventStore()
|
|
12
|
+
private lazy var implementation = CapacitorCalendar(bridge: self.bridge, eventStore: self.eventStore)
|
|
11
13
|
|
|
12
14
|
@objc public func checkPermission(_ call: CAPPluginCall) {
|
|
13
|
-
|
|
15
|
+
guard let alias = call.getString("alias") else {
|
|
16
|
+
call.reject("[CapacitorCalendar.\(#function)] Permission name is not defined")
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Task {
|
|
21
|
+
do {
|
|
22
|
+
let permissionsState = try await implementation.checkAllPermissions()
|
|
23
|
+
|
|
24
|
+
switch alias {
|
|
25
|
+
case "readCalendar":
|
|
26
|
+
call.resolve(["result": permissionsState["readCalendar"]!])
|
|
27
|
+
case "writeCalendar":
|
|
28
|
+
call.resolve(["result": permissionsState["writeCalendar"]!])
|
|
29
|
+
default:
|
|
30
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not determine the status of the requested permission")
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not determine the status of the requested permission")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
}
|
|
14
38
|
}
|
|
15
39
|
|
|
16
40
|
@objc public func checkAllPermissions(_ call: CAPPluginCall) {
|
|
17
|
-
|
|
41
|
+
Task {
|
|
42
|
+
do {
|
|
43
|
+
let permissionsState = try await implementation.checkAllPermissions()
|
|
44
|
+
call.resolve(permissionsState)
|
|
45
|
+
} catch {
|
|
46
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not determine the status of the requested permissions")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
}
|
|
18
50
|
}
|
|
19
51
|
|
|
20
52
|
@objc public func requestPermission(_ call: CAPPluginCall) {
|
|
21
|
-
|
|
53
|
+
guard let alias = call.getString("alias") else {
|
|
54
|
+
call.reject("[CapacitorCalendar.\(#function)] Permission name is not defined")
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Task {
|
|
59
|
+
do {
|
|
60
|
+
switch alias {
|
|
61
|
+
case "writeCalendar":
|
|
62
|
+
let result = try await implementation.requestWriteAccessToEvents()
|
|
63
|
+
call.resolve(result)
|
|
64
|
+
case "readCalendar":
|
|
65
|
+
let result = try await implementation.requestFullAccessToEvents()
|
|
66
|
+
call.resolve(["result": result])
|
|
67
|
+
default:
|
|
68
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not authorize \(alias)")
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not authorize \(alias)")
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
}
|
|
22
76
|
}
|
|
23
77
|
|
|
24
78
|
@objc public func requestAllPermissions(_ call: CAPPluginCall) {
|
|
25
|
-
|
|
79
|
+
Task {
|
|
80
|
+
do {
|
|
81
|
+
let result = try await implementation.requestFullAccessToEvents()
|
|
82
|
+
if (result == PermissionState.granted.rawValue) {
|
|
83
|
+
call.resolve([
|
|
84
|
+
"readCalendar": PermissionState.granted.rawValue,
|
|
85
|
+
"writeCalendar": PermissionState.granted.rawValue
|
|
86
|
+
])
|
|
87
|
+
} else {
|
|
88
|
+
call.resolve([
|
|
89
|
+
"readCalendar": PermissionState.denied.rawValue,
|
|
90
|
+
"writeCalendar": PermissionState.denied.rawValue
|
|
91
|
+
])
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
call.reject("[CapacitorCalendar.\(#function)] Could not authorize all permissions")
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
}
|
|
26
98
|
}
|
|
27
99
|
|
|
28
100
|
@objc public func createEventWithPrompt(_ call: CAPPluginCall) {
|
|
29
|
-
|
|
30
|
-
|
|
101
|
+
Task {
|
|
102
|
+
do {
|
|
103
|
+
let result = try await implementation.createEventWithPrompt()
|
|
104
|
+
call.resolve(["eventCreated": result])
|
|
105
|
+
} catch {
|
|
106
|
+
call.reject("[CapacitorCalendar.\(#function)] Unable to retrieve view controller")
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@objc public func selectCalendarsWithPrompt(_ call: CAPPluginCall) {
|
|
113
|
+
guard let selectionStyle = call.getInt("selectionStyle") else {
|
|
114
|
+
call.reject("[CapacitorCalendar.\(#function)] Selection style was not provided")
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
guard let displayStyle = call.getInt("displayStyle") else {
|
|
118
|
+
call.reject("[CapacitorCalendar.\(#function)] Display style was not provided")
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
Task {
|
|
123
|
+
do {
|
|
124
|
+
let result = try await implementation.selectCalendarsWithPrompt(selectionStyle: selectionStyle, displayStyle: displayStyle)
|
|
125
|
+
call.resolve(["result": result])
|
|
126
|
+
} catch {
|
|
127
|
+
call.reject("[CapacitorCalendar.\(#function)] Calendars selection prompt got canceled")
|
|
128
|
+
return
|
|
129
|
+
}
|
|
31
130
|
}
|
|
32
131
|
}
|
|
33
132
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PermissionError.swift
|
|
3
|
+
// Plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by Ehsan Barooni on 27.02.24.
|
|
6
|
+
// Copyright © 2024 Max Lynch. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
public enum CapacitorCalendarPluginError: Error {
|
|
12
|
+
case unknownPermissionStatus
|
|
13
|
+
case eventStoreAuthorization
|
|
14
|
+
case viewControllerUnavailable
|
|
15
|
+
case unknownActionEventCreationPrompt
|
|
16
|
+
case canceledCalendarsSelectionPrompt
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PermissionState.swift
|
|
3
|
+
// Plugin
|
|
4
|
+
//
|
|
5
|
+
// Created by Ehsan Barooni on 28.02.24.
|
|
6
|
+
// Copyright © 2024 Max Lynch. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
public enum PermissionState: String {
|
|
12
|
+
case granted = "granted"
|
|
13
|
+
case denied = "denied"
|
|
14
|
+
case prompt = "prompt"
|
|
15
|
+
case promptWithRationale = "prompt-with-rationale"
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebarooni/capacitor-calendar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The Capacitor Calendar Plugin exposes functionalities for interacting with the calendar of iOS and Android devices.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"native",
|
|
29
29
|
"calendar"
|
|
30
30
|
],
|
|
31
|
-
"homepage": "https://
|
|
31
|
+
"homepage": "https://capacitor-calendar.pages.dev",
|
|
32
32
|
"scripts": {
|
|
33
33
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
34
|
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|