Skip to content

Commit

Permalink
Fix cancellable option for withProgress
Browse files Browse the repository at this point in the history
also cleaned up unused `NotificationMain.$startProgress` options.

Fixes eclipse-theia#5578

Signed-off-by: Alex Tugarev <alex.tugarev@typefox.io>
  • Loading branch information
AlexTugarev authored and akosyakov committed Feb 24, 2020
1 parent 7637bb4 commit 013f7ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,15 @@ export interface DecorationProvider {
}

export interface NotificationMain {
$startProgress(options: string | NotificationMain.StartProgressOptions): Promise<string>;
$startProgress(options: NotificationMain.StartProgressOptions): Promise<string>;
$stopProgress(id: string): void;
$updateProgress(id: string, report: NotificationMain.ProgressReport): void;
}
export namespace NotificationMain {
export interface StartProgressOptions {
title: string;
location?: string;
cancellable?: boolean;
}
export interface ProgressReport {
message?: string;
Expand Down
9 changes: 4 additions & 5 deletions packages/plugin-ext/src/main/browser/notification-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class NotificationMainImpl implements NotificationMain, Disposable {
this.toDispose.dispose();
}

async $startProgress(options: string | NotificationMain.StartProgressOptions): Promise<string> {
async $startProgress(options: NotificationMain.StartProgressOptions): Promise<string> {
const progressMessage = this.mapOptions(options);
const progress = await this.progressService.showProgress(progressMessage);
const id = progress.id;
Expand All @@ -51,10 +51,9 @@ export class NotificationMainImpl implements NotificationMain, Disposable {
}
return id;
}
protected mapOptions(options: string | NotificationMain.StartProgressOptions): ProgressMessage {
const text = typeof options === 'string' ? options : options.title;
const location = typeof options === 'string' ? 'notification' : options.location;
return { text, options: { location, cancelable: true } };
protected mapOptions(options: NotificationMain.StartProgressOptions): ProgressMessage {
const { title, location, cancellable } = options;
return { text: title, options: { location, cancelable: cancellable } };
}

$stopProgress(id: string): void {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class NotificationExtImpl implements NotificationExt {
const progress = task({ report: async item => this.proxy.$updateProgress(await id.promise, item)}, tokenSource.token);
const title = options.title ? options.title : '';
const location = this.mapLocation(options.location);
id.resolve(await this.proxy.$startProgress({ title, location }));
const cancellable = options.cancellable;
id.resolve(await this.proxy.$startProgress({ title, location, cancellable }));
const stop = async () => this.proxy.$stopProgress(await id.promise);
const promise = Promise.all([
progress,
Expand Down

0 comments on commit 013f7ed

Please sign in to comment.