Skip to content

Commit 45f6c4b

Browse files
author
Akos Kitta
committed
fix: update index if 3rd party URLs have changed
Signed-off-by: Akos Kitta <[email protected]>
1 parent b0fa4c3 commit 45f6c4b

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

arduino-ide-extension/src/common/protocol/config-service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,16 @@ export namespace AdditionalUrls {
160160
export function stringify(additionalUrls: AdditionalUrls): string {
161161
return additionalUrls.join(',');
162162
}
163-
export function sameAs(left: AdditionalUrls, right: AdditionalUrls): boolean {
163+
export function sameAs(
164+
left: AdditionalUrls | undefined,
165+
right: AdditionalUrls | undefined
166+
): boolean {
167+
if (!left) {
168+
return !right;
169+
}
170+
if (!right) {
171+
return false;
172+
}
164173
if (left.length !== right.length) {
165174
return false;
166175
}

arduino-ide-extension/src/node/config-service-impl.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ export class ConfigServiceImpl
5555
],
5656
};
5757
private cliConfig: DefaultCliConfig | undefined;
58-
/**
59-
* An array of errors occurred during the loading and mapping of the CLI configuration.
60-
* If empty, IDE2 neither noticed any problems nor received any errors from the services.
61-
* The purpose of this array is to store the messages of all errors that were caught during
62-
* the initialization. It's not sufficient to broadcast the messages when they are caught because,
63-
* at that time, no client might exist.
64-
*/
65-
private _configErrors: string[] = [];
6658
private ready = new Deferred<void>();
67-
private readonly configChangeEmitter = new Emitter<ConfigState>();
59+
private readonly configChangeEmitter = new Emitter<{
60+
oldState: ConfigState;
61+
newState: ConfigState;
62+
}>();
6863

6964
onStart(): void {
7065
this.initConfig();
@@ -86,6 +81,7 @@ export class ConfigServiceImpl
8681
if (Config.sameAs(this._configState.config, config)) {
8782
return;
8883
}
84+
const oldConfigState = deepClone(this._configState);
8985
let copyDefaultCliConfig: DefaultCliConfig | undefined = deepClone(
9086
this.cliConfig
9187
);
@@ -115,26 +111,25 @@ export class ConfigServiceImpl
115111
try {
116112
await this.validateCliConfig(this.cliConfig);
117113
delete this._configState.messages;
118-
this.fireConfigChanged(this._configState);
114+
this.fireConfigChanged(oldConfigState, this._configState);
119115
} catch (err) {
120116
if (err instanceof InvalidConfigError) {
121117
this._configState.messages = err.errors;
122-
this.fireConfigChanged(this._configState);
118+
this.fireConfigChanged(oldConfigState, this._configState);
123119
} else {
124120
throw err;
125121
}
126122
}
127123
}
128124

129-
async configErrors(): Promise<string[]> {
130-
return this._configErrors;
131-
}
132-
133125
get cliConfiguration(): DefaultCliConfig | undefined {
134126
return this.cliConfig;
135127
}
136128

137-
get onConfigChange(): Event<ConfigState> {
129+
get onConfigChange(): Event<{
130+
oldState: ConfigState;
131+
newState: ConfigState;
132+
}> {
138133
return this.configChangeEmitter.event;
139134
}
140135

@@ -235,9 +230,12 @@ export class ConfigServiceImpl
235230
};
236231
}
237232

238-
private fireConfigChanged(configState: ConfigState): void {
239-
this.configChangeEmitter.fire(configState);
240-
this.notificationService.notifyConfigDidChange(configState);
233+
private fireConfigChanged(
234+
oldState: ConfigState,
235+
newState: ConfigState
236+
): void {
237+
this.configChangeEmitter.fire({ oldState, newState });
238+
this.notificationService.notifyConfigDidChange(newState);
241239
}
242240

243241
private async validateCliConfig(config: DefaultCliConfig): Promise<void> {

arduino-ide-extension/src/node/core-client-provider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
IndexUpdateDidFailParams,
2626
IndexUpdateWillStartParams,
2727
NotificationServiceServer,
28+
AdditionalUrls,
2829
} from '../common/protocol';
2930
import { Deferred } from '@theia/core/lib/common/promise-util';
3031
import {
@@ -75,9 +76,15 @@ export class CoreClientProvider {
7576
});
7677
this.daemon.onDaemonStarted((port) => this.create(port));
7778
this.daemon.onDaemonStopped(() => this.closeClient());
78-
this.configService.onConfigChange(
79-
() => this.client.then((client) => this.updateIndex(client, ['platform'])) // Assuming 3rd party URL changes. No library index update is required.
80-
);
79+
this.configService.onConfigChange(({ oldState, newState }) => {
80+
if (
81+
AdditionalUrls.sameAs(
82+
oldState.config?.additionalUrls,
83+
newState.config?.additionalUrls
84+
)
85+
)
86+
this.client.then((client) => this.updateIndex(client, ['platform']));
87+
});
8188
}
8289

8390
get tryGetClient(): CoreClientProvider.Client | undefined {

0 commit comments

Comments
 (0)