Skip to content

Commit

Permalink
Add isResumable()
Browse files Browse the repository at this point in the history
  • Loading branch information
theogravity committed Mar 25, 2024
1 parent ea30fed commit 5394c41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 2.2.0 (2024-03-25)

- Added some missing instructions for how to format the download rate / estimated time remaining

Added to `DownloadData`:

- `isDownloadResumable()`

# 2.1.0 (2024-03-25)

Added to `DownloadData`:
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ manager.resumeDownload(id);
- [Formatting download progress](#formatting-download-progress)
- [`isDownloadInProgress()`](#isdownloadinprogress)
- [`isDownloadPaused()`](#isdownloadpaused)
- [`isDownloadResumable()`](#isdownloadresumable)
- [`isDownloadCancelled()`](#isdownloadcancelled)
- [`isDownloadInterrupted()`](#isdownloadinterrupted)
- [`isDownloadCompleted()`](#isdownloadcompleted)
Expand Down Expand Up @@ -375,6 +376,11 @@ $ npm install @types/bytes --save-dev
```typescript
import bytes from 'bytes'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime';
import duration from 'dayjs/plugin/duration';

dayjs.extend(relativeTime);
dayjs.extend(duration);

const downloadData = manager.getDownloadData(id); // or DataItem from the callbacks

Expand All @@ -401,6 +407,14 @@ Returns true if the download is paused.
isDownloadPaused(): boolean
```

### `isDownloadResumable()`

Returns true if the download is resumable.

```typescript
isDownloadResumable(): boolean
```

### `isDownloadCancelled()`

Returns true if the download is cancelled.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-dl-manager",
"version": "2.1.0",
"version": "2.2.0",
"description": "A library for implementing file downloads in Electron with 'save as' dialog and id support.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/DownloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class DownloadData {
return this.item.getState() === 'interrupted'
}

isDownloadResumable() {
return this.item.canResume()
}

isDownloadPaused() {
return this.item.isPaused()
}
Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/DownloadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function createMockDownloadData() {
isDownloadCompleted: jest.fn(),
isDownloadCancelled: jest.fn(),
isDownloadInterrupted: jest.fn(),
isDownloadResumable: jest.fn(),
isDownloadPaused: jest.fn(),
item,
}
Expand Down

0 comments on commit 5394c41

Please sign in to comment.