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

MULTIPLY BUG with DOWNLOAD (BIGGEST BUG 2021?) #127

Open
copyandexecute opened this issue Jan 9, 2021 · 5 comments
Open

MULTIPLY BUG with DOWNLOAD (BIGGEST BUG 2021?) #127

copyandexecute opened this issue Jan 9, 2021 · 5 comments

Comments

@copyandexecute
Copy link

copyandexecute commented Jan 9, 2021

After I click on my button the download multiplies each team

ipcMain.on('download', (ev, args) => {
  const focusedWindow = BrowserWindow.getFocusedWindow()
  if (focusedWindow) {
    args.properties.onProgress = (status: number) => focusedWindow.webContents.send('download-progress', status)
    download(focusedWindow, args.url, args.properties)
      .then(dl => {
        console.log(ev)
        focusedWindow.webContents.send('download-complete', dl.getSavePath())
      })
      .catch(reason => {
        console.log(reason)
      })
  }
})
export const downloadAndWriteFile = (url: string, properties: electronDl.Options, cb?: any) => {
  ipcRenderer.send('download',
    {
      url: url,
      properties: { ...properties }
    })
  ipcRenderer.on('download-complete', (event, file) => {
    console.log(file)
    if (cb instanceof Function) {
      cb()
    }
  })
  ipcRenderer.on('download-progress', (event, progress) => {
    /* if (status) {
      status(Math.floor(progress.percent * 100) + '%')
    } */
    // console.log(progress)
  })
}
@kah9509
Copy link

kah9509 commented Jan 12, 2021

I have the same problem....
I try to receive 2 files in sequence, but the download event does not work intermittently...ㅠㅠ
SOMEBODY HELPME

@megakraken
Copy link

This thing is just horrendously broken as everything electron.

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

@theogravity
Copy link
Contributor

I think this is due to it spawning two listeners if you look at the source.

Give my package a try where it does handle multiple downloads:

https:/theogravity/electron-dl-manager

@xianyunleo
Copy link

My library support Multiple downloads are handled properly and report individual progress. You are also able to cancel / pause / resume as well. Easy to use

https:/xianyunleo/electron-dl-downloader

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

5 participants