@@ -59,6 +59,8 @@ import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
59
59
import { ExecuteWithProgress } from '../../common/protocol/progressible' ;
60
60
import { BoardsServiceProvider } from '../boards/boards-service-provider' ;
61
61
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' ;
62
64
63
65
export {
64
66
Command ,
@@ -186,6 +188,22 @@ export abstract class CoreServiceContribution extends SketchContribution {
186
188
@inject ( ResponseServiceClient )
187
189
private readonly responseService : ResponseServiceClient ;
188
190
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
+
189
207
protected handleError ( error : unknown ) : void {
190
208
this . tryToastErrorMessage ( error ) ;
191
209
}
@@ -208,6 +226,7 @@ export abstract class CoreServiceContribution extends SketchContribution {
208
226
'arduino/coreContribution/copyError' ,
209
227
'Copy error messages'
210
228
) ;
229
+ this . visibleNotificationId = this . notificationId ( message , copyAction ) ;
211
230
this . messageService . error ( message , copyAction ) . then ( async ( action ) => {
212
231
if ( action === copyAction ) {
213
232
const content = await this . outputChannelManager . contentOfChannel (
@@ -241,6 +260,14 @@ export abstract class CoreServiceContribution extends SketchContribution {
241
260
} ) ;
242
261
return result ;
243
262
}
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
+ }
244
271
}
245
272
246
273
export namespace Contribution {
0 commit comments