-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(electron-updater): abort download
Close #1150
- Loading branch information
Showing
73 changed files
with
495 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,108 @@ | ||
import BluebirdPromise from "bluebird-lst" | ||
import { EventEmitter } from "events" | ||
import BluebirdPromise from "bluebird-lst-c" | ||
|
||
export class CancellationToken extends EventEmitter { | ||
private parentCancelHandler: any | null = null | ||
|
||
private _cancelled: boolean | ||
get cancelled(): boolean { | ||
return this._cancelled || (this._parent != null && this._parent.cancelled) | ||
} | ||
|
||
private _parent: CancellationToken | null | ||
set parent(value: CancellationToken) { | ||
this.removeParentCancelHandler() | ||
|
||
this._parent = value | ||
this.parentCancelHandler = () => this.cancel() | ||
this._parent.onCancel(this.parentCancelHandler) | ||
} | ||
|
||
// babel cannot compile ... correctly for super calls | ||
constructor() { | ||
constructor(parent?: CancellationToken) { | ||
super() | ||
|
||
this._cancelled = false | ||
if (parent != null) { | ||
this.parent = parent | ||
} | ||
} | ||
|
||
cancel() { | ||
this._cancelled = true | ||
this.emit("cancel") | ||
} | ||
|
||
onCancel(handler: () => any) { | ||
this.once("cancel", handler) | ||
private onCancel(handler: () => any) { | ||
if (this.cancelled) { | ||
handler() | ||
} | ||
else { | ||
this.once("cancel", handler) | ||
} | ||
} | ||
|
||
trackPromise(promise: BluebirdPromise<any>): BluebirdPromise<any> { | ||
const handler = () => promise.cancel() | ||
this.onCancel(handler) | ||
// it is important to return promise, otherwise will be unhandled rejection error on reject | ||
return promise.finally(() => this.removeListener("cancel", handler)) | ||
createPromise<R>(callback: (resolve: (thenableOrResult?: R) => void, reject: (error?: any) => void, onCancel: (callback: () => void) => void) => void): Promise<R> { | ||
if (this.cancelled) { | ||
return BluebirdPromise.reject(new CancellationError()) | ||
} | ||
|
||
let cancelHandler: (() => void) | null = null | ||
return new BluebirdPromise((resolve, reject) => { | ||
let addedCancelHandler: (() => void) | null = null | ||
|
||
cancelHandler = () => { | ||
try { | ||
if (addedCancelHandler != null) { | ||
addedCancelHandler() | ||
addedCancelHandler = null | ||
} | ||
} | ||
finally { | ||
reject(new CancellationError()) | ||
} | ||
} | ||
|
||
if (this.cancelled) { | ||
cancelHandler() | ||
return | ||
} | ||
|
||
this.onCancel(cancelHandler) | ||
|
||
callback(resolve, reject, (callback: () => void) => { | ||
addedCancelHandler = callback | ||
}) | ||
}) | ||
.finally(() => { | ||
if (cancelHandler != null) { | ||
this.removeListener("cancel", cancelHandler) | ||
cancelHandler = null | ||
} | ||
}) | ||
} | ||
|
||
private removeParentCancelHandler() { | ||
const parent = this._parent | ||
if (parent != null && this.parentCancelHandler != null) { | ||
parent.removeListener("cancel", this.parentCancelHandler) | ||
this.parentCancelHandler = null | ||
} | ||
} | ||
|
||
dispose() { | ||
try { | ||
this.removeParentCancelHandler() | ||
} | ||
finally { | ||
this.removeAllListeners() | ||
this._parent = null | ||
} | ||
} | ||
} | ||
|
||
export class CancellationError extends Error { | ||
constructor() { | ||
super("Cancelled") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
packages/electron-builder-squirrel-windows/src/squirrelPack.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.