Class: DownloadManager
helpers/services/download-manager.DownloadManager
The DownloadManager class serves as a centralized manager for handling all download-related activities within an application. It is designed to manage a queue of downloads, allowing for operations such as adding to the queue, checking the queue's status, and processing downloads in a controlled manner. This class employs a singleton pattern to ensure that only one instance manages the download operations throughout the application lifecycle, thereby preventing conflicts and ensuring consistency in download management.
The DownloadManager encapsulates the complexity of download operations, providing a simple and thread-safe interface for queuing and managing downloads. It supports basic queue operations such as adding items to the queue and checking if an item exists within the queue. Additionally, it implements logic to manage concurrent downloads, adhering to a specified limit of concurrent download operations to avoid overwhelming the system or the network connection.
This class utilizes events to communicate the progress and completion of downloads, making it easy to integrate with UI components or other parts of the application that require updates on download status. It leverages the electron-dl library for performing the actual download operations, encapsulating the library's functionality and providing a simplified interface for download tasks.
Key functionalities include:
- Singleton access to ensure a single point of download management.
- Queue management to add, check, and process download items.
- Limitation of concurrent downloads to prevent overloading.
- Integration with electron-dl for handling download tasks, including support for progress tracking and cancellation.
- Event-driven updates for download progress, completion, and errors, facilitating easy integration with other application components.
Usage of this class should be done through the getInstance method to access the singleton instance, ensuring that download operations are centrally managed. The class provides methods to manipulate the download queue, including adding new downloads and querying the queue status. It automatically handles the processing of queued downloads, respecting the maximum concurrent downloads limit and updating the status of each download accordingly.
Table of contents
Constructors
Methods
Constructors
constructor
• new DownloadManager(): DownloadManager
Constructs a new instance of the DownloadManager class.
Returns
Defined in
src/electron/helpers/services/download-manager/index.ts:94 (opens in a new tab)
Methods
addToQueue
▸ addToQueue(item
): void
Adds a new item to the download queue and processes the queue if possible.
Parameters
Name | Type | Description |
---|---|---|
item | DownloadItem | The DownloadItem object to add to the queue. |
Returns
void
Defined in
src/electron/helpers/services/download-manager/index.ts:144 (opens in a new tab)
getDownloadQueue
▸ getDownloadQueue(): DownloadItem
[]
Retrieves the current download queue.
Returns
DownloadItem
[]
An array of DownloadItem objects in the queue.
Defined in
src/electron/helpers/services/download-manager/index.ts:127 (opens in a new tab)
getQueueSize
▸ getQueueSize(): number
Gets the current size of the download queue.
Returns
number
The number of items in the download queue.
Defined in
src/electron/helpers/services/download-manager/index.ts:119 (opens in a new tab)
isItemInQueue
▸ isItemInQueue(itemId
): boolean
Checks if an item is already present in the download queue.
Parameters
Name | Type | Description |
---|---|---|
itemId | string | The unique identifier of the download item. |
Returns
boolean
A boolean indicating whether the item is in the queue.
Defined in
src/electron/helpers/services/download-manager/index.ts:136 (opens in a new tab)
getInstance
▸ getInstance(): DownloadManager
Retrieves the singleton instance of the DownloadManager.
Returns
The singleton instance of the DownloadManager.
Defined in
src/electron/helpers/services/download-manager/index.ts:102 (opens in a new tab)
resetInstance
▸ resetInstance(): void
Resets the singleton instance of the DownloadManager to null.
Returns
void
Defined in
src/electron/helpers/services/download-manager/index.ts:111 (opens in a new tab)