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:
215
README.md
215
README.md
@@ -1,143 +1,146 @@
|
||||
# Daily Notification Plugin for Capacitor
|
||||
# Daily Notification Plugin
|
||||
|
||||
A Capacitor plugin for scheduling and managing daily notifications with advanced features and robust error handling.
|
||||
A Capacitor plugin for scheduling and managing daily notifications on Android devices.
|
||||
|
||||
## Features
|
||||
|
||||
- Schedule daily notifications with custom time and content
|
||||
- Support for different priority levels
|
||||
- Timezone-aware scheduling
|
||||
- Offline support with caching
|
||||
- Comprehensive permission handling
|
||||
- Automatic retry logic
|
||||
- Detailed notification status tracking
|
||||
- Configurable settings management
|
||||
- Schedule daily notifications with precise timing
|
||||
- Handle system state changes (battery, power, etc.)
|
||||
- Support for adaptive scheduling based on device state
|
||||
- Background task management
|
||||
- Battery optimization support
|
||||
- Rich logging system
|
||||
- Comprehensive error handling
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install daily-notification-plugin
|
||||
npx cap sync
|
||||
npm install @timesafari/daily-notification-plugin
|
||||
```
|
||||
|
||||
## iOS Setup
|
||||
|
||||
No additional setup required for iOS. The plugin automatically handles all necessary configurations.
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```typescript
|
||||
import { DailyNotification } from 'daily-notification-plugin';
|
||||
import { DailyNotification } from '@timesafari/daily-notification-plugin';
|
||||
|
||||
// Initialize the plugin
|
||||
const dailyNotification = new DailyNotification();
|
||||
|
||||
// Schedule a daily notification
|
||||
await DailyNotification.scheduleDailyNotification({
|
||||
url: 'https://api.example.com/updates',
|
||||
time: '09:00',
|
||||
title: 'Daily Update',
|
||||
body: 'Your daily update is ready'
|
||||
await dailyNotification.scheduleDailyNotification({
|
||||
sound: true,
|
||||
priority: 'default',
|
||||
timezone: 'UTC'
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Features
|
||||
// Get notification status
|
||||
const status = await dailyNotification.getNotificationStatus();
|
||||
|
||||
#### Custom Priority
|
||||
|
||||
```typescript
|
||||
await DailyNotification.scheduleDailyNotification({
|
||||
url: 'https://api.example.com/updates',
|
||||
time: '09:00',
|
||||
// Update settings
|
||||
await dailyNotification.updateSettings({
|
||||
sound: false,
|
||||
priority: 'high'
|
||||
});
|
||||
|
||||
// Cancel all notifications
|
||||
await dailyNotification.cancelAllNotifications();
|
||||
|
||||
// Get battery status
|
||||
const batteryStatus = await dailyNotification.getBatteryStatus();
|
||||
|
||||
// Request battery optimization exemption
|
||||
await dailyNotification.requestBatteryOptimizationExemption();
|
||||
```
|
||||
|
||||
#### Timezone Support
|
||||
## Configuration
|
||||
|
||||
```typescript
|
||||
await DailyNotification.scheduleDailyNotification({
|
||||
url: 'https://api.example.com/updates',
|
||||
time: '09:00',
|
||||
timezone: 'America/New_York'
|
||||
});
|
||||
### Android
|
||||
|
||||
Add the following permissions to your `AndroidManifest.xml`:
|
||||
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
```
|
||||
|
||||
#### Check Notification Status
|
||||
## Development
|
||||
|
||||
```typescript
|
||||
const status = await DailyNotification.getNotificationStatus();
|
||||
console.log('Notification status:', status);
|
||||
### Prerequisites
|
||||
|
||||
- Node.js 14 or later
|
||||
- Android Studio
|
||||
- Android SDK
|
||||
- Gradle
|
||||
|
||||
### Building
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Build the plugin
|
||||
npm run build
|
||||
|
||||
# Run tests
|
||||
npm test
|
||||
```
|
||||
|
||||
#### Update Settings
|
||||
### Project Structure
|
||||
|
||||
```typescript
|
||||
await DailyNotification.updateSettings({
|
||||
sound: true,
|
||||
priority: 'high',
|
||||
timezone: 'America/Los_Angeles'
|
||||
});
|
||||
```
|
||||
|
||||
## API Documentation
|
||||
|
||||
### Methods
|
||||
|
||||
#### scheduleDailyNotification(options: ScheduleOptions)
|
||||
Schedule a new daily notification.
|
||||
|
||||
#### getLastNotification()
|
||||
Get information about the last delivered notification.
|
||||
|
||||
#### cancelAllNotifications()
|
||||
Cancel all pending notifications.
|
||||
|
||||
#### getNotificationStatus()
|
||||
Get current notification status and settings.
|
||||
|
||||
#### updateSettings(settings: NotificationSettings)
|
||||
Update notification settings.
|
||||
|
||||
#### checkPermissions()
|
||||
Check current notification permissions.
|
||||
|
||||
#### requestPermissions()
|
||||
Request notification permissions.
|
||||
|
||||
### Types
|
||||
|
||||
```typescript
|
||||
interface ScheduleOptions {
|
||||
url: string;
|
||||
time: string;
|
||||
title?: string;
|
||||
body?: string;
|
||||
sound?: boolean;
|
||||
priority?: 'high' | 'default' | 'low';
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
interface NotificationSettings {
|
||||
sound?: boolean;
|
||||
priority?: string;
|
||||
timezone?: string;
|
||||
}
|
||||
daily-notification-plugin/
|
||||
├── android/ # Android implementation
|
||||
│ ├── app/ # Main application module
|
||||
│ └── build.gradle # Root build configuration
|
||||
├── src/ # TypeScript source
|
||||
├── tests/ # Test files
|
||||
├── package.json # Package configuration
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
The plugin provides detailed error messages for various scenarios:
|
||||
- Invalid parameters
|
||||
- Permission issues
|
||||
- Scheduling failures
|
||||
- Invalid time formats
|
||||
- Invalid timezone identifiers
|
||||
- Invalid priority values
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
|
||||
1. Fork the repository
|
||||
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
||||
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
||||
4. Push to the branch (`git push origin feature/amazing-feature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see LICENSE file for details
|
||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
||||
|
||||
## Author
|
||||
|
||||
Matthew Raymer
|
||||
|
||||
## Security
|
||||
|
||||
This plugin follows security best practices:
|
||||
|
||||
- Uses AndroidX for modern security features
|
||||
- Implements proper permission handling
|
||||
- Follows Android security guidelines
|
||||
- Uses secure storage for sensitive data
|
||||
- Implements proper error handling
|
||||
- Logs security-relevant events
|
||||
- Uses secure communication channels
|
||||
- Implements proper access control
|
||||
- Follows Android's security model
|
||||
- Uses secure defaults
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.0.0
|
||||
- Initial release
|
||||
- Basic notification scheduling
|
||||
- System state handling
|
||||
- Battery optimization support
|
||||
- Background task management
|
||||
- Rich logging system
|
||||
|
||||
Reference in New Issue
Block a user