How can I handle no internet in case of electron-dl?

Viewed 164

I am trying to download a file via electron-dl and I want to gracefully end the download in case the internet goes off. I want to send a main to renderer event in case the download interrupts because of internet connection breaking down. How can I achieve that? Thanks in advance. :)

1 Answers

What's up?

Electron has an event called online and offline:

  window.addEventListener('online',  () => {})
  window.addEventListener('offline',  () => {})

And you can get the file with

electronDL.onStart((item) => {
   window.addEventListener('offline',  () => {
     item.cancel();
   })
}))
Related