Initial commit
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
dist/
|
||||
node_modules/
|
||||
.DS_Store
|
||||
Pods/
|
||||
*.iml
|
||||
.idea/
|
||||
.vscode/
|
||||
build/
|
||||
*.tgz
|
||||
45
package.json
Normal file
45
package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/definitions.ts
Normal file
19
src/definitions.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export interface DailyNotificationPlugin {
|
||||
initialize(options: DailyNotificationOptions): Promise<void>;
|
||||
checkPermissions(): Promise<PermissionStatus>;
|
||||
requestPermissions(): Promise<PermissionStatus>;
|
||||
}
|
||||
|
||||
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';
|
||||
10
src/index.ts
Normal file
10
src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { registerPlugin } from '@capacitor/core';
|
||||
|
||||
import type { DailyNotificationPlugin } from './definitions';
|
||||
|
||||
const DailyNotification = registerPlugin<DailyNotificationPlugin>('DailyNotification', {
|
||||
web: () => import('./web').then(m => new m.DailyNotificationWeb()),
|
||||
});
|
||||
|
||||
export * from './definitions';
|
||||
export { DailyNotification };
|
||||
45
src/web.ts
Normal file
45
src/web.ts
Normal file
@@ -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<void> {
|
||||
console.warn('DailyNotification.initialize() is not implemented on web');
|
||||
return;
|
||||
}
|
||||
|
||||
async checkPermissions(): Promise<PermissionStatus> {
|
||||
if ('Notification' in window) {
|
||||
const status = await Notification.permission;
|
||||
return {
|
||||
notifications: this.mapWebPermission(status),
|
||||
};
|
||||
}
|
||||
return {
|
||||
notifications: 'denied',
|
||||
};
|
||||
}
|
||||
|
||||
async requestPermissions(): Promise<PermissionStatus> {
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
0
tsconfig.json
Normal file
0
tsconfig.json
Normal file
Reference in New Issue
Block a user