export type BackgroundTaskType = 'fetch' | 'processing'; export interface RegisterOptions { /** * Seconds. On iOS this is `BGTaskRequest.earliestBeginDate` — the OS * treats it as "no earlier than", and may fire much later (or never). * On Android it's the `PeriodicWorkRequest` repeat interval, clamped to * a 15-minute (900s) floor by the platform. */ minimumInterval?: number; requiresNetwork?: boolean; requiresCharging?: boolean; /** * iOS only. `'fetch'` → `BGAppRefreshTask` (lightweight, ~30s budget). * `'processing'` → `BGProcessingTask` (longer budget, can require * charging). Defaults to `'fetch'`. Ignored on Android, where the * `requiresCharging` constraint covers the same use case. */ type?: BackgroundTaskType; } export type BackgroundHandler = () => unknown | Promise; /** * Periodic background tasks via iOS `BGTaskScheduler` and Android * `WorkManager`. * * @example * ```ts * import { Background } from '@sigx/lynx-background'; * * Background.setHandler('refresh-feed', async () => { * const res = await fetch('https://example.com/feed.json'); * await Storage.set('feed', await res.text()); * }); * * await Background.register('refresh-feed', { * minimumInterval: 15 * 60, * requiresNetwork: true, * }); * ``` */ export declare const Background: { /** * Schedule a background task. Idempotent — calling twice with the same * `taskName` updates the existing request rather than creating a * duplicate. Safe to call on every cold start. */ readonly register: (taskName: string, options?: RegisterOptions) => Promise; /** Cancel a previously-registered task. No-op if not registered. */ readonly unregister: (taskName: string) => Promise; /** * Register the JS handler for a task. Must be called BEFORE the first * `register` on every cold start — the OS can fire the task as soon as * the process starts, before any UI is up. Returns an unsubscribe * function that clears the handler (subsequent fires will complete as * no-ops until a new handler is set). */ readonly setHandler: (taskName: string, handler: BackgroundHandler) => () => void; /** * List task identifiers currently persisted by the native side. Useful * for diagnostics ("did the previous app version register tasks I no * longer know about?") and for cleaning up stale registrations: * * ```ts * const known = new Set(['refresh-feed', 'sync-outbox']); * for (const name of await Background.getRegistered()) { * if (!known.has(name)) await Background.unregister(name); * } * ``` */ readonly getRegistered: () => Promise; /** Whether the native module is wired in the current build. */ readonly isAvailable: () => boolean; }; export declare const __resetForTests: () => void; //# sourceMappingURL=background.d.ts.map