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

Saddenly "save dialog" open duration downloading #19

Open
thehatami opened this issue May 12, 2018 · 23 comments
Open

Saddenly "save dialog" open duration downloading #19

thehatami opened this issue May 12, 2018 · 23 comments

Comments

@thehatami
Copy link

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
Copy link

arulapj commented May 23, 2018

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

@danielnieto
Copy link
Owner

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
Copy link
Collaborator

@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
Copy link

tonylkc commented Jun 17, 2018

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
Copy link

michaelarmfield commented Jun 25, 2018

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
Copy link

shealan commented Jun 28, 2018

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
Copy link

shealan commented Jun 28, 2018

@danielnieto I have emailed you some example code :)

@tonylkc
Copy link

tonylkc commented Jul 2, 2018

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
Copy link
Contributor

cedced19 commented Aug 9, 2018

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
Copy link

henkdot commented Sep 26, 2018

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

@danielnieto
Copy link
Owner

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

@danielnieto
Copy link
Owner

Does this still happens? Otherwise I can close this issue

@benesva4
Copy link

benesva4 commented Apr 5, 2019

It's still a problem.

@florianperrot44
Copy link

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
Copy link

minhdv commented Jun 23, 2019

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
Copy link

bung87 commented Jul 19, 2019

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

@bung87
Copy link

bung87 commented Jul 19, 2019

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
Copy link

DonSalvador commented Dec 5, 2019

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
Copy link

skyslide22 commented Dec 23, 2019

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
Copy link

SpinShare commented Apr 30, 2020

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
Copy link

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
Copy link

gaols commented Oct 12, 2020

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
Copy link

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);
    });
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests