danielnieto / electron-download-manager

Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading
MIT License
119 stars 51 forks source link

Saddenly "save dialog" open duration downloading #19

Open thehatami opened 6 years ago

thehatami commented 6 years ago

i try download multi files by .map and {download} function. but sometime save dialog open and try somthing called "download", how can i manage it?

downloadQueue.map(source => {
          DownloadManager.download({
            url: source.filename,
            path: source.type
          }, (error, finished, failed) => {
            if (finished) {
              repoDownloaded += 1;
            }
            return !error;
          });
          return true;
        });
arulapj commented 6 years ago

i am too facing it now days, even though we have downloadpath.

danielnieto commented 6 years ago

Can any of you guys provide a simple project in which I can reproduce this bug? I need to see it myself to debug it

ndelvalle commented 6 years ago

@thehatami can you provide more code to your example please? If your intention is to loop and execute async functions, that is not the best approach.

tonylkc commented 6 years ago

i have the same issues. in my case, ive used the remote to call the app, browser windows and net. is it the problem causing the dialog?

And Im using the electron-react-boilerplate

michaelarmfield commented 6 years ago

I've experienced this issue as well while iterating over an array of signed URL's received from a server. I'm doing this so I can show the download state in my UI via onProgress option callback. Strangely, it works in development mode but not production for my application. I am calling it from the renderer process with remote. Something similar to:

files.forEach(file => {
  require("electron").remote.require("electron-download-manager").download({
    url: file.url, 
    onProgress: (progress, item) => updateDownloadState(file, progress, item)
  }, (error, info) => {
    // ...rest of code
    })
  })
})

I'll have to dig in further, but from my initial experimentation calling download will push an item into the queue as expected and then win.webContents.downloadURL(options.url); is called.

The 'will-download' event occurs and the listener function (set via _registerListener) is called. However, the queue is empty for the listener function. The variable queueItem is then null so the code within the conditional doesn't run and that's why the dialog appears. Figuring out why the queue is empty is the next step...

shealan commented 6 years ago

I'm having the same issue. Has anyone made any progress. Weirdly it seems to work sometimes, not other... I have not got it working on a final built app yet. Hoping someone else has uncovered more?

shealan commented 6 years ago

@danielnieto I have emailed you some example code :)

tonylkc commented 6 years ago

I got it work by adding electron-download-manager as dependence inside app/package.json to resolve the remote require problem. And avoid using remote to register the download path.

cedced19 commented 6 years ago

I resolved this problem by adding to the index.js file (where you create your window):

const DownloadManager = require("electron-download-manager");

DownloadManager.register({downloadFolder: yourpath });
henkdot commented 5 years ago

Issue randomly appeared after I haven't changed anything. Any one found a solution for this, yet?

danielnieto commented 5 years ago

I'll bump the dependencies versions and see if this still happens, I'm thinking this might be an issue from Electron itself

danielnieto commented 5 years ago

Does this still happens? Otherwise I can close this issue

benesva4 commented 5 years ago

It's still a problem.

florianperrot44 commented 5 years ago

I have the same problem with my Electron app (use lastest version of Electron and download manager). I use ipc main event to run a DownloadManager.download in main.js to be sure to be always in main process. Sometime the download box appears... but very rarely But i reproduced a case that download box always appears : It's when i register the download dir in the ipc event function (DownloadManager.register) When register() is placed in global context (outside all functions).. that seems to better works. But why this behaviour ?

That means user can't change the download folder at runtime... and it's a problem.

minhdv commented 5 years ago

I have the same problem. And I found that, if the url contains the port number then download box will be appeared instead of store file into the defined folder automatically. IMO, It is a bug.

bung87 commented 5 years ago

onResult:(finishedCount, errorsCount, itemUrl) => { progressBar.value = finishedCount } same problem during bulkDownload with electron-progressbar

bung87 commented 5 years ago

I've fixed my problem by editing index.js rename _registerListener to registerListener and export it . then specify the window as first parameter. thinking progressbar will create new window, and private function _registerListener can't change window variable. that's the problem.

hope this helpful.

DownloadManager.registerListener(mainWindow, {
    downloadFolder: downloads_dir
  });
DonSalvador commented 4 years ago

In Electron 7 is not working anymore. You need to change in index.js the variable queue to global.queue to get it working

skyslide22 commented 4 years ago

download the homepage as html is not working on homepages f.e youtube.com opens the savefile dialog (windows fileexplorer) but, any subpage like youtube.com/watch?=djfhgdkjfhd is actually working, just homepages doesn't work :/

main.js

const DownloadManager = require("electron-download-manager");
DownloadManager.register({downloadFolder: __dirname + "/siteColorDownloads"});

renderer.js / devtool console (from chromium)

const dl = app.require("electron-download-manager")
dl.download({
    url: "http://youtube.com",
    path: ""
  }, function (error, finished, errors) {
    if (error) {
        console.log("finished: " + finished);
        console.log("errors: " + errors);
        return;
    }

    console.log("site download finished");

  });
SpinShare commented 4 years ago

We also have similar problems with both this project and electron-dl. We're sending them one at a time (after the download, we do some processing and send out the next dl after that) via IPC. Sometimes there is no actual response from electron-download-manager, sometimes it shows the Save as dialog, sometimes it throws an "Object has already been destroyed" error.

ipcRenderer.send("download", {
    queueItem: downloadItem
});

And in the main process we use electron-download-manager like so:

DownloadManager.register({
    downloadFolder: app.getPath("temp")
});

ipcMain.on("download", (event, ipcData) => {
    console.log("Download: " + ipcData.queueItem.title);

    DownloadManager.download({url: ipcData.queueItem.downloadPath}, (error, dlInfo) => {
        if (error) {
            console.log(error);
            return;
        }

        let downloadItem = {
            id: ipcData.queueItem.id,
            downloadPath: dlInfo.filePath
        }

        win.webContents.send("download-complete", downloadItem);
    });
});
themagiulio commented 4 years ago

I have the same problem with bulkDownload.

  downloadManager.bulkDownload({
          urls: urls
      }, function(error, finished, errors){
          if(error){
            console.log("finished: " + finished);
            console.log("errors: " + errors);
          }
  });

If urls contains only one element everything is fine, but if I pass 2 or more elements sometimes the savefile dialog appears. I think I will create a script which downloads every single file one at a time...

gaols commented 3 years ago

I have the same problem, but i solved it by reading the doc more carefully.
you should call DownloadManager.register({downloadFolder: yourpath }); before creating your window, or dialog will open.

megakraken commented 3 years ago

Because of the unbelievable crappiness of electron that manages to f*ck up even a most basic task like downloading a file, I have come up with this nodejs function that I use instead. Electron must be the only technology that manages to be even crappier than Node.js itself which is an incredible achievement in its own right, but whatever.

async function downloadFile(destPath, url) {
  let cookies = await session.defaultSession.cookies.get({}),
      header  = cookies.map(c => `${c.name}=${c.value}`).join('; '),
      _fs     = require('fs'),
      _http   = require('http');
  return new Promise((resolve, reject) => {
    _http.get(url, { headers: { 'Cookie': header } }, ret => {
      let file = _fs.createWriteStream(destPath);
      ret.pipe(file);
      file.on('finish', () => {
        file.close();
        resolve(destPath);
      });
    }).on('error', err => {
      reject(err.message);
    });
  });
}