@ebarooni/capacitor-calendar 0.1.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/EbarooniCapacitorCalendar.podspec +17 -0
- package/README.md +193 -0
- package/android/build.gradle +64 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +159 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +229 -0
- package/dist/esm/definitions.d.ts +94 -0
- package/dist/esm/definitions.js +14 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +19 -0
- package/dist/esm/web.js +19 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +49 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +52 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/CapacitorCalendar.swift +181 -0
- package/ios/Plugin/CapacitorCalendarPlugin.h +10 -0
- package/ios/Plugin/CapacitorCalendarPlugin.m +12 -0
- package/ios/Plugin/CapacitorCalendarPlugin.swift +33 -0
- package/ios/Plugin/Info.plist +24 -0
- package/package.json +85 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'EbarooniCapacitorCalendar'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<h1 align="center">CapacitorCalendar</h1>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<em>
|
|
4
|
+
This CapacitorJS plugin simplifies the process of managing calendar events within your hybrid mobile applications.
|
|
5
|
+
With CRUD functionalities (Create, Read, Update, Delete), you can seamlessly interact with the device's native
|
|
6
|
+
calendar directly from your app.
|
|
7
|
+
</em>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://capacitor-calendar.netlify.app/"><strong>https://capacitor-calendar.netlify.app</strong></a>
|
|
11
|
+
<br>
|
|
12
|
+
</p>
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://app.netlify.com/sites/capacitor-calendar/deploys">
|
|
15
|
+
<img src="https://api.netlify.com/api/v1/badges/0f1a6d09-740f-4f52-889c-38ff57d11380/deploy-status" alt="Netlify Status">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
## Table of Contents
|
|
20
|
+
|
|
21
|
+
- [Demo](#demo--click-for-details-)
|
|
22
|
+
- [Upcoming Features](#upcoming-features)
|
|
23
|
+
- [Support Range](#support-range)
|
|
24
|
+
- [Install](#install)
|
|
25
|
+
- [Permissions](#permissions)
|
|
26
|
+
- [API](#api)
|
|
27
|
+
|
|
28
|
+
## [Demo (click for details)](./example/README.md)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
| iOS 17 | Android 14 |
|
|
32
|
+
|:--------------------------------------:|:------------------------------------------:|
|
|
33
|
+
|  |  |
|
|
34
|
+
|
|
35
|
+
On iOS, `readCalendar` permission is not needed when you are creating an event using the native prompt.
|
|
36
|
+
The video is just for showing the functionality, otherwise the `createEventWithPrompt` method works without the `readCalendar` authorization.
|
|
37
|
+
|
|
38
|
+
## Upcoming Features
|
|
39
|
+
|
|
40
|
+
- [ ] Create calendar events without native prompts
|
|
41
|
+
- [ ] Create reminders (iOS)
|
|
42
|
+
- [ ] Find calendar events
|
|
43
|
+
- [ ] Delete calendar events
|
|
44
|
+
|
|
45
|
+
## Support Range
|
|
46
|
+
|
|
47
|
+
| Platform | range |
|
|
48
|
+
|:----------:|:------------------------------------:|
|
|
49
|
+
| iOS | ≥ 13 |
|
|
50
|
+
| Android | ≥ 4 (SDK 14 – Ice Cream Sandwich) |
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install @ebarooni/capacitor-calendar
|
|
56
|
+
npx cap sync
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Permissions
|
|
60
|
+
|
|
61
|
+
To be able to use the plugin, you will need to add the required permissions to your app. The required platform-specific
|
|
62
|
+
permissions can be found below:
|
|
63
|
+
|
|
64
|
+
* [iOS](./ios/PERMISSIONS.md)
|
|
65
|
+
* [Android](./android/PERMISSIONS.md)
|
|
66
|
+
|
|
67
|
+
## API
|
|
68
|
+
|
|
69
|
+
<docgen-index>
|
|
70
|
+
|
|
71
|
+
* [`checkPermission(...)`](#checkpermission)
|
|
72
|
+
* [`checkAllPermissions()`](#checkallpermissions)
|
|
73
|
+
* [`requestPermission(...)`](#requestpermission)
|
|
74
|
+
* [`requestAllPermissions()`](#requestallpermissions)
|
|
75
|
+
* [`createEventWithPrompt()`](#createeventwithprompt)
|
|
76
|
+
* [Interfaces](#interfaces)
|
|
77
|
+
* [Type Aliases](#type-aliases)
|
|
78
|
+
* [Enums](#enums)
|
|
79
|
+
|
|
80
|
+
</docgen-index>
|
|
81
|
+
|
|
82
|
+
<docgen-api>
|
|
83
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
84
|
+
|
|
85
|
+
### checkPermission(...)
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
checkPermission(options: { alias: keyof CalendarPermissionStatus; }) => Promise<{ result: PermissionState; }>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Checks the current authorization status of a specific permission.
|
|
92
|
+
|
|
93
|
+
| Param | Type | Description |
|
|
94
|
+
| ------------- | --------------------------------------- | ----------------------------------------- |
|
|
95
|
+
| **`options`** | <code>{ alias: 'readCalendar'; }</code> | An object with the name of the permission |
|
|
96
|
+
|
|
97
|
+
**Returns:** <code>Promise<{ result: <a href="#permissionstate">PermissionState</a>; }></code>
|
|
98
|
+
|
|
99
|
+
--------------------
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### checkAllPermissions()
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
checkAllPermissions() => Promise<CalendarPermissionStatus>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Checks the current authorization status of all the required permissions for the plugin.
|
|
109
|
+
|
|
110
|
+
**Returns:** <code>Promise<<a href="#calendarpermissionstatus">CalendarPermissionStatus</a>></code>
|
|
111
|
+
|
|
112
|
+
--------------------
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### requestPermission(...)
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
requestPermission(options: { alias: keyof CalendarPermissionStatus; }) => Promise<{ result: PermissionState; }>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Requests authorization to a specific permission, if not already granted.
|
|
122
|
+
If the permission is already granted, it will directly return the status.
|
|
123
|
+
|
|
124
|
+
| Param | Type | Description |
|
|
125
|
+
| ------------- | --------------------------------------- | ----------------------------------------- |
|
|
126
|
+
| **`options`** | <code>{ alias: 'readCalendar'; }</code> | An object with the name of the permission |
|
|
127
|
+
|
|
128
|
+
**Returns:** <code>Promise<{ result: <a href="#permissionstate">PermissionState</a>; }></code>
|
|
129
|
+
|
|
130
|
+
--------------------
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### requestAllPermissions()
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
requestAllPermissions() => Promise<CalendarPermissionStatus>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Requests authorization to all the required permissions for the plugin, if they have not already been granted.
|
|
140
|
+
|
|
141
|
+
**Returns:** <code>Promise<<a href="#calendarpermissionstatus">CalendarPermissionStatus</a>></code>
|
|
142
|
+
|
|
143
|
+
--------------------
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### createEventWithPrompt()
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
createEventWithPrompt() => Promise<{ result: CalendarEventActionResult; }>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Creates an event in the calendar by using the native calendar.
|
|
153
|
+
On iOS opens a native sheet and on Android opens an intent.
|
|
154
|
+
This method does not need any read or write authorization from the user on iOS. However, the entries in the Info.plist file are still needed.
|
|
155
|
+
On Android, the user has to authorize for read access.
|
|
156
|
+
|
|
157
|
+
**Returns:** <code>Promise<{ result: <a href="#calendareventactionresult">CalendarEventActionResult</a>; }></code>
|
|
158
|
+
|
|
159
|
+
--------------------
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
### Interfaces
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
#### CalendarPermissionStatus
|
|
166
|
+
|
|
167
|
+
Describes the permission status for reading from the calendar.
|
|
168
|
+
|
|
169
|
+
| Prop | Type |
|
|
170
|
+
| ------------------ | ----------------------------------------------------------- |
|
|
171
|
+
| **`readCalendar`** | <code><a href="#permissionstate">PermissionState</a></code> |
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
### Type Aliases
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
#### PermissionState
|
|
178
|
+
|
|
179
|
+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
### Enums
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
#### CalendarEventActionResult
|
|
186
|
+
|
|
187
|
+
| Members | Value |
|
|
188
|
+
| -------------- | ----------------------- |
|
|
189
|
+
| **`Saved`** | <code>'saved'</code> |
|
|
190
|
+
| **`Canceled`** | <code>'canceled'</code> |
|
|
191
|
+
| **`Error`** | <code>'error'</code> |
|
|
192
|
+
|
|
193
|
+
</docgen-api>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
ext {
|
|
10
|
+
kotlin_version = '1.9.22'
|
|
11
|
+
}
|
|
12
|
+
repositories {
|
|
13
|
+
google()
|
|
14
|
+
mavenCentral()
|
|
15
|
+
}
|
|
16
|
+
dependencies {
|
|
17
|
+
classpath 'com.android.tools.build:gradle:8.2.2'
|
|
18
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
apply plugin: 'com.android.library'
|
|
23
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
24
|
+
|
|
25
|
+
android {
|
|
26
|
+
namespace "dev.barooni.capacitor.calendar"
|
|
27
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
28
|
+
defaultConfig {
|
|
29
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
30
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
31
|
+
versionCode 1
|
|
32
|
+
versionName "1.0"
|
|
33
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
34
|
+
}
|
|
35
|
+
buildTypes {
|
|
36
|
+
release {
|
|
37
|
+
minifyEnabled false
|
|
38
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
lintOptions {
|
|
42
|
+
abortOnError false
|
|
43
|
+
}
|
|
44
|
+
compileOptions {
|
|
45
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
46
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
repositories {
|
|
51
|
+
google()
|
|
52
|
+
mavenCentral()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
dependencies {
|
|
57
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
58
|
+
implementation project(':capacitor-android')
|
|
59
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
60
|
+
implementation 'androidx.core:core-ktx:+'
|
|
61
|
+
testImplementation "junit:junit:$junitVersion"
|
|
62
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
63
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
64
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package dev.barooni.capacitor.calendar
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.ContentResolver
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.content.Intent
|
|
7
|
+
import android.provider.CalendarContract
|
|
8
|
+
import androidx.activity.result.ActivityResult
|
|
9
|
+
import com.getcapacitor.JSObject
|
|
10
|
+
import com.getcapacitor.PermissionState
|
|
11
|
+
import com.getcapacitor.Plugin
|
|
12
|
+
import com.getcapacitor.PluginCall
|
|
13
|
+
import com.getcapacitor.PluginMethod
|
|
14
|
+
import com.getcapacitor.annotation.ActivityCallback
|
|
15
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
16
|
+
import com.getcapacitor.annotation.Permission
|
|
17
|
+
import com.getcapacitor.annotation.PermissionCallback
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(
|
|
21
|
+
name = "CapacitorCalendar",
|
|
22
|
+
permissions = [
|
|
23
|
+
Permission(
|
|
24
|
+
alias = "readCalendar",
|
|
25
|
+
strings = [
|
|
26
|
+
Manifest.permission.READ_CALENDAR
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
]
|
|
30
|
+
)
|
|
31
|
+
class CapacitorCalendarPlugin : Plugin() {
|
|
32
|
+
private enum class CalendarEventActionResult(val value: String) {
|
|
33
|
+
SAVED("saved"),
|
|
34
|
+
CANCELED("canceled"),
|
|
35
|
+
ERROR("error")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private var totalNumberOfEvents: Int = 0
|
|
39
|
+
|
|
40
|
+
@PluginMethod
|
|
41
|
+
fun createEventWithPrompt(call: PluginCall) {
|
|
42
|
+
try {
|
|
43
|
+
if (getPermissionState("readCalendar") != PermissionState.GRANTED) {
|
|
44
|
+
throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Missing readCalendar permission")
|
|
45
|
+
} else {
|
|
46
|
+
totalNumberOfEvents = getTotalNumberOfEvents(context)
|
|
47
|
+
openCalendarIntent(call)
|
|
48
|
+
}
|
|
49
|
+
} catch (error: Exception) {
|
|
50
|
+
call.reject(error.message)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@PluginMethod
|
|
56
|
+
fun checkPermission(call: PluginCall) {
|
|
57
|
+
try {
|
|
58
|
+
val permissionName = call.getString("alias")
|
|
59
|
+
?: throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Permission name is not defined")
|
|
60
|
+
val state = getPermissionState(permissionName)
|
|
61
|
+
?: throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Could not determine the status of the requested permission")
|
|
62
|
+
val ret = JSObject()
|
|
63
|
+
ret.put("result", state)
|
|
64
|
+
call.resolve(ret)
|
|
65
|
+
} catch (error: Exception) {
|
|
66
|
+
call.reject(error.message)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@PluginMethod
|
|
72
|
+
fun checkAllPermissions(call: PluginCall) {
|
|
73
|
+
try {
|
|
74
|
+
checkPermissions(call)
|
|
75
|
+
} catch (_: Exception) {
|
|
76
|
+
call.reject("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Could not determine the status of the requested permissions")
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@PluginMethod
|
|
82
|
+
fun requestPermission(call: PluginCall) {
|
|
83
|
+
try {
|
|
84
|
+
val permissionName = call.getString("alias")
|
|
85
|
+
?: throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Permission name is not defined")
|
|
86
|
+
requestPermissionForAlias(
|
|
87
|
+
permissionName,
|
|
88
|
+
call,
|
|
89
|
+
"permissionsCallback"
|
|
90
|
+
)
|
|
91
|
+
} catch (error: Exception) {
|
|
92
|
+
call.reject(error.message)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@PluginMethod
|
|
98
|
+
fun requestAllPermissions(call: PluginCall) {
|
|
99
|
+
try {
|
|
100
|
+
requestPermissions(call)
|
|
101
|
+
} catch (_: Exception) {
|
|
102
|
+
call.reject("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Could not request permissions")
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private fun openCalendarIntent(call: PluginCall) {
|
|
108
|
+
val intent = Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
|
|
109
|
+
startActivityForResult(call, intent, "openCalendarIntentActivityCallback")
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private fun getTotalNumberOfEvents(context: Context): Int {
|
|
113
|
+
val contentResolver: ContentResolver = context.contentResolver
|
|
114
|
+
val uri = CalendarContract.Events.CONTENT_URI
|
|
115
|
+
val projection = arrayOf(CalendarContract.Events._ID)
|
|
116
|
+
val cursor = contentResolver.query(uri, projection, null, null, null)
|
|
117
|
+
return if (cursor == null) {
|
|
118
|
+
0
|
|
119
|
+
} else {
|
|
120
|
+
try {
|
|
121
|
+
cursor.count
|
|
122
|
+
} catch (_: Exception) {
|
|
123
|
+
throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Failed to get the total events count")
|
|
124
|
+
} finally {
|
|
125
|
+
cursor.close()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@ActivityCallback
|
|
131
|
+
private fun openCalendarIntentActivityCallback(call: PluginCall?, result: ActivityResult) {
|
|
132
|
+
if (call == null) {
|
|
133
|
+
throw Exception("[CapacitorCalendar.${Thread.currentThread().stackTrace[1].methodName}] Call is not defined")
|
|
134
|
+
}
|
|
135
|
+
val ret = JSObject()
|
|
136
|
+
val currentEventsCount: Int = getTotalNumberOfEvents(context)
|
|
137
|
+
val action: String = if (currentEventsCount > totalNumberOfEvents) {
|
|
138
|
+
CalendarEventActionResult.SAVED.value
|
|
139
|
+
} else if (totalNumberOfEvents == currentEventsCount) {
|
|
140
|
+
CalendarEventActionResult.CANCELED.value
|
|
141
|
+
} else {
|
|
142
|
+
CalendarEventActionResult.ERROR.value
|
|
143
|
+
}
|
|
144
|
+
ret.put("result", action)
|
|
145
|
+
call.resolve(ret)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@PermissionCallback
|
|
149
|
+
private fun permissionsCallback(call: PluginCall) {
|
|
150
|
+
val permissionName = call.getString("alias")
|
|
151
|
+
try {
|
|
152
|
+
val ret = JSObject()
|
|
153
|
+
ret.put("result", getPermissionState(permissionName))
|
|
154
|
+
call.resolve(ret)
|
|
155
|
+
} catch (_: Exception) {
|
|
156
|
+
throw Exception("${Thread.currentThread().stackTrace[1].methodName} Could not authorize $permissionName")
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "CapacitorCalendarPlugin",
|
|
4
|
+
"slug": "capacitorcalendarplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "checkPermission",
|
|
10
|
+
"signature": "(options: { alias: keyof CalendarPermissionStatus; }) => Promise<{ result: PermissionState; }>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "An object with the name of the permission",
|
|
15
|
+
"type": "{ alias: 'readCalendar'; }"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<{ result: PermissionState; }>",
|
|
19
|
+
"tags": [
|
|
20
|
+
{
|
|
21
|
+
"name": "method"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "param",
|
|
25
|
+
"text": "options An object with the name of the permission"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "returns",
|
|
29
|
+
"text": ";{ result: PermissionState }>} – A promise that resolves with the current status of the requested permission."
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "example",
|
|
33
|
+
"text": "const status = await this.checkPermission({ alias: 'readCalendar' });"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"docs": "Checks the current authorization status of a specific permission.",
|
|
37
|
+
"complexTypes": [
|
|
38
|
+
"PermissionState",
|
|
39
|
+
"CalendarPermissionStatus"
|
|
40
|
+
],
|
|
41
|
+
"slug": "checkpermission"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "checkAllPermissions",
|
|
45
|
+
"signature": "() => Promise<CalendarPermissionStatus>",
|
|
46
|
+
"parameters": [],
|
|
47
|
+
"returns": "Promise<CalendarPermissionStatus>",
|
|
48
|
+
"tags": [
|
|
49
|
+
{
|
|
50
|
+
"name": "method"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "returns",
|
|
54
|
+
"text": ";CalendarPermissionStatus>} – A promise that resolves with an object containing all the permissions and their status."
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "example",
|
|
58
|
+
"text": "const permissionsStatus = await this.checkAllPermissions();"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"docs": "Checks the current authorization status of all the required permissions for the plugin.",
|
|
62
|
+
"complexTypes": [
|
|
63
|
+
"CalendarPermissionStatus"
|
|
64
|
+
],
|
|
65
|
+
"slug": "checkallpermissions"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "requestPermission",
|
|
69
|
+
"signature": "(options: { alias: keyof CalendarPermissionStatus; }) => Promise<{ result: PermissionState; }>",
|
|
70
|
+
"parameters": [
|
|
71
|
+
{
|
|
72
|
+
"name": "options",
|
|
73
|
+
"docs": "An object with the name of the permission",
|
|
74
|
+
"type": "{ alias: 'readCalendar'; }"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"returns": "Promise<{ result: PermissionState; }>",
|
|
78
|
+
"tags": [
|
|
79
|
+
{
|
|
80
|
+
"name": "method"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "param",
|
|
84
|
+
"text": "options An object with the name of the permission"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "returns",
|
|
88
|
+
"text": ";{ result: PermissionState }>} – A promise that resolves with the new permission status after the request is made."
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "example",
|
|
92
|
+
"text": "const result = await this.requestPermission({ alias: 'readCalendar' });"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"docs": "Requests authorization to a specific permission, if not already granted.\nIf the permission is already granted, it will directly return the status.",
|
|
96
|
+
"complexTypes": [
|
|
97
|
+
"PermissionState",
|
|
98
|
+
"CalendarPermissionStatus"
|
|
99
|
+
],
|
|
100
|
+
"slug": "requestpermission"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "requestAllPermissions",
|
|
104
|
+
"signature": "() => Promise<CalendarPermissionStatus>",
|
|
105
|
+
"parameters": [],
|
|
106
|
+
"returns": "Promise<CalendarPermissionStatus>",
|
|
107
|
+
"tags": [
|
|
108
|
+
{
|
|
109
|
+
"name": "method"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "returns",
|
|
113
|
+
"text": ";CalendarPermissionStatus>} – A promise that resolves with the new permission statuses after the request is made."
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "example",
|
|
117
|
+
"text": "const permissionResults = await this.requestAllPermissions();"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"docs": "Requests authorization to all the required permissions for the plugin, if they have not already been granted.",
|
|
121
|
+
"complexTypes": [
|
|
122
|
+
"CalendarPermissionStatus"
|
|
123
|
+
],
|
|
124
|
+
"slug": "requestallpermissions"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "createEventWithPrompt",
|
|
128
|
+
"signature": "() => Promise<{ result: CalendarEventActionResult; }>",
|
|
129
|
+
"parameters": [],
|
|
130
|
+
"returns": "Promise<{ result: CalendarEventActionResult; }>",
|
|
131
|
+
"tags": [
|
|
132
|
+
{
|
|
133
|
+
"name": "method"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "returns",
|
|
137
|
+
"text": ";{ result: CalendarEventActionResult }>} – A promise that resolves with the result of the action."
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"name": "example",
|
|
141
|
+
"text": "let result: CalendarEventActionResult;\nif (capacitor.getPlatform() === 'android') {\n const readCalendarStatus = this.requestPermission({ alias: 'readCalendar' }).result;\n if (readCalendarStatus === 'granted') {\n result = await this.createEventWithPrompt();\n } else {\n // handle the case when user rejects the permission\n }\n} else {\n result = await this.createEventWithPrompt();\n}"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"docs": "Creates an event in the calendar by using the native calendar.\nOn iOS opens a native sheet and on Android opens an intent.\nThis method does not need any read or write authorization from the user on iOS. However, the entries in the Info.plist file are still needed.\nOn Android, the user has to authorize for read access.",
|
|
145
|
+
"complexTypes": [
|
|
146
|
+
"CalendarEventActionResult"
|
|
147
|
+
],
|
|
148
|
+
"slug": "createeventwithprompt"
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"properties": []
|
|
152
|
+
},
|
|
153
|
+
"interfaces": [
|
|
154
|
+
{
|
|
155
|
+
"name": "CalendarPermissionStatus",
|
|
156
|
+
"slug": "calendarpermissionstatus",
|
|
157
|
+
"docs": "Describes the permission status for reading from the calendar.",
|
|
158
|
+
"tags": [
|
|
159
|
+
{
|
|
160
|
+
"name": "interface"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"methods": [],
|
|
164
|
+
"properties": [
|
|
165
|
+
{
|
|
166
|
+
"name": "readCalendar",
|
|
167
|
+
"tags": [],
|
|
168
|
+
"docs": "",
|
|
169
|
+
"complexTypes": [
|
|
170
|
+
"PermissionState"
|
|
171
|
+
],
|
|
172
|
+
"type": "PermissionState"
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"enums": [
|
|
178
|
+
{
|
|
179
|
+
"name": "CalendarEventActionResult",
|
|
180
|
+
"slug": "calendareventactionresult",
|
|
181
|
+
"members": [
|
|
182
|
+
{
|
|
183
|
+
"name": "Saved",
|
|
184
|
+
"value": "'saved'",
|
|
185
|
+
"tags": [],
|
|
186
|
+
"docs": ""
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"name": "Canceled",
|
|
190
|
+
"value": "'canceled'",
|
|
191
|
+
"tags": [],
|
|
192
|
+
"docs": ""
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "Error",
|
|
196
|
+
"value": "'error'",
|
|
197
|
+
"tags": [],
|
|
198
|
+
"docs": ""
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"typeAliases": [
|
|
204
|
+
{
|
|
205
|
+
"name": "PermissionState",
|
|
206
|
+
"slug": "permissionstate",
|
|
207
|
+
"docs": "",
|
|
208
|
+
"types": [
|
|
209
|
+
{
|
|
210
|
+
"text": "'prompt'",
|
|
211
|
+
"complexTypes": []
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"text": "'prompt-with-rationale'",
|
|
215
|
+
"complexTypes": []
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"text": "'granted'",
|
|
219
|
+
"complexTypes": []
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"text": "'denied'",
|
|
223
|
+
"complexTypes": []
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"pluginConfigs": []
|
|
229
|
+
}
|