Skip to content

Commit

Permalink
Update dialog: add Cancel button #428
Browse files Browse the repository at this point in the history
  • Loading branch information
jfaltermeier committed Dec 12, 2024
1 parent 58c7f43 commit 92908fd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions theia-extensions/updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@theia/core": "1.55.0",
"@theia/output": "1.55.0",
"@theia/preferences": "1.55.0",
"builder-util-runtime": "9.1.1",
"electron-log": "^4.3.0",
"electron-updater": "5.3.0",
"fs-extra": "^10.0.0",
Expand Down
2 changes: 2 additions & 0 deletions theia-extensions/updater/src/common/updater/theia-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TheiaUpdater extends JsonRpcServer<TheiaUpdaterClient> {
onRestartToUpdateRequested(): void;
disconnectClient(client: TheiaUpdaterClient): void;
setUpdateChannel(channel: string): void;
cancel(): void;
}

export const TheiaUpdaterClient = Symbol('TheiaUpdaterClient');
Expand All @@ -30,4 +31,5 @@ export interface TheiaUpdaterClient {
updateAvailable(available: boolean, startupCheck: boolean): void;
notifyReadyToInstall(): void;
reportError(error: UpdaterError): void;
reportCancelled(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export class TheiaUpdaterClientImpl implements TheiaUpdaterClient {
protected readonly onErrorEmitter = new Emitter<UpdaterError>();
readonly onError = this.onErrorEmitter.event;

protected readonly onCancelEmitter = new Emitter<void>();
readonly onCancel = this.onCancelEmitter.event;

notifyReadyToInstall(): void {
this.onReadyToInstallEmitter.fire();
}
Expand Down Expand Up @@ -89,6 +92,10 @@ export class TheiaUpdaterClientImpl implements TheiaUpdaterClient {
this.onErrorEmitter.fire(error);
}

reportCancelled(): void {
this.onCancelEmitter.fire();
}

}

// Dynamic menus aren't yet supported by electron: https://github.com/eclipse-theia/theia/issues/446
Expand Down Expand Up @@ -158,6 +165,7 @@ export class TheiaUpdaterFrontendContribution implements CommandContribution, Me
});

this.updaterClient.onError(error => this.handleError(error));
this.updaterClient.onCancel(() => this.stopProgress());
}

registerCommands(registry: CommandRegistry): void {
Expand Down Expand Up @@ -194,7 +202,7 @@ export class TheiaUpdaterFrontendContribution implements CommandContribution, Me
this.stopProgress();
this.progress = await this.messageService.showProgress({
text: 'Theia IDE Update'
});
}, () => this.updater.cancel());
let dots = 0;
this.intervalId = setInterval(() => {
if (this.progress !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ElectronMainApplication, ElectronMainApplicationContribution } from '@t
import { TheiaUpdater, TheiaUpdaterClient } from '../../common/updater/theia-updater';
import { injectable } from '@theia/core/shared/inversify';
import { isOSX, isWindows } from '@theia/core';
import { CancellationToken } from "builder-util-runtime";

const STABLE_CHANNEL_WINDOWS = 'https://download.eclipse.org/theia/ide/version/windows';
const STABLE_CHANNEL_MACOS = 'https://download.eclipse.org/theia/ide/latest/macos';
Expand All @@ -37,6 +38,7 @@ export class TheiaUpdaterImpl implements TheiaUpdater, ElectronMainApplicationCo
private initialCheck: boolean = true;
private updateChannelReported: boolean = false;
private reportOnFirstRegistration: boolean = false;
private cancellationToken: CancellationToken = new CancellationToken();

constructor() {
autoUpdater.autoDownload = false;
Expand Down Expand Up @@ -81,8 +83,14 @@ export class TheiaUpdaterImpl implements TheiaUpdater, ElectronMainApplicationCo
autoUpdater.quitAndInstall();
}

cancel(): void {
this.cancellationToken.cancel();
this.clients.forEach(c => c.reportCancelled());
}

downloadUpdate(): void {
autoUpdater.downloadUpdate();
this.cancellationToken = new CancellationToken();
autoUpdater.downloadUpdate(this.cancellationToken);

// record download stat, ignore errors
fs.mkdtemp(path.join(os.tmpdir(), 'updater-'))
Expand Down

0 comments on commit 92908fd

Please sign in to comment.