Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de3794a

Browse files
author
Akos Kitta
committed
fix: update monitor settings only if it's changed
Closes #375 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent bfcb518 commit de3794a

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

‎arduino-ide-extension/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"dateformat": "^3.0.3",
6969
"deepmerge": "2.0.1",
7070
"electron-updater": "^4.6.5",
71+
"fast-json-stable-stringify": "^2.1.0",
7172
"fast-safe-stringify": "^2.1.1",
7273
"glob": "^7.1.6",
7374
"google-protobuf": "^3.20.1",

‎arduino-ide-extension/src/common/utils.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import stableJsonStringify = require('fast-json-stable-stringify');
2+
13
export const naturalCompare: (left: string, right: string) => number =
24
require('string-natural-compare').caseInsensitive;
35

@@ -13,6 +15,19 @@ export function firstToUpperCase(what: string): string {
1315
return what.charAt(0).toUpperCase() + what.slice(1);
1416
}
1517

16-
export function isNullOrUndefined(what: any): what is undefined | null {
18+
export function isNullOrUndefined(what: unknown): what is undefined | null {
1719
return what === undefined || what === null;
1820
}
21+
22+
export function sameAs(left: unknown, right: unknown): boolean {
23+
if (left === right) {
24+
return true;
25+
}
26+
if (!left) {
27+
return right === undefined;
28+
}
29+
if (!right) {
30+
return false;
31+
}
32+
return stableJsonStringify(left) === stableJsonStringify(right);
33+
}

‎arduino-ide-extension/src/node/monitor-service.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
491491
*/
492492
async changeSettings(settings: MonitorSettings): Promise<Status> {
493493
const config = new MonitorPortConfiguration();
494-
const { pluggableMonitorSettings } = settings;
494+
const { pluggableMonitorSettings ={}} = settings;
495495
const reconciledSettings = await this.monitorSettingsProvider.setSettings(
496496
this.monitorID,
497-
pluggableMonitorSettings||{}
497+
pluggableMonitorSettings
498498
);
499499

500500
if (reconciledSettings) {
@@ -512,9 +512,13 @@ export class MonitorService extends CoreClientAware implements Disposable {
512512
connected: !!this.duplex,
513513
serialPort: this.port.address,
514514
},
515-
pluggableMonitorSettings: reconciledSettings,
515+
pluggableMonitorSettings: reconciledSettings??pluggableMonitorSettings,
516516
});
517517

518+
if (!reconciledSettings) {
519+
return Status.OK;
520+
}
521+
518522
if (!this.duplex) {
519523
return Status.NOT_CONNECTED;
520524
}

‎arduino-ide-extension/src/node/monitor-settings/monitor-settings-provider-impl.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
longestPrefixMatch,
1818
reconcileSettings,
1919
} from './monitor-settings-utils';
20-
import { ILogger } from '@theia/core';
20+
import { deepClone, ILogger } from '@theia/core';
21+
import { sameAs } from '../../common/utils';
2122

2223
const MONITOR_SETTINGS_FILE = 'pluggable-monitor-settings.json';
2324

@@ -74,14 +75,17 @@ export class MonitorSettingsProviderImpl implements MonitorSettingsProvider {
7475
async setSettings(
7576
monitorId: string,
7677
settings: PluggableMonitorSettings
77-
): Promise<PluggableMonitorSettings> {
78+
): Promise<PluggableMonitorSettings|undefined> {
7879
// wait for the service to complete the init
7980
await this.ready.promise;
8081

81-
const newSettings = this.reconcileSettings(
82-
settings,
83-
this.monitorSettings[monitorId] || {}
84-
);
82+
const defaultSettings = this.monitorSettings[monitorId] || {};
83+
const oldSettings = deepClone(defaultSettings);
84+
const newSettings = this.reconcileSettings(settings, defaultSettings);
85+
if (sameAs(oldSettings, newSettings)) {
86+
// NOOP if no settings change. The `undefined` return value represents this case.
87+
return undefined;
88+
}
8589
this.monitorSettings[monitorId] = newSettings;
8690

8791
await this.writeSettingsToFS();

‎arduino-ide-extension/src/node/monitor-settings/monitor-settings-provider.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { MonitorModel } from '../../browser/monitor-model';
2-
import { PluggableMonitorSetting } from '../../common/protocol';
1+
import type{ MonitorModel } from '../../browser/monitor-model';
2+
import type{ PluggableMonitorSetting } from '../../common/protocol';
33

44
export type PluggableMonitorSettings = Record<string, PluggableMonitorSetting>;
55
export interface MonitorSettings {
@@ -13,8 +13,12 @@ export interface MonitorSettingsProvider {
1313
monitorId: string,
1414
defaultSettings: PluggableMonitorSettings
1515
): Promise<PluggableMonitorSettings>;
16+
/**
17+
* The promise resolves to `undefined` if no settings change we performed. Otherwise, the reconciled settings value.
18+
*/
19+
// TODO: find a better name for this method
1620
setSettings(
1721
monitorId: string,
1822
settings: PluggableMonitorSettings
19-
): Promise<PluggableMonitorSettings>;
23+
): Promise<PluggableMonitorSettings|undefined>;
2024
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /