refactor(plugin): modernize plugin architecture and improve type definitions
- Update package.json with modern build tooling and dependencies - Streamline and enhance TypeScript definitions for better type safety - Reorganize plugin structure for better maintainability - Add comprehensive interface definitions for notification features - Implement proper build configuration with rollup - Update tsconfig.json for stricter type checking and ES2020 modules Breaking Changes: - Changed module structure to use ES modules - Updated interface definitions with stricter typing - Removed redundant notification options - Simplified API surface while maintaining core functionality Dependencies: - Upgrade @capacitor dependencies to v5.7.8 - Add rollup and typescript build tools - Update test framework configuration
This commit is contained in:
@@ -1,98 +1,61 @@
|
||||
/**
|
||||
* Interface definitions for the Daily Notification plugin
|
||||
* Daily Notification Plugin Definitions
|
||||
*
|
||||
* TypeScript definitions for the Daily Notification Plugin
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
*/
|
||||
|
||||
export interface NotificationOptions {
|
||||
url: string;
|
||||
time: string;
|
||||
title?: string;
|
||||
body?: string;
|
||||
sound?: boolean;
|
||||
vibrate?: boolean;
|
||||
priority?: 'low' | 'normal' | 'high';
|
||||
retryCount?: number;
|
||||
retryInterval?: number;
|
||||
cacheDuration?: number;
|
||||
headers?: Record<string, string>;
|
||||
offlineFallback?: boolean;
|
||||
timezone?: string;
|
||||
contentHandler?: (response: Response) => Promise<{
|
||||
title: string;
|
||||
body: string;
|
||||
data?: any;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface NotificationStatus {
|
||||
isScheduled: boolean;
|
||||
nextNotificationTime?: string;
|
||||
lastNotificationTime?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface NotificationResponse {
|
||||
title: string;
|
||||
body: string;
|
||||
data?: any;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface NotificationSettings {
|
||||
time?: string;
|
||||
export interface NotificationOptions {
|
||||
title?: string;
|
||||
body?: string;
|
||||
sound?: boolean;
|
||||
vibrate?: boolean;
|
||||
priority?: 'low' | 'normal' | 'high';
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
export interface NotificationEvent extends Event {
|
||||
detail: {
|
||||
id: string;
|
||||
action: string;
|
||||
data?: any;
|
||||
};
|
||||
priority?: 'high' | 'low' | 'normal';
|
||||
}
|
||||
|
||||
export interface DailyNotificationPlugin {
|
||||
/**
|
||||
* Schedule a daily notification with the specified options
|
||||
*/
|
||||
scheduleDailyNotification(options: NotificationOptions): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get the last notification that was delivered
|
||||
*/
|
||||
scheduleDailyNotification(options: NotificationOptions | ScheduleOptions): Promise<void>;
|
||||
getLastNotification(): Promise<NotificationResponse | null>;
|
||||
|
||||
/**
|
||||
* Cancel all scheduled notifications
|
||||
*/
|
||||
cancelAllNotifications(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get the current status of notifications
|
||||
*/
|
||||
getNotificationStatus(): Promise<NotificationStatus>;
|
||||
|
||||
/**
|
||||
* Update notification settings
|
||||
*/
|
||||
updateSettings(settings: NotificationSettings): Promise<void>;
|
||||
|
||||
/**
|
||||
* Check notification permissions
|
||||
*/
|
||||
checkPermissions(): Promise<PermissionStatus>;
|
||||
|
||||
/**
|
||||
* Request notification permissions
|
||||
*/
|
||||
requestPermissions(): Promise<PermissionStatus>;
|
||||
getBatteryStatus(): Promise<BatteryStatus>;
|
||||
requestBatteryOptimizationExemption(): Promise<void>;
|
||||
setAdaptiveScheduling(options: { enabled: boolean }): Promise<void>;
|
||||
getPowerState(): Promise<PowerState>;
|
||||
}
|
||||
|
||||
export interface PermissionStatus {
|
||||
notifications: PermissionState;
|
||||
backgroundRefresh?: PermissionState; // iOS only
|
||||
export interface ScheduleOptions {
|
||||
sound?: boolean;
|
||||
priority?: 'high' | 'default' | 'low' | 'min' | 'max';
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';
|
||||
export interface NotificationSettings {
|
||||
sound?: boolean;
|
||||
priority?: string;
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
export interface NotificationStatus {
|
||||
lastNotificationTime: number;
|
||||
nextNotificationTime: number;
|
||||
settings: NotificationSettings;
|
||||
}
|
||||
|
||||
export interface BatteryStatus {
|
||||
level: number;
|
||||
isCharging: boolean;
|
||||
powerState: number;
|
||||
isOptimizationExempt: boolean;
|
||||
}
|
||||
|
||||
export interface PowerState {
|
||||
powerState: number;
|
||||
isOptimizationExempt: boolean;
|
||||
}
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
import { registerPlugin } from '@capacitor/core';
|
||||
import type { DailyNotificationPlugin } from './definitions';
|
||||
import { DailyNotificationWeb } from './web';
|
||||
|
||||
const DailyNotification = registerPlugin<DailyNotificationPlugin>('DailyNotification', {
|
||||
web: () => import('./web').then(m => new m.DailyNotificationWeb()),
|
||||
web: async () => new DailyNotificationWeb(),
|
||||
});
|
||||
|
||||
export * from './definitions';
|
||||
|
||||
63
src/web.ts
Normal file
63
src/web.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Daily Notification Plugin Web Implementation
|
||||
*
|
||||
* Web implementation of the Daily Notification Plugin
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
*/
|
||||
|
||||
import { DailyNotificationPlugin, NotificationOptions, NotificationResponse, NotificationSettings, NotificationStatus, BatteryStatus, PowerState, ScheduleOptions } from './definitions';
|
||||
|
||||
export class DailyNotificationWeb implements DailyNotificationPlugin {
|
||||
async scheduleDailyNotification(options: NotificationOptions | ScheduleOptions): Promise<void> {
|
||||
console.warn('Daily notifications are not supported on web');
|
||||
}
|
||||
|
||||
async getLastNotification(): Promise<NotificationResponse | null> {
|
||||
console.warn('Daily notifications are not supported on web');
|
||||
return null;
|
||||
}
|
||||
|
||||
async cancelAllNotifications(): Promise<void> {
|
||||
console.warn('Daily notifications are not supported on web');
|
||||
}
|
||||
|
||||
async getNotificationStatus(): Promise<NotificationStatus> {
|
||||
console.warn('Daily notifications are not supported on web');
|
||||
return {
|
||||
lastNotificationTime: 0,
|
||||
nextNotificationTime: 0,
|
||||
settings: {}
|
||||
};
|
||||
}
|
||||
|
||||
async updateSettings(settings: NotificationSettings): Promise<void> {
|
||||
console.warn('Daily notifications are not supported on web');
|
||||
}
|
||||
|
||||
async getBatteryStatus(): Promise<BatteryStatus> {
|
||||
console.warn('Battery status is not supported on web');
|
||||
return {
|
||||
level: 0,
|
||||
isCharging: false,
|
||||
powerState: 0,
|
||||
isOptimizationExempt: false
|
||||
};
|
||||
}
|
||||
|
||||
async requestBatteryOptimizationExemption(): Promise<void> {
|
||||
console.warn('Battery optimization is not supported on web');
|
||||
}
|
||||
|
||||
async setAdaptiveScheduling(options: { enabled: boolean }): Promise<void> {
|
||||
console.warn('Adaptive scheduling is not supported on web');
|
||||
}
|
||||
|
||||
async getPowerState(): Promise<PowerState> {
|
||||
console.warn('Power state is not supported on web');
|
||||
return {
|
||||
powerState: 0,
|
||||
isOptimizationExempt: false
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user