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

download-progress event not firing #8659

Open
remzany opened this issue Nov 4, 2024 · 2 comments
Open

download-progress event not firing #8659

remzany opened this issue Nov 4, 2024 · 2 comments

Comments

@remzany
Copy link

remzany commented Nov 4, 2024

package JSON

"dependencies": {
"@capacitor-community/electron": "^5.0.0",
"chokidar": "~3.5.3",
"electron-is-dev": "~2.0.0",
"electron-serve": "~1.1.0",
"electron-unhandled": "~4.0.1",
"electron-updater": "^5.3.0",
"electron-window-state": "^5.0.3",
"keytar": "^7.9.0",
"electron-store": "^10.0.0"
},

"scripts": {
"electron:make:windows": "npm run build && electron-builder build --win -c ./electron-builder.config.json -p always"
},

"build": {
"appId": "/",
"mac": {
  "target": "default",
  "arch": [
    "universal"
  ]
},
"nsis": {
  "perMachine": true,
  "oneClick": false,
  "allowToChangeInstallationDirectory": true,
  "artifactName": "${name}-${version}.${ext}"
}

},

---------------------- end ----------------------

index.ts - Logic

autoUpdater.setFeedURL({
provider: 'generic',
url: 'https://custom_domain/releases/'
});

// Automatically check for updates and notify
autoUpdater.checkForUpdatesAndNotify();

// Handle autoUpdater events
autoUpdater.on('update-available', (info) => {
  console.log('Update available:', info);
  const dialogOpts = {
    type: 'info' as const, // Ensure this is a specific string literal
    buttons: ['OK', 'Later'],
    title: 'Update Available',
    message: `Version ${info.version} is now available.`,
    detail: `A new version is available. For the application to work as it should you must download new version. Don't close the application when downloading.`,
  };
  dialog.showMessageBox(dialogOpts).then((result) => {
    if (result.response === 0) { // User clicked "OK"
      autoUpdater.downloadUpdate();
    }
  });
});

autoUpdater.on('download-progress', (progressObj) => {
  console.log('download progress event');
  // const progressMessage = `Download speed: ${(progressObj.bytesPerSecond / 1000).toFixed(2)} KB/s\n` +
  //                         `Downloaded ${Math.round(progressObj.percent)}% ` +
  //                         `(${(progressObj.transferred / (1024 * 1024)).toFixed(2)} MB / ${(progressObj.total / (1024 * 1024)).toFixed(2)} MB)`;
  
  const dialogOpts = {
    type: 'info' as const,
    buttons: ['OK', 'Later'],
    title: 'Downloading progress',
    message: `downloading happening`,
    detail: `Downloading now...`,
  };
  dialog.showMessageBox(dialogOpts)

  // dialog.showMessageBox({
  //   type: 'info',
  //   title: 'Downloading Update',
  //   message: progressMessage,
  //   detail: 'Please wait while the update is being downloaded.',
  //   buttons: ['OK']
  // });
});

autoUpdater.on('update-downloaded', () => {
  console.log('Update downloaded; will install now');
  const dialogOpts = {
    type: 'info' as const, // Ensure this is a specific string literal
    buttons: ['Restart', 'Later'],
    title: 'Install Update',
    message: 'A new version has been downloaded.',
    detail: 'The application will restart to install the update.',
  };
  dialog.showMessageBox(dialogOpts).then((result) => {
    if (result.response === 0) { // User clicked "Restart"
      autoUpdater.quitAndInstall();
    }
  });
});

autoUpdater.on('error', (error) => {
  console.error('Error in auto-updater:', error);
  dialog.showErrorBox('Update Error', `There was an error while updating the application:\n${error.message}`);
});

---------------------- end ----------------------

Question:

The download-progress event doesn't fire, all other events from the code above works just fine. But the download-progress is not. I have Content-Length in headers from the server (browser shows the download size). I'm trying on windows 11 Pro 23H2 version. Is there something else I'm missing? Thank you in advance.

@peter-sanderson
Copy link

peter-sanderson commented Nov 19, 2024

Hello, I did a lot of digging and I think I have a smoking gun.

If the isUseMultipleRangeRequest=true then here the downloadInfoTransform is not created.

I think this is the root cause of this trouble.


On top of that, weirdly the autoUpdater.disableDifferentialDownload = true; is not working for me on Linux. It seems it is read only in the MacUpdater and in the NsisUpdater and nowhere else.

This issue I am trying to solve in this PR: #8695

@peter-sanderson
Copy link

It seems to me that solution is to pass downloadInfoTransform down the line into the multipleRangeDownloader and its doExecuteTasks function.

Here is PR just for demonstrative purpose. Here is the draft PR: #8697 Its is just an illustrative example.

I lack the knowledge to complate this PR.

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

2 participants