Skip to content

Commit

Permalink
Add overwrite option (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Wilson Wong <wilsonwong2988@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
3 people authored Sep 17, 2021
1 parent c342211 commit 8b045bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ declare namespace electronDl {
@default true
*/
readonly showBadge?: boolean;

/**
Allow downloaded files to overwrite files with the same name in the directory they are saved to.
The default behavior is to append a number to the filename.
@default false
*/
readonly overwrite?: boolean;
}
}

Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ function registerListener(session, options, callback = () => {}) {
} else {
const filename = item.getFilename();
const name = path.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType());
filePath = unusedFilename.sync(path.join(directory, name));

if (options.overwrite) {
filePath = path.join(directory, name);
} else {
filePath = unusedFilename.sync(path.join(directory, name));
}
}

const errorMessage = options.errorMessage || 'The download of {filename} was interrupted';
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ Default: `true`

Shows the file count badge on macOS/Linux dock icons when download is in progress.

#### overwrite

Type: `boolean`\
Default: `false`

Allow downloaded files to overwrite files with the same name in the directory they are saved to.

The default behavior is to append a number to the filename.

## Development

After making changes, run the automated tests:
Expand Down

0 comments on commit 8b045bb

Please sign in to comment.