Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dad09c5

Browse files
author
Akos Kitta
committed
Close core error notification on subsequent action
Closes #1154 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 30a9de9 commit dad09c5

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

‎arduino-ide-extension/src/browser/contributions/burn-bootloader.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class BurnBootloader extends CoreServiceContribution {
2929
}
3030

3131
private async burnBootloader(): Promise<void> {
32+
this.clearVisibleNotification();
3233
const options = await this.options();
3334
try {
3435
await this.doWithProgress({

‎arduino-ide-extension/src/browser/contributions/contribution.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
5959
import { ExecuteWithProgress } from '../../common/protocol/progressible';
6060
import { BoardsServiceProvider } from '../boards/boards-service-provider';
6161
import { BoardsDataStore } from '../boards/boards-data-store';
62+
import { NotificationManager } from '../theia/messages/notifications-manager';
63+
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
6264

6365
export {
6466
Command,
@@ -186,6 +188,22 @@ export abstract class CoreServiceContribution extends SketchContribution {
186188
@inject(ResponseServiceClient)
187189
private readonly responseService: ResponseServiceClient;
188190

191+
@inject(NotificationManager)
192+
private readonly notificationManager: NotificationManager;
193+
194+
/**
195+
* This is the internal (Theia) ID of the notification that is currently visible.
196+
* It's stored here as a field to be able to close it before executing any new core command (such as verify, upload, etc.)
197+
*/
198+
private visibleNotificationId: string | undefined;
199+
200+
protected clearVisibleNotification(): void {
201+
if (this.visibleNotificationId) {
202+
this.notificationManager.clear(this.visibleNotificationId);
203+
this.visibleNotificationId = undefined;
204+
}
205+
}
206+
189207
protected handleError(error: unknown): void {
190208
this.tryToastErrorMessage(error);
191209
}
@@ -208,6 +226,7 @@ export abstract class CoreServiceContribution extends SketchContribution {
208226
'arduino/coreContribution/copyError',
209227
'Copy error messages'
210228
);
229+
this.visibleNotificationId = this.notificationId(message, copyAction);
211230
this.messageService.error(message, copyAction).then(async (action) => {
212231
if (action === copyAction) {
213232
const content = await this.outputChannelManager.contentOfChannel(
@@ -241,6 +260,14 @@ export abstract class CoreServiceContribution extends SketchContribution {
241260
});
242261
return result;
243262
}
263+
264+
private notificationId(message: string, ...actions: string[]): string {
265+
return this.notificationManager.getMessageId({
266+
text: message,
267+
actions,
268+
type: MessageType.Error,
269+
});
270+
}
244271
}
245272

246273
export namespace Contribution {

‎arduino-ide-extension/src/browser/contributions/upload-sketch.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class UploadSketch extends CoreServiceContribution {
191191
// uploadInProgress will be set to false whether the upload fails or not
192192
this.uploadInProgress = true;
193193
this.onDidChangeEmitter.fire();
194+
this.clearVisibleNotification();
194195

195196
const verifyOptions =
196197
await this.commandService.executeCommand<CoreService.Options.Compile>(

‎arduino-ide-extension/src/browser/contributions/verify-sketch.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class VerifySketch extends CoreServiceContribution {
108108
this.verifyInProgress = true;
109109
this.onDidChangeEmitter.fire();
110110
}
111+
this.clearVisibleNotification();
111112
this.coreErrorHandler.reset();
112113

113114
const options = await this.options(params?.exportBinaries);

‎arduino-ide-extension/src/browser/theia/messages/notifications-manager.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { injectable } from '@theia/core/shared/inversify';
21
import { CancellationToken } from '@theia/core/lib/common/cancellation';
3-
import {
2+
import type {
3+
Message,
44
ProgressMessage,
55
ProgressUpdate,
66
} from '@theia/core/lib/common/message-service-protocol';
7+
import { injectable } from '@theia/core/shared/inversify';
78
import { NotificationManager as TheiaNotificationManager } from '@theia/messages/lib/browser/notifications-manager';
89

910
@injectable()
@@ -34,7 +35,9 @@ export class NotificationManager extends TheiaNotificationManager {
3435
this.fireUpdatedEvent();
3536
}
3637

37-
protected override toPlainProgress(update: ProgressUpdate): number | undefined {
38+
protected override toPlainProgress(
39+
update: ProgressUpdate
40+
): number | undefined {
3841
if (!update.work) {
3942
return undefined;
4043
}
@@ -43,4 +46,11 @@ export class NotificationManager extends TheiaNotificationManager {
4346
}
4447
return Math.min((update.work.done / update.work.total) * 100, 100);
4548
}
49+
50+
/**
51+
* For `public` visibility.
52+
*/
53+
override getMessageId(message: Message): string {
54+
return super.getMessageId(message);
55+
}
4656
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /