Description: - Add battery status and power state monitoring - Implement adaptive scheduling based on battery levels - Add maintenance worker for background tasks - Enhance logging with structured DailyNotificationLogger - Add configuration management with DailyNotificationConfig - Define constants in DailyNotificationConstants - Improve error handling and recovery mechanisms Testing: - Add comprehensive test coverage for battery optimization - Add test coverage for power state management - Add test coverage for maintenance tasks - Add test coverage for configuration management - Add test coverage for constants validation Documentation: - Add comprehensive file-level documentation - Add method-level documentation - Add test documentation - Add configuration documentation This commit improves the iOS implementation's reliability and battery efficiency by adding robust error handling, logging, and configuration management to make the plugin more maintainable and debuggable.
85 lines
3.1 KiB
Swift
85 lines
3.1 KiB
Swift
/**
|
|
* DailyNotificationConfig.swift
|
|
* Daily Notification Plugin for Capacitor
|
|
*
|
|
* Provides configuration options for the notification plugin
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
/// Configuration options for the DailyNotification plugin
|
|
///
|
|
/// This singleton structure provides configurable options that can be modified
|
|
/// to customize the plugin's behavior.
|
|
public struct DailyNotificationConfig {
|
|
/// Shared instance for singleton access
|
|
public static var shared = DailyNotificationConfig()
|
|
|
|
/// Maximum number of notifications that can be scheduled per day
|
|
public var maxNotificationsPerDay = 10
|
|
|
|
/// Default timezone for notifications when none is specified
|
|
public var defaultTimeZone = TimeZone.current
|
|
|
|
/// Whether debug logging is enabled
|
|
public var loggingEnabled = true
|
|
|
|
/// Number of days to retain delivered notifications
|
|
public var retentionDays = 7
|
|
|
|
/// Whether adaptive scheduling is enabled
|
|
public var adaptiveSchedulingEnabled = true
|
|
|
|
/// Battery level thresholds for adaptive scheduling
|
|
public struct BatteryThresholds {
|
|
public static let critical = 15
|
|
public static let low = 30
|
|
public static let medium = 50
|
|
}
|
|
|
|
/// Time intervals for different battery levels (in seconds)
|
|
public struct SchedulingIntervals {
|
|
public static let critical = TimeInterval(4 * 60 * 60) // 4 hours
|
|
public static let low = TimeInterval(2 * 60 * 60) // 2 hours
|
|
public static let medium = TimeInterval(60 * 60) // 1 hour
|
|
public static let normal = TimeInterval(30 * 60) // 30 minutes
|
|
}
|
|
|
|
/// Wake lock duration based on battery level (in seconds)
|
|
public struct WakeLockDurations {
|
|
public static let critical = TimeInterval(30) // 30 seconds
|
|
public static let low = TimeInterval(45) // 45 seconds
|
|
public static let normal = TimeInterval(60) // 1 minute
|
|
}
|
|
|
|
private init() {}
|
|
|
|
/// Resets all configuration options to their default values
|
|
public mutating func resetToDefaults() {
|
|
maxNotificationsPerDay = 10
|
|
defaultTimeZone = TimeZone.current
|
|
loggingEnabled = true
|
|
retentionDays = 7
|
|
adaptiveSchedulingEnabled = true
|
|
}
|
|
|
|
/// Validates and sets the maximum notifications per day
|
|
/// - Parameter value: The new maximum notifications value
|
|
/// - Throws: DailyNotificationError if the value is invalid
|
|
public mutating func setMaxNotificationsPerDay(_ value: Int) throws {
|
|
guard value > 0 else {
|
|
throw DailyNotificationError.invalidParameters("Max notifications per day must be greater than 0")
|
|
}
|
|
maxNotificationsPerDay = value
|
|
}
|
|
|
|
/// Validates and sets the retention days
|
|
/// - Parameter value: The new retention days value
|
|
/// - Throws: DailyNotificationError if the value is invalid
|
|
public mutating func setRetentionDays(_ value: Int) throws {
|
|
guard value > 0 else {
|
|
throw DailyNotificationError.invalidParameters("Retention days must be greater than 0")
|
|
}
|
|
retentionDays = value
|
|
}
|
|
} |