Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overwrite option #137

Merged
merged 11 commits into from
Sep 17, 2021
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