Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7efc4c8

Browse files
author
Akos Kitta
committedDec 16, 2022
fix: removed unused client API
Signed-off-by: Akos Kitta <[email protected]>
1 parent ca78c52 commit 7efc4c8

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed
 

‎arduino-ide-extension/src/browser/config/config-service-client.ts

+18-29
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
injectable,
1111
postConstruct,
1212
} from '@theia/core/shared/inversify';
13-
import { Config, ConfigService, ConfigState } from '../../common/protocol';
13+
import { ConfigService, ConfigState } from '../../common/protocol';
1414
import { NotificationCenter } from '../notification-center';
1515

1616
@injectable()
@@ -33,7 +33,7 @@ export class ConfigServiceClient implements FrontendApplicationContribution {
3333
this.didChangeDataDirUriEmitter
3434
);
3535

36-
private _config: ConfigState | undefined;
36+
private config: ConfigState | undefined;
3737

3838
@postConstruct()
3939
protected init(): void {
@@ -63,53 +63,42 @@ export class ConfigServiceClient implements FrontendApplicationContribution {
6363
return this.delegate.getConfiguration();
6464
}
6565

66-
tryGetConfig(): Config | undefined {
67-
return this._config?.config;
68-
}
69-
66+
/**
67+
* CLI config related error messages if any.
68+
*/
7069
tryGetMessages(): string[] | undefined {
71-
return this._config?.messages;
70+
return this.config?.messages;
7271
}
7372

7473
/**
7574
* `directories.user`
7675
*/
7776
tryGetSketchDirUri(): URI | undefined {
78-
return this._config?.config?.sketchDirUri
79-
? new URI(this._config?.config?.sketchDirUri)
77+
return this.config?.config?.sketchDirUri
78+
? new URI(this.config?.config?.sketchDirUri)
8079
: undefined;
8180
}
8281

8382
/**
8483
* `directories.data`
8584
*/
8685
tryGetDataDirUri(): URI | undefined {
87-
return this._config?.config?.dataDirUri
88-
? new URI(this._config?.config?.dataDirUri)
86+
return this.config?.config?.dataDirUri
87+
? new URI(this.config?.config?.dataDirUri)
8988
: undefined;
9089
}
9190

9291
private use(config: ConfigState): void {
93-
const oldConfig = deepClone(this._config);
94-
this._config = config;
95-
if (oldConfig?.config?.dataDirUri !== this._config?.config?.dataDirUri) {
96-
this.didChangeDataDirUriEmitter.fire(
97-
this._config.config?.dataDirUri
98-
? new URI(this._config.config.dataDirUri)
99-
: undefined
100-
);
92+
const oldConfig = deepClone(this.config);
93+
this.config = config;
94+
if (oldConfig?.config?.sketchDirUri !== this.config?.config?.sketchDirUri) {
95+
this.didChangeSketchDirUriEmitter.fire(this.tryGetSketchDirUri());
10196
}
102-
if (
103-
oldConfig?.config?.sketchDirUri !== this._config?.config?.sketchDirUri
104-
) {
105-
this.didChangeSketchDirUriEmitter.fire(
106-
this._config.config?.sketchDirUri
107-
? new URI(this._config.config.sketchDirUri)
108-
: undefined
109-
);
97+
if (oldConfig?.config?.dataDirUri !== this.config?.config?.dataDirUri) {
98+
this.didChangeDataDirUriEmitter.fire(this.tryGetDataDirUri());
11099
}
111-
if (this._config.messages?.length) {
112-
const message = this._config.messages.join(' ');
100+
if (this.config.messages?.length) {
101+
const message = this.config.messages.join(' ');
113102
// toast the error later otherwise it might not show up in IDE2
114103
setTimeout(() => this.messageService.error(message), 1_000);
115104
}

‎arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,15 @@ export class SketchesServiceClientImpl
6666
private currentSketchLoaded = new Deferred<CurrentSketch>();
6767

6868
onStart(): void {
69-
const config = this.configService.tryGetConfig();
70-
if (config) {
71-
this.watchSketchbookDir(config.sketchDirUri);
72-
}
69+
const sketchDirUri = this.configService.tryGetSketchDirUri();
70+
this.watchSketchbookDir(sketchDirUri);
7371
const refreshCurrentSketch = async () => {
7472
const currentSketch = await this.loadCurrentSketch();
7573
this.useCurrentSketch(currentSketch);
7674
};
7775
this.toDispose.push(
7876
this.configService.onDidChangeSketchDirUri((sketchDirUri) => {
79-
this.watchSketchbookDir(sketchDirUri?.toString());
77+
this.watchSketchbookDir(sketchDirUri);
8078
refreshCurrentSketch();
8179
})
8280
);
@@ -86,23 +84,22 @@ export class SketchesServiceClientImpl
8684
}
8785

8886
private async watchSketchbookDir(
89-
sketchDirUri: string | undefined
87+
sketchDirUri: URI | undefined
9088
): Promise<void> {
9189
this.toDisposeBeforeWatchSketchbookDir.dispose();
9290
if (!sketchDirUri) {
9391
return;
9492
}
9593
const container = await this.sketchService.getSketches({
96-
uri: sketchDirUri,
94+
uri: sketchDirUri.toString(),
9795
});
98-
const sketchbookUri = new URI(sketchDirUri);
9996
for (const sketch of SketchContainer.toArray(container)) {
10097
this.sketches.set(sketch.uri, sketch);
10198
}
10299
this.toDisposeBeforeWatchSketchbookDir.pushAll([
103100
Disposable.create(() => this.sketches.clear()),
104101
// Watch changes in the sketchbook to update `File` > `Sketchbook` menu items.
105-
this.fileService.watch(new URI(sketchDirUri), {
102+
this.fileService.watch(sketchDirUri, {
106103
recursive: true,
107104
excludes: [],
108105
}),
@@ -145,7 +142,7 @@ export class SketchesServiceClientImpl
145142
return;
146143
}
147144
// We track main sketch files changes only. // TODO: check sketch folder changes. One can rename the folder without renaming the `.ino` file.
148-
if (sketchbookUri.isEqualOrParent(resource)) {
145+
if (sketchDirUri.isEqualOrParent(resource)) {
149146
if (Sketch.isSketchFile(resource)) {
150147
if (type === FileChangeType.ADDED) {
151148
try {
@@ -165,7 +162,7 @@ export class SketchesServiceClientImpl
165162
const toDelete = this.sketches.get(uri);
166163
if (toDelete) {
167164
console.log(
168-
`Sketch '${toDelete.name}' was removed from sketchbook '${sketchbookUri}'.`
165+
`Sketch '${toDelete.name}' was removed from sketchbook '${sketchDirUri}'.`
169166
);
170167
this.sketches.delete(uri);
171168
this.fireSoon(toDelete, 'removed');

0 commit comments

Comments
 (0)
Please sign in to comment.