Electrom will-download pause function

1、code from github

url-link:

   https://github.com/electron/electron/issues/7712

// to store downloadItems
var downloadItems = [];

ipcMain.on('dowloadFiles', function(evt, options) {
    // ...
    if(options.command === 'stopDownload') {
           var item = getDownloadItem(options.url); // fetch item from downloadItems array
           item.pause();
           return;
      }
    // ...
});

mainWindow.webContents.session.on('will-download', function(event, item, webContents) {
    // ...

      // store the download item, so that we can call item.pause/resume in a 
      downloadItems.push(item);

    // ...
});

  

原文地址:https://www.cnblogs.com/cbugs/p/10096078.html