/** * Sleep Prevention Service * * Cross-platform sleep prevention during long-running operations. * Uses caffeinate on macOS, systemd-inhibit on Linux, and PowerShell on Windows. * * ## Platform Differences * * | Platform | Method | Requirements | Notes | * |----------|--------|--------------|-------| * | macOS | caffeinate | Built-in | Uses -i (idle) and -w (wait for PID) flags | * | Linux | systemd-inhibit | systemd | Falls back to no-op if systemd not available | * | Windows | SetThreadExecutionState | PowerShell | Uses kernel32.dll via P/Invoke | * | Other | No-op | None | Returns false, operation continues normally | * * ## Graceful Degradation * * When sleep prevention is unavailable (unsupported platform, missing tools), * the service returns `false` from `preventSleep()` but operations continue. * This ensures operations work on all platforms, with sleep prevention as * a best-effort enhancement. * * ## Reference Counting * * The service uses reference counting for nested operations. Each `preventSleep()` * call increments the count, each `allowSleep()` decrements it. The actual * sleep prevention only stops when the count reaches zero. * * @example * ```typescript * // Using the wrapper (recommended) * const result = await withSleepPrevention(async () => { * // Long-running operation * return await downloadPlugins(); * }, 'Downloading plugins'); * * // Manual control * const service = getSleepPrevention(); * if (await service.preventSleep('Sync in progress')) { * try { * await performSync(); * } finally { * await service.allowSleep(); * } * } * ``` * * @since v1.23.1 */ export type Platform = 'darwin' | 'linux' | 'win32' | 'unknown'; export interface SleepPreventionService { /** Check if sleep prevention is available on this platform */ isAvailable(): boolean; /** Prevent sleep, returns true if successful */ preventSleep(reason?: string): Promise; /** Allow sleep again */ allowSleep(): Promise; /** Check if currently preventing sleep */ isPreventing(): boolean; /** Get current platform */ getPlatform(): Platform; } /** * Get the sleep prevention service for the current platform */ export declare function getSleepPrevention(): SleepPreventionService; /** * Create a new sleep prevention service (for testing) */ export declare function createSleepPrevention(platform?: Platform): SleepPreventionService; /** * Reset the singleton (for testing) */ export declare function resetSleepPrevention(): void; /** * Wrapper to run an operation with sleep prevention */ export declare function withSleepPrevention(operation: () => Promise, reason?: string): Promise; //# sourceMappingURL=sleep-prevention.d.ts.map