feat(phase3): implement Background Enhancement & TimeSafari Coordination
- Enhanced Android DailyNotificationScheduler with comprehensive TimeSafari coordination - Implemented app lifecycle handling for TimeSafari PlatformServiceMixin integration - Enhanced Android DailyNotificationPlugin with coordinateBackgroundTasks and lifecycle events - Enhanced Android DailyNotificationFetchWorker with WorkManager coordination constraints - Enhanced Web platform with visibility change and window lifecycle coordination - Added comprehensive Phase 3 TypeScript interfaces and type definitions - Implemented background execution constraints and coordination reporting - Added app foreground/background detection with activeDid change coordination - Enhanced state synchronization between plugin and TimeSafari host - Implemented notification throttling and coordination pause/resume mechanisms Phase 3 delivers: ✅ Android WorkManager coordination with PlatformServiceMixin ✅ Android app lifecycle event handling (background/foreground/resumed/paused) ✅ Android background task coordination with constraints (low power mode, activeDid changes) ✅ Web platform visibility and window lifecycle coordination ✅ Web sessionStorage-based coordination state persistence ✅ Comprehensive Phase 3 TypeScript interfaces (EnhancedDailyNotificationPlugin, CoordinationStatus, etc.) ✅ Background execution constraint validation ✅ Cross-platform TimeSafari state synchronization ✅ Coordination reporting and debugging capabilities ✅ App lifecycle-aware activeDid change detection and recovery Ready for Phase 4: Advanced Features & TimeSafari Integration
This commit is contained in:
@@ -550,4 +550,140 @@ export interface ActiveDidChangeEvent {
|
||||
activeDid: string;
|
||||
timestamp: number;
|
||||
source: 'host' | 'plugin';
|
||||
};
|
||||
};
|
||||
|
||||
// MARK: - Phase 3: TimeSafari Background Coordination Interfaces
|
||||
|
||||
/**
|
||||
* Phase 3: Extended DailyNotificationPlugin interface with TimeSafari coordination
|
||||
*/
|
||||
export interface EnhancedDailyNotificationPlugin extends DailyNotificationPlugin {
|
||||
// Phase 1: ActiveDid Management (already extended in parent)
|
||||
|
||||
// Phase 3: TimeSafari Background Coordination
|
||||
coordinateBackgroundTasks(): Promise<void>;
|
||||
handleAppLifecycleEvent(event: AppLifecycleEvent): Promise<void>;
|
||||
getCoordinationStatus(): Promise<CoordinationStatus>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: App lifecycle events for TimeSafari coordination
|
||||
*/
|
||||
export type AppLifecycleEvent =
|
||||
| 'app_background'
|
||||
| 'app_foreground'
|
||||
| 'app_resumed'
|
||||
| 'app_paused'
|
||||
| 'app_visibility_change'
|
||||
| 'app_hidden'
|
||||
| 'app_visible'
|
||||
| 'app_blur'
|
||||
| 'app_focus';
|
||||
|
||||
/**
|
||||
* Phase 3: Coordination status for debugging and monitoring
|
||||
*/
|
||||
export interface CoordinationStatus {
|
||||
platform: 'android' | 'ios' | 'web' | 'electron';
|
||||
coordinationActive: boolean;
|
||||
coordinationPaused: boolean;
|
||||
autoSync?: boolean;
|
||||
appBackgrounded?: boolean;
|
||||
appHidden?: boolean;
|
||||
visibilityState?: DocumentVisibilityState;
|
||||
focused?: boolean;
|
||||
lastActiveDidChange?: number;
|
||||
lastCoordinationTimestamp?: number;
|
||||
lastAppBackgrounded?: number;
|
||||
lastAppForegrounded?: number;
|
||||
lastCoordinationSuccess?: number;
|
||||
lastCoordinationFailure?: number;
|
||||
coordinationErrors?: string[];
|
||||
activeDidTracking?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: PlatformServiceMixin coordination configuration
|
||||
*/
|
||||
export interface PlatformServiceMixinConfig {
|
||||
enableAutoCoordination?: boolean;
|
||||
coordinationTimeout?: number; // Max time for coordination attempts
|
||||
enableLifecycleEvents?: boolean;
|
||||
enableBackgroundSync?: boolean;
|
||||
enableStatePersistence?: boolean;
|
||||
coordinationGracePeriod?: number; // Grace period for coordination
|
||||
eventHandlers?: {
|
||||
[K in AppLifecycleEvent]?: () => Promise<void>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: WorkManager coordination data
|
||||
*/
|
||||
export interface WorkManagerCoordinationData {
|
||||
timesafariCoordination: boolean;
|
||||
coordinationTimestamp: number;
|
||||
activeDidTracking: string;
|
||||
platformCoordinationVersion?: number;
|
||||
coordinationTimeouts?: {
|
||||
maxCoordinationAge: number;
|
||||
maxExecutionTime: number;
|
||||
maxRetryAge: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: Background execution constraints
|
||||
*/
|
||||
export interface BackgroundExecutionConstraints {
|
||||
devicePowerMode?: 'normal' | 'low_power' | 'critical';
|
||||
appForegroundState?: 'foreground' | 'background' | 'inactive';
|
||||
activeDidStability?: 'stable' | 'changing' | 'unknown';
|
||||
coordinationFreshness?: 'fresh' | 'stale' | 'expired';
|
||||
networkAvailability?: 'cellular' | 'wifi' | 'offline';
|
||||
batteryLevel?: 'high' | 'medium' | 'low' | 'critical';
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: Coordination report
|
||||
*/
|
||||
export interface CoordinationReport {
|
||||
success: boolean;
|
||||
operation: string;
|
||||
duration: number;
|
||||
constraints: BackgroundExecutionConstraints;
|
||||
errors?: string[];
|
||||
timestamp: number;
|
||||
activeDid?: string;
|
||||
authUsed: boolean;
|
||||
platformSpecific?: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 3: TimeSafari state synchronization data
|
||||
*/
|
||||
export interface TimeSafariSyncData {
|
||||
authenticationState: {
|
||||
activeDid: string;
|
||||
jwtExpiration?: number;
|
||||
tokenRefreshNeeded: boolean;
|
||||
};
|
||||
notificationState: {
|
||||
lastDelivery: number;
|
||||
lastDeliveryId?: string;
|
||||
pendingDeliveries: string[];
|
||||
};
|
||||
backgroundTaskState: {
|
||||
lastBackgroundExecution: number;
|
||||
lastCoordinationSuccess: number;
|
||||
pendingCoordinationTasks: string[];
|
||||
};
|
||||
activeDidHistory: {
|
||||
changes: Array<{
|
||||
did: string;
|
||||
timestamp: number;
|
||||
source: string;
|
||||
}>;
|
||||
pendingUpdates: string[];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user