import type { PluginListenerHandle } from '@capacitor/core'; /** * Represents the current state and progress of a download task. */ export interface DownloadTask { /** Unique identifier for the download task */ id: string; /** Download progress from 0 to 100 */ progress: number; /** Current state of the download */ state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR'; } /** * Configuration options for starting a download. */ export interface DownloadOptions { /** Unique identifier for this download task */ id: string; /** URL of the file to download */ url: string; /** Local file path where the download will be saved */ destination: string; /** Optional HTTP headers to include in the request */ headers?: { [key: string]: string; }; /** Network type requirement for download */ network?: 'cellular' | 'wifi-only'; /** Download priority level */ priority?: 'high' | 'normal' | 'low'; /** * Android DownloadManager notification visibility. * * - `'completed'` (default): show while downloading and keep the notification after completion. * - `'progress'`: show while downloading, remove the notification when finished. * - `'hidden'`: no system notification; use plugin progress events instead. * * Ignored on iOS and Web. * * @since 8.2.0 */ notification?: 'completed' | 'progress' | 'hidden'; } /** * Capacitor plugin for downloading files with background support. * Provides resumable downloads with progress tracking. */ export interface CapacitorDownloaderPlugin { /** * Start a new download task. * * @param options - Download configuration * @returns Promise with initial download task status * @example * ```typescript * const task = await Downloader.download({ * id: 'my-download', * url: 'https://example.com/file.pdf', * destination: 'downloads/file.pdf', * notification: 'hidden', // Android: no system notification; use downloadProgress events * }); * ``` */ download(options: DownloadOptions): Promise; /** * Pause an active download. * Download can be resumed later from the same position. * * @param options - Options containing the download task ID * @returns Promise that resolves when paused */ pause(options: { id: string; }): Promise; /** * Resume a paused download. * Continues from where it was paused. * * @param options - Options containing the download task ID * @returns Promise that resolves when resumed */ resume(options: { id: string; }): Promise; /** * Stop and cancel a download permanently. * Downloaded data will be deleted. * * @param options - Options containing the download task ID * @returns Promise that resolves when stopped */ stop(options: { id: string; }): Promise; /** * Check the current status of a download. * * @param options - Options containing the download task ID * @returns Promise with current download task status */ checkStatus(options: { id: string; }): Promise; /** * Get information about a downloaded file. * * @param options - Options containing the file path * @returns Promise with file size and MIME type */ getFileInfo(options: { path: string; }): Promise<{ size: number; type: string; }>; /** * Listen for download progress updates. * Fired periodically as download progresses. * * @param eventName - Must be 'downloadProgress' * @param listenerFunc - Callback receiving progress updates * @returns Promise with listener handle for removal * @example * ```typescript * const listener = await Downloader.addListener('downloadProgress', (data) => { * console.log(`Download ${data.id}: ${data.progress}%`); * }); * ``` */ addListener(eventName: 'downloadProgress', listenerFunc: (progress: { id: string; progress: number; /** Bytes written so far */ bytesWritten?: number; /** Total bytes expected, or 0 when the server did not report a length */ bytesTotal?: number; }) => void): Promise; /** * Listen for download completion. * Fired when a download finishes successfully. * * @param eventName - Must be 'downloadCompleted' * @param listenerFunc - Callback receiving completion notification * @returns Promise with listener handle for removal */ addListener(eventName: 'downloadCompleted', listenerFunc: (result: { id: string; }) => void): Promise; /** * Listen for download failures. * Fired when a download encounters an error. * * @param eventName - Must be 'downloadFailed' * @param listenerFunc - Callback receiving error information * @returns Promise with listener handle for removal */ addListener(eventName: 'downloadFailed', listenerFunc: (error: { id: string; error: string; }) => void): Promise; /** * Remove all event listeners. * Cleanup method to prevent memory leaks. * * @returns Promise that resolves when all listeners removed */ removeAllListeners(): Promise; /** * Get the plugin version number. * * @returns Promise with version string */ getPluginVersion(): Promise<{ version: string; }>; }