Skip to content

Commit

Permalink
Prevent files in default download directories from being overwritten,…
Browse files Browse the repository at this point in the history
… close worker after download
  • Loading branch information
asivery committed Dec 1, 2023
1 parent bcced62 commit eaddf21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ async function createWindow() {

window.webContents.session.on('will-download', async (event, item, contents) => {
if (downloadPath) {
item.setSavePath(path.join(downloadPath, item.getFilename()));
const baseFilename = item.getFilename();
let filename = path.join(downloadPath, baseFilename);
const { name, ext } = path.parse(baseFilename);
let i = 1;
while(fs.existsSync(filename)){
filename = path.join(downloadPath, `${name} (${i++})${ext}`);
}
item.setSavePath(filename);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/wmd/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class EWMDHiMD extends HiMDFullService {
blocks.push(data);
progressCallback({ read: blocks.length, total });
}
nodeWorker.close();
return { format: DiscFormat.spStereo, data: concatUint8Arrays(...blocks) };
}

Expand Down

0 comments on commit eaddf21

Please sign in to comment.