electron-dl-manager
Version:
A library for implementing file downloads in Electron with 'save as' dialog and id support.
101 lines (100 loc) • 2.87 kB
TypeScript
import type { DownloadItem, Event, WebContents } from "electron";
export interface RestoreDownloadData {
/**
* Download id
*/
id: string;
url: string;
/**
* The path and filename where the download will be saved.
*/
fileSaveAsPath: string;
urlChain: string[];
mimeType: string;
/**
* The ETag of the download, if available.
* This is used to resume downloads.
*/
eTag: string;
receivedBytes: number;
totalBytes: number;
startTime: number;
percentCompleted: number;
/**
* If persistOnAppClose is true, this is the path where the download
* is persisted to. This is used to restore the download later.
*/
persistedFilePath?: string;
}
export interface DownloadDataConfig {
/**
* Download id
*/
id?: string;
}
/**
* Contains the data for a download.
*/
export declare class DownloadData {
/**
* Generated id for the download
*/
id: string;
/**
* The Electron.DownloadItem. Use this to grab the filename, path, etc.
* @see https://www.electronjs.org/docs/latest/api/download-item
*/
item: DownloadItem;
/**
* The Electron.WebContents
* @see https://www.electronjs.org/docs/latest/api/web-contents
*/
webContents: WebContents;
/**
* The Electron.Event
* @see https://www.electronjs.org/docs/latest/api/event
*/
event: Event;
/**
* The name of the file that is being saved to the user's computer.
* Recommended over Item.getFilename() as it may be inaccurate when using the save as dialog.
*/
resolvedFilename: string;
/**
* If true, the download was cancelled from the save as dialog. This flag
* will also be true if the download was cancelled by the application when
* using the save as dialog.
*/
cancelledFromSaveAsDialog?: boolean;
/**
* The percentage of the download that has been completed
*/
percentCompleted: number;
/**
* The download rate in bytes per second.
*/
downloadRateBytesPerSecond: number;
/**
* The estimated time remaining in seconds.
*/
estimatedTimeRemainingSeconds: number;
/**
* If the download was interrupted, the state in which it was interrupted from
*/
interruptedVia?: "in-progress" | "completed";
/**
* If defined, this is the path where the download is persisted to.
*/
persistedFilePath?: string;
constructor(config?: DownloadDataConfig);
/**
* Returns data necessary for restoring a download
*/
getRestoreDownloadData(): RestoreDownloadData;
isDownloadInProgress(): boolean;
isDownloadCompleted(): boolean;
isDownloadCancelled(): boolean;
isDownloadInterrupted(): boolean;
isDownloadResumable(): boolean;
isDownloadPaused(): boolean;
}