Skip to content

Commit 5b1e826

Browse files
author
Akos Kitta
committed
do not show error notification on sketch restore
Signed-off-by: Akos Kitta <[email protected]>
1 parent 77b9efa commit 5b1e826

File tree

5 files changed

+27
-130
lines changed

5 files changed

+27
-130
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ import { StartupTasks } from './widgets/sketchbook/startup-task';
304304
import { IndexesUpdateProgress } from './contributions/indexes-update-progress';
305305
import { Daemon } from './contributions/daemon';
306306
import { FirstStartupInstaller } from './contributions/first-startup-installer';
307-
import { Notifications } from './contributions/notifications';
308307
import { OpenSketchFiles } from './contributions/open-sketch-files';
309308
import { InoLanguage } from './contributions/ino-language';
310309
import { SelectedBoard } from './contributions/selected-board';
@@ -705,7 +704,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
705704
Contribution.configure(bind, Daemon);
706705
Contribution.configure(bind, FirstStartupInstaller);
707706
Contribution.configure(bind, StartupTasks);
708-
Contribution.configure(bind, Notifications);
709707
Contribution.configure(bind, OpenSketchFiles);
710708
Contribution.configure(bind, InoLanguage);
711709
Contribution.configure(bind, SelectedBoard);

arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx

+22-23
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import * as ReactDOM from '@theia/core/shared/react-dom';
33
import { CommandRegistry } from '@theia/core/lib/common/command';
44
import { DisposableCollection } from '@theia/core/lib/common/disposable';
55
import { Port } from '../../common/protocol';
6-
import { BoardsConfig } from './boards-config';
6+
import { OpenBoardsConfig } from '../contributions/open-boards-config';
77
import {
88
BoardsServiceProvider,
99
AvailableBoard,
1010
} from './boards-service-provider';
1111
import { nls } from '@theia/core/lib/common';
1212
import classNames from 'classnames';
13-
import { OpenBoardsConfig } from '../contributions/open-boards-config';
1413

1514
export interface BoardsDropDownListCoords {
1615
readonly top: number;
@@ -177,7 +176,7 @@ export class BoardsToolBarItem extends React.Component<
177176
this.toDispose.dispose();
178177
}
179178

180-
protected readonly show = (event: React.MouseEvent<HTMLElement>) => {
179+
protected readonly show = (event: React.MouseEvent<HTMLElement>): void => {
181180
const { currentTarget: element } = event;
182181
if (element instanceof HTMLElement) {
183182
if (this.state.coords === 'hidden') {
@@ -200,23 +199,24 @@ export class BoardsToolBarItem extends React.Component<
200199

201200
override render(): React.ReactNode {
202201
const { coords, availableBoards } = this.state;
203-
const boardsConfig = this.props.boardsServiceProvider.boardsConfig;
204-
const title = BoardsConfig.Config.toString(boardsConfig, {
205-
default: nls.localize(
206-
'arduino/common/noBoardSelected',
207-
'No board selected'
208-
),
209-
});
210-
const decorator = (() => {
211-
const selectedBoard = availableBoards.find(({ selected }) => selected);
212-
if (!selectedBoard || !selectedBoard.port) {
213-
return 'fa fa-times notAttached';
214-
}
215-
if (selectedBoard.state === AvailableBoard.State.guessed) {
216-
return 'fa fa-exclamation-triangle guessed';
217-
}
218-
return '';
219-
})();
202+
const selectedBoard = availableBoards.find(({ selected }) => selected);
203+
204+
const boardLabel =
205+
selectedBoard?.name ||
206+
nls.localize('arduino/board/selectBoard', 'Select Board');
207+
const selectedPortLabel = portLabel(selectedBoard?.port?.address);
208+
209+
const isConnected = Boolean(
210+
selectedBoard && AvailableBoard.hasPort(selectedBoard)
211+
);
212+
const protocolIcon = isConnected
213+
? iconNameFromProtocol(selectedBoard?.port?.protocol || '')
214+
: null;
215+
const protocolIconClassNames = classNames(
216+
'arduino-boards-toolbar-item--protocol',
217+
'fa',
218+
protocolIcon
219+
);
220220

221221
return (
222222
<React.Fragment>
@@ -225,7 +225,7 @@ export class BoardsToolBarItem extends React.Component<
225225
title={selectedPortLabel}
226226
onClick={this.show}
227227
>
228-
{protocolIcon && <div className={procolIconClassNames} />}
228+
{protocolIcon && <div className={protocolIconClassNames} />}
229229
<div
230230
className={classNames(
231231
'arduino-boards-toolbar-item--label',
@@ -264,11 +264,10 @@ export class BoardsToolBarItem extends React.Component<
264264
);
265265
}
266266

267-
protected openDialog = () => {
267+
protected openDialog = (): void => {
268268
this.props.commands.executeCommand(
269269
OpenBoardsConfig.Commands.OPEN_DIALOG.id
270270
);
271-
this.setState({ coords: 'hidden' });
272271
};
273272
}
274273
export namespace BoardsToolBarItem {

arduino-ide-extension/src/browser/contributions/notifications.ts

-52
This file was deleted.

arduino-ide-extension/src/browser/contributions/open-sketch-files.ts

+3-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ApplicationError } from '@theia/core/lib/common/application-error';
21
import { nls } from '@theia/core/lib/common/nls';
32
import { injectable } from '@theia/core/shared/inversify';
43
import type { EditorOpenerOptions } from '@theia/editor/lib/browser/editor-manager';
@@ -9,7 +8,6 @@ import {
98
SketchContribution,
109
URI,
1110
} from './contribution';
12-
import { Notifications } from './notifications';
1311
import { SaveAsSketch } from './save-as-sketch';
1412

1513
@injectable()
@@ -60,7 +58,7 @@ export class OpenSketchFiles extends SketchContribution {
6058
}
6159
} catch (err) {
6260
if (SketchesError.NotFound.is(err)) {
63-
this.openFallbackSketch(err);
61+
this.openFallbackSketch();
6462
} else {
6563
console.error(err);
6664
const message =
@@ -74,36 +72,9 @@ export class OpenSketchFiles extends SketchContribution {
7472
}
7573
}
7674

77-
private async openFallbackSketch(
78-
err: ApplicationError<
79-
number,
80-
{
81-
uri: string;
82-
}
83-
>
84-
): Promise<void> {
75+
private async openFallbackSketch(): Promise<void> {
8576
const sketch = await this.sketchService.createNewSketch();
86-
this.workspaceService.open(
87-
new URI(sketch.uri),
88-
Object.assign(
89-
{
90-
preserveWindow: true,
91-
},
92-
{
93-
tasks: [
94-
{
95-
command: Notifications.Commands.NOTIFY.id,
96-
args: [
97-
{
98-
type: 'error',
99-
message: err.message,
100-
},
101-
],
102-
},
103-
],
104-
}
105-
)
106-
);
77+
this.workspaceService.open(new URI(sketch.uri), { preserveWindow: true });
10778
}
10879

10980
private async ensureOpened(

arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { ConfigService } from '../../../common/protocol/config-service';
1717
import {
1818
SketchesService,
1919
Sketch,
20-
SketchesError,
2120
} from '../../../common/protocol/sketches-service';
2221
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
2322
import { BoardsConfig } from '../../boards/boards-config';
@@ -70,30 +69,12 @@ export class WorkspaceService extends TheiaWorkspaceService {
7069
): Promise<FileStat | undefined> {
7170
const stat = await super.toFileStat(uri);
7271
if (!stat) {
73-
return this.toFileStatWithNewSketchFallback(uri);
72+
const newSketchUri = await this.sketchService.createNewSketch();
73+
return this.toFileStat(newSketchUri.uri);
7474
}
7575
return stat;
7676
}
7777

78-
private async toFileStatWithNewSketchFallback(
79-
uri: string | URI | undefined
80-
): Promise<FileStat | undefined> {
81-
if (!uri) {
82-
return;
83-
}
84-
try {
85-
await this.sketchService.loadSketch(
86-
uri instanceof URI ? uri.toString() : uri
87-
);
88-
} catch (err) {
89-
if (SketchesError.NotFound.is(err)) {
90-
this.messageService.error(err.message);
91-
}
92-
}
93-
const newSketchUri = await this.sketchService.createNewSketch();
94-
return this.toFileStat(newSketchUri.uri);
95-
}
96-
9778
// Was copied from the Theia implementation.
9879
// Unlike the default behavior, IDE2 does not check the existence of the workspace before open.
9980
protected override async doGetDefaultWorkspaceUri(): Promise<

0 commit comments

Comments
 (0)