Comments (4)
I have forgotten about this, but seems that the download call will resolve the downloadItem from will-download
event listener, which would get the same downloadItem if the latter listener registered before the former will-download
event dispatched.
IMO if electron-dl would like to handle this correctly, it should implement a queue mechanism to prevent/delay the latter download call/listener registration until got a will-download
event, for currently electron has not provided any api to get the specified downloadItem.
from electron-dl.
It seems two calls got the same downloadItem.
Sample code:
win.webContents.on('did-finish-load', () => {
const p1 = download(win, target);
const p2 = download(win, target2);
Promise.all([p1, p2]).then((arr) => {
console.log(arr[0] === arr[1]);
});
});
And more, the two listeners has been called for 4 times in total, which I think is not expected.
Maybe we should avoid calling like this?
from electron-dl.
Confirmed, and it is not intermittent in my case but 100% reproducible. I attempted to set up bulk download via the code below and noticed that the downloads got tangled.
const downloadByUrl = async (url, options) => {
// https://electronjs.org/docs/api/download-item
const dl /* :DownloadItem */ = await download(mainWindow, url, options);
const downloadItemInfo = {
savePath: dl.getSavePath(),
url: dl.getURL(),
mimeType: dl.getMimeType(),
};
return downloadItemInfo;
};
interface DownloadConfig {
url: any;
options: any;
}
const bulkDownload = async (downloadConfigs: Array<DownloadConfig>) => {
const promises = [];
downloadConfigs.forEach(downloadConfig => {
promises.push(downloadByUrl(downloadConfig.url, downloadConfig.options));
});
const downloadItemInfos = await Promise.all(promises);
log.debug("downloadItemInfos", downloadItemInfos);
return downloadItemInfos;
};
Proof of tangled downloads when trying to download another-small-text-file.txt
and small-text-file.txt
below.
downloadConfigs sent to bulkDownload():
[
{
options: {
directory: '/var/folders/_1/fnvjsx8j2r97wknt0vvfvhmh0000gn/T/7ReCyHxuMUbBv2hIuvmn',
filename: 'another-small-text-file.txt'
},
url: 'http://localhost:7777/another-small-text-file.txt'
},
{
options: {
directory: '/var/folders/_1/fnvjsx8j2r97wknt0vvfvhmh0000gn/T/7ReCyHxuMUbBv2hIuvmn',
filename: 'small-text-file.txt'
},
url: 'http://localhost:7777/small-text-file.txt'
}
]
Resulting downloadItemInfos:
[
{
savePath: '/var/folders/_1/fnvjsx8j2r97wknt0vvfvhmh0000gn/T/7ReCyHxuMUbBv2hIuvmn/small-text-file.txt',
url: 'http://localhost:7777/another-small-text-file.txt',
mimeType: 'text/plain'
},
{
savePath: '/var/folders/_1/fnvjsx8j2r97wknt0vvfvhmh0000gn/T/7ReCyHxuMUbBv2hIuvmn/small-text-file.txt',
url: 'http://localhost:7777/another-small-text-file.txt',
mimeType: 'text/plain'
}
]
from electron-dl.
After looking at the source code, it looks like it isn't setup to easily handle multiple downloads at one time.
By calling the 'download' function multiple times you are calling the 'registerListeners' multiple times which will reset some variables that are meant to be used for multiple file downloads. It appears that function is only meant to be called once.
Hard to say exactly what the author was thinking. He needs some good examples.
In the mean time, its very easy to implement your own setup for this.
from electron-dl.
Related Issues (20)
- saveAs window prompt always showing up HOT 8
- Allow to fetch the file as a buffer HOT 3
- Support relative paths HOT 1
- MULTIPLY BUG with DOWNLOAD (BIGGEST BUG 2021?) HOT 4
- Cannot find n ame 'Completed'. (new in 3.2) HOT 1
- Utilizing session.enableNetworkEmulation with ElectronDL HOT 1
- TypeError upon evaluation of download() arguments HOT 1
- how to use electron latest in electron-dl HOT 10
- Overwrite Option is flase. but, the same file name is specified in the directory, it is overwritten. HOT 2
- Status of tests and remote module HOT 1
- Downloads stuck on MacOS HOT 5
- Cannot read property 'getType' of null at getWindowFromWebContents
- cannot read 'getOwnerBrowserWindow' HOT 1
- Save-as dialog shows two periods before the SQLite file extension in the file type filter
- Property defination are different between index.d.ts and index.js
- Download URL with POST requests. HOT 1
- is there any sample project i can't make
- how can i make progress bar please help HOT 1
- When I change menu in navbar with route, it goes into loop
- how to post a json param
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-dl.