-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDE2 falls back to new sketch if opening failed.
Closes #1089 Signed-off-by: Akos Kitta <[email protected]>
- Loading branch information
Akos Kitta
committed
Jul 8, 2022
1 parent
d7a2d83
commit e77b972
Showing
12 changed files
with
345 additions
and
81 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
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
52 changes: 52 additions & 0 deletions
52
arduino-ide-extension/src/browser/contributions/notifications.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { Command, CommandRegistry, Contribution } from './contribution'; | ||
|
||
@injectable() | ||
export class Notifications extends Contribution { | ||
override registerCommands(registry: CommandRegistry): void { | ||
registry.registerCommand(Notifications.Commands.NOTIFY, { | ||
execute: (arg) => { | ||
if (NotifyParams.is(arg)) { | ||
switch (arg.type) { | ||
case 'info': | ||
return this.messageService.info(arg.message); | ||
case 'warn': | ||
return this.messageService.warn(arg.message); | ||
case 'error': | ||
return this.messageService.error(arg.message); | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
export namespace Notifications { | ||
export namespace Commands { | ||
export const NOTIFY: Command = { | ||
id: 'arduino-notify', | ||
}; | ||
} | ||
} | ||
const TypeLiterals = ['info', 'warn', 'error'] as const; | ||
export type Type = typeof TypeLiterals[number]; | ||
interface NotifyParams { | ||
readonly type: Type; | ||
readonly message: string; | ||
} | ||
namespace NotifyParams { | ||
export function is(arg: unknown): arg is NotifyParams { | ||
if (typeof arg === 'object') { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const object = arg as any; | ||
return ( | ||
'message' in object && | ||
'type' in object && | ||
typeof object['message'] === 'string' && | ||
typeof object['type'] === 'string' && | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
TypeLiterals.includes(object['type'] as any) | ||
); | ||
} | ||
return false; | ||
} | ||
} |
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.