commit e191f8206807b58d7126253d511f002b2252c0ed Author: Matthew Raymer Date: Tue Mar 25 10:21:14 2025 +0000 Initial project setup - Add .gitignore file with standard exclusions - Ignore build artifacts (dist/, build/) - Ignore dependency directories (node_modules/, Pods/) - Ignore system and IDE files (.DS_Store, .idea/, .vscode/) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3371289 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +dist/ +node_modules/ +.DS_Store +Pods/ +*.iml +.idea/ +.vscode/ +build/ +*.tgz diff --git a/package.json b/package.json new file mode 100644 index 0000000..614192d --- /dev/null +++ b/package.json @@ -0,0 +1,45 @@ +{ + "name": "capacitor-daily-notification", + "version": "0.0.1", + "description": "Capacitor plugin for daily notifications with network content", + "main": "dist/plugin.js", + "module": "dist/esm/index.js", + "types": "dist/types/index.d.ts", + "scripts": { + "build": "npm run clean && tsc", + "clean": "rimraf ./dist", + "watch": "tsc --watch", + "prepublishOnly": "npm run build" + }, + "author": "Matthew Raymer", + "license": "MIT", + "dependencies": { + "@capacitor/core": "^5.0.0" + }, + "devDependencies": { + "typescript": "^4.9.0", + "rimraf": "^3.0.2" + }, + "peerDependencies": { + "@capacitor/core": "^5.0.0" + }, + "files": [ + "dist/", + "ios/", + "android/", + "CapacitorDailyNotification.podspec" + ], + "keywords": [ + "capacitor", + "plugin", + "native" + ], + "capacitor": { + "ios": { + "src": "ios" + }, + "android": { + "src": "android" + } + } +} \ No newline at end of file diff --git a/src/definitions.ts b/src/definitions.ts new file mode 100644 index 0000000..a122ea4 --- /dev/null +++ b/src/definitions.ts @@ -0,0 +1,19 @@ +export interface DailyNotificationPlugin { + initialize(options: DailyNotificationOptions): Promise; + checkPermissions(): Promise; + requestPermissions(): Promise; + } + + export interface DailyNotificationOptions { + url: string; + notificationTime: string; // "HH:mm" format + title?: string; + body?: string; + } + + export interface PermissionStatus { + notifications: PermissionState; + backgroundRefresh?: PermissionState; // iOS only + } + + export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..3a62d86 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,10 @@ +import { registerPlugin } from '@capacitor/core'; + +import type { DailyNotificationPlugin } from './definitions'; + +const DailyNotification = registerPlugin('DailyNotification', { + web: () => import('./web').then(m => new m.DailyNotificationWeb()), +}); + +export * from './definitions'; +export { DailyNotification }; diff --git a/src/web.ts b/src/web.ts new file mode 100644 index 0000000..5042ce2 --- /dev/null +++ b/src/web.ts @@ -0,0 +1,45 @@ +import { WebPlugin } from '@capacitor/core'; + +import type { DailyNotificationPlugin, DailyNotificationOptions, PermissionStatus } from './definitions'; + +export class DailyNotificationWeb extends WebPlugin implements DailyNotificationPlugin { + async initialize(options: DailyNotificationOptions): Promise { + console.warn('DailyNotification.initialize() is not implemented on web'); + return; + } + + async checkPermissions(): Promise { + if ('Notification' in window) { + const status = await Notification.permission; + return { + notifications: this.mapWebPermission(status), + }; + } + return { + notifications: 'denied', + }; + } + + async requestPermissions(): Promise { + if ('Notification' in window) { + const status = await Notification.requestPermission(); + return { + notifications: this.mapWebPermission(status), + }; + } + return { + notifications: 'denied', + }; + } + + private mapWebPermission(permission: NotificationPermission): PermissionState { + switch (permission) { + case 'granted': + return 'granted'; + case 'denied': + return 'denied'; + default: + return 'prompt'; + } + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e69de29