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

Abort download #1150

Closed
sante85 opened this issue Jan 20, 2017 · 23 comments · May be fixed by qcif/data-curator#563
Closed

Abort download #1150

sante85 opened this issue Jan 20, 2017 · 23 comments · May be fixed by qcif/data-curator#563

Comments

@sante85
Copy link

sante85 commented Jan 20, 2017

  • Version:
    last tag
  • Target:
    all

Make it possible abort download?

@develar
Copy link
Member

develar commented Jan 20, 2017

What do you mean?

@sante85
Copy link
Author

sante85 commented Jan 20, 2017

when autoUpdater download release file, and another event is emitted, I want programmatically abort (stop) download in progress and delete file in temp directory.

  1. delete file in temp directory even next release has been successfully installed.

Thanks

@sante85
Copy link
Author

sante85 commented Jan 23, 2017

Hi developer,
the problem is clear?

Thanks

@develar
Copy link
Member

develar commented Jan 23, 2017

You can abort download —

  1. checkForUpdates returns Promise of UpdateCheckResult.
  2. UpdateCheckResult has property downloadPromise.
  3. We use special configured Bluebird — you can call downloadPromise.cancel()

But — isCancelled is not checked by electronHttpExecutor.ts or nodeHttpExecutor.ts. To be fixed.

delete file in temp directory even next release has been successfully installed.

It is a different issue. To investigate (currently we suppose that OS will delete temp files).

@sante85
Copy link
Author

sante85 commented Jan 23, 2017

I use generic provider on windows OS

@sante85
Copy link
Author

sante85 commented Jan 23, 2017

we automatically delete temp file, because if download fail, on reopen app, it try dowload update. Repeating this step many times and create problem on disk full temp directory.

@sante85
Copy link
Author

sante85 commented Jan 23, 2017

The problem is that while downloading the update, I wish I could stop at any time. Then if it is blocked or fails for other reasons, the temporary file should be deleted.

@sante85
Copy link
Author

sante85 commented Feb 6, 2017

when autoUpdater download release file, and another event is emitted, I want programmatically abort (stop) download in progress and delete file in temp directory.

delete file in temp directory even next release has been successfully installed.

Thanks

@sante85
Copy link
Author

sante85 commented Feb 16, 2017

when autoUpdater download release file, and another event is emitted, I want programmatically abort (stop) download in progress and delete file in temp directory.

thanks

@Ruj89
Copy link

Ruj89 commented Feb 16, 2017

up

@develar develar changed the title Make it possible abort download? Abort download Feb 17, 2017
develar added a commit to develar/electron-builder that referenced this issue Feb 17, 2017
@develar
Copy link
Member

develar commented Feb 17, 2017

UpdateCheckResult now has cancellationToken property — call cancellationToken.cancel()

@develar
Copy link
Member

develar commented Feb 17, 2017

Docs will be updated later.

@sante85
Copy link
Author

sante85 commented Mar 3, 2017

hi developer,
how to pass cancellationToken to updater? he write docs please?

@Argyos
Copy link

Argyos commented Sep 3, 2017

How is the implementation to abort the Download? I'm not clear in this aspect, checkForUpdates return a promise which I see on the JSON, but the implementations, to stop by user's demand, when autoDownload is false ?

@develar
Copy link
Member

develar commented Sep 3, 2017

@New-key

Set autoDownload to false and then you can call autoUdater.downloadUpdate directly.

import { CancellationToken } from "electron-updater"

const cancellationToken = new CancellationToken()
autoUdater.downloadUpdate(cancellationToken)

// stop download
cancellationToken.cancel()

@develar
Copy link
Member

develar commented Sep 3, 2017

@New-key I don't want expose electron-builder-http so, in the next version CancellationToken will be available from electron-updater. I will add example to docs.

@genesy
Copy link

genesy commented Jun 30, 2018

Am I doing this right ?

autoUpdater.checkForUpdates().then((downloadPromise) => {
    cancellationToken = downloadPromise.cancellationToken;
});
someEvent.then(() => { cancellationToken.cancel() })

when i trigger cancellationToken.cancel() i get an error Error: Cancelled why is it an error if i'm purposely doing it?

@jason-zuo
Copy link

@genesy hi ,i face the same problem ,can you fixed it?

@genesy
Copy link

genesy commented Jul 10, 2018

@jason-zuo nope just left it as is. might be meant that way

@develar
Copy link
Member

develar commented Nov 8, 2018

electron-updater 3.2.2 will not dispatch error event for CancellationError, but returned promise still will be rejected with CancellationError because otherwise not easy for you to handle this properly (either then or catch handlers must be called for Promise, so, it is logical to call catch).

develar added a commit to develar/electron-builder that referenced this issue Nov 8, 2018
develar added a commit to develar/electron-builder that referenced this issue Nov 8, 2018
@mqliutie
Copy link

mqliutie commented Oct 14, 2021

@New-key

Set autoDownload to false and then you can call autoUdater.downloadUpdate directly.

import { CancellationToken } from "electron-updater"

const cancellationToken = new CancellationToken()
autoUdater.downloadUpdate(cancellationToken)

// stop download
cancellationToken.cancel()

I called cancellationToken.cancel(), and next time I check for udpating , download will always be cancelled.

The log file is

[2021-10-14 20:46:16.808] [info] cancelled
[2021-10-14 20:46:16.809] [error] unhandledRejection Error: cancelled

How can I make it works again

Thanks

Update:

let cancellationToken = new CancellationToken();
const downloadApp = () => {
  autoUpdater.downloadUpdate(cancellationToken)
};
const abortDownload = () => {
  cancellationToken.cancel();
  cancellationToken = new CancellationToken();
};

@shmmly
Copy link

shmmly commented Oct 21, 2021

// first checkForUpdates get cancellationToken
let cancelToken
  autoUpdater.checkForUpdates().then((res) => {
      cancelToken = res.cancellationToken;
    });

// second call downloadUpdate 
 autoUpdater.downloadUpdate(cancelToken);

// three  just call cancel to stop download
 cancelToken?.cancel();

but i can‘not find some way to remuse download ...

@mqliutie
Copy link

// first checkForUpdates get cancellationToken
let cancelToken
  autoUpdater.checkForUpdates().then((res) => {
      cancelToken = res.cancellationToken;
    });

// second call downloadUpdate 
 autoUpdater.downloadUpdate(cancelToken);

// three  just call cancel to stop download
 cancelToken?.cancel();

but i can‘not find some way to remuse download ...

Try this

let cancellationToken = new CancellationToken();
const downloadApp = () => {
  autoUpdater.downloadUpdate(cancellationToken)
};
const abortDownload = () => {
  cancellationToken.cancel();
  cancellationToken = new CancellationToken();
};

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

Successfully merging a pull request may close this issue.

8 participants