Skip to content

Commit

Permalink
refactor(types): breakdown definitions file (#164)
Browse files Browse the repository at this point in the history
Add reminders access interface.
  • Loading branch information
ebarooni committed Feb 4, 2025
1 parent b9cdf97 commit aebab04
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import type { CalendarSource } from "./schemas/interfaces/calendar-source";
import { EventSpan } from "./schemas/enums/event-span";
import type { Reminder } from "./schemas/interfaces/reminder";
import type { ReminderRecurrenceRule } from "./schemas/interfaces/reminder-recurrence-rule";
import { RemindersAccess } from "./sub-definitions/reminders-access";
import type { RemindersList } from "./schemas/interfaces/reminders-list";

export interface CapacitorCalendarPlugin extends CalendarAccess {
export interface CapacitorCalendarPlugin
extends CalendarAccess,
RemindersAccess {
/**
* Creates an event in the calendar by using the native calendar.
* On iOS opens a native sheet and on Android opens an intent.
Expand Down
45 changes: 28 additions & 17 deletions src/sub-definitions/calendar-access.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { CalendarPermissionScope } from "../schemas/enums/calendar-permission-scope";
import { PermissionState } from "@capacitor/core";
import { PluginPermission } from "../schemas/enums/plugin-permission";

/**
* @since 7.1.0
*/
export interface CalendarAccess {
/**
* Retrieves the current permission status for a given permission alias.
* Retrieves the current permission state for a given permission scope.
*
* @since 0.1.0
* @platform Android, iOS
*
* @example
* CapacitorCalendar.checkPermission({ alias: 'readCalendar' });
* CapacitorCalendar.checkPermission({ scope: CalendarPermissionScope.READ_CALENDAR });
*/
checkPermission(options: {
alias: PluginPermission;
scope: CalendarPermissionScope;
}): Promise<{ result: PermissionState }>;

/**
* Retrieves the current status of all permissions.
* Retrieves the current state of all permissions.
*
* @since 0.1.0
* @platform Android, iOS
*/
checkAllPermissions(): Promise<{ result: CheckAllPermissionsResult }>;

/**
* Requests permission for a given permission alias.
* Requests permission for a given permission scope.
*
* @since 0.1.0
* @platform Android, iOS
*
* @example
* this.requestPermission({ alias: 'readCalendar' });
* this.requestPermission({ scope: CalendarPermissionScope.READ_CALENDAR });
*/
requestPermission(options: {
alias: PluginPermission;
scope: CalendarPermissionScope;
}): Promise<{ result: PermissionState }>;

/**
Expand All @@ -49,6 +52,12 @@ export interface CalendarAccess {
*
* @since 5.4.0
* @platform Android, iOS
* @permissions
* | Platform | Required |
* |-----------|---------------------|
* | iOS 17+ | `NSCalendarsWriteOnlyAccessUsageDescription` |
* | iOS 13-16 | `NSCalendarsUsageDescription` |
* | Android | `android.permission.WRITE_CALENDAR` |
*/
requestWriteOnlyCalendarAccess(): Promise<{ result: PermissionState }>;

Expand All @@ -57,6 +66,10 @@ export interface CalendarAccess {
*
* @since 5.4.0
* @platform Android
* @permissions
* | Platform | Required |
* |-----------|---------------------|
* | Android | `android.permission.READ_CALENDAR` |
*/
requestReadOnlyCalendarAccess(): Promise<{ result: PermissionState }>;

Expand All @@ -65,24 +78,22 @@ export interface CalendarAccess {
*
* @since 5.4.0
* @platform Android, iOS
* @permissions
* | Platform | Required |
* |-----------|---------------------|
* | iOS 17+ | `NSCalendarsFullAccessUsageDescription` |
* | iOS 13-16 | `NSCalendarsUsageDescription` |
* | Android | `android.permission.READ_CALENDAR` & `android.permission.WRITE_CALENDAR` |
*/
requestFullCalendarAccess(): Promise<{ result: PermissionState }>;

/**
* Requests read and write access to the reminders.
*
* @since 5.4.0
* @platform iOS
*/
requestFullRemindersAccess(): Promise<{ result: PermissionState }>;
}

/**
* @since 7.1.0
* @platform Android, iOS
*/
export type CheckAllPermissionsResult = Record<
PluginPermission,
CalendarPermissionScope,
PermissionState
>;

Expand Down
20 changes: 20 additions & 0 deletions src/sub-definitions/reminders-access.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PermissionState } from "@capacitor/core";

/**
* @since 7.1.0
*/
export interface RemindersAccess {
/**
* Requests read and write access to the reminders.
*
* @since 5.4.0
* @platform iOS
* @see {@link CalendarPermissionScope}
* @permissions
* | Platform | Required |
* |-----------|---------------------|
* | iOS 17+ | `NSRemindersFullAccessUsageDescription` |
* | iOS 10-16 | `NSRemindersUsageDescription` |
*/
requestFullRemindersAccess(): Promise<{ result: PermissionState }>;
}

0 comments on commit aebab04

Please sign in to comment.