File tree 5 files changed +41
-13
lines changed
5 files changed +41
-13
lines changed Original file line number Diff line number Diff line change 68
68
"dateformat" : " ^3.0.3" ,
69
69
"deepmerge" : " 2.0.1" ,
70
70
"electron-updater" : " ^4.6.5" ,
71
+ "fast-json-stable-stringify" : " ^2.1.0" ,
71
72
"fast-safe-stringify" : " ^2.1.1" ,
72
73
"glob" : " ^7.1.6" ,
73
74
"google-protobuf" : " ^3.20.1" ,
Original file line number Diff line number Diff line change
1
+ import stableJsonStringify = require( 'fast-json-stable-stringify' ) ;
2
+
1
3
export const naturalCompare : ( left : string , right : string ) => number =
2
4
require ( 'string-natural-compare' ) . caseInsensitive ;
3
5
@@ -13,6 +15,19 @@ export function firstToUpperCase(what: string): string {
13
15
return what . charAt ( 0 ) . toUpperCase ( ) + what . slice ( 1 ) ;
14
16
}
15
17
16
- export function isNullOrUndefined ( what : any ) : what is undefined | null {
18
+ export function isNullOrUndefined ( what : unknown ) : what is undefined | null {
17
19
return what === undefined || what === null ;
18
20
}
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
+ }
Original file line number Diff line number Diff line change @@ -491,10 +491,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
491
491
*/
492
492
async changeSettings ( settings : MonitorSettings ) : Promise < Status > {
493
493
const config = new MonitorPortConfiguration ( ) ;
494
- const { pluggableMonitorSettings } = settings ;
494
+ const { pluggableMonitorSettings = { } } = settings ;
495
495
const reconciledSettings = await this . monitorSettingsProvider . setSettings (
496
496
this . monitorID ,
497
- pluggableMonitorSettings || { }
497
+ pluggableMonitorSettings
498
498
) ;
499
499
500
500
if ( reconciledSettings ) {
@@ -512,9 +512,13 @@ export class MonitorService extends CoreClientAware implements Disposable {
512
512
connected : ! ! this . duplex ,
513
513
serialPort : this . port . address ,
514
514
} ,
515
- pluggableMonitorSettings : reconciledSettings ,
515
+ pluggableMonitorSettings : reconciledSettings ?? pluggableMonitorSettings ,
516
516
} ) ;
517
517
518
+ if ( ! reconciledSettings ) {
519
+ return Status . OK ;
520
+ }
521
+
518
522
if ( ! this . duplex ) {
519
523
return Status . NOT_CONNECTED ;
520
524
}
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ import {
17
17
longestPrefixMatch ,
18
18
reconcileSettings ,
19
19
} from './monitor-settings-utils' ;
20
- import { ILogger } from '@theia/core' ;
20
+ import { deepClone , ILogger } from '@theia/core' ;
21
+ import { sameAs } from '../../common/utils' ;
21
22
22
23
const MONITOR_SETTINGS_FILE = 'pluggable-monitor-settings.json' ;
23
24
@@ -74,14 +75,17 @@ export class MonitorSettingsProviderImpl implements MonitorSettingsProvider {
74
75
async setSettings (
75
76
monitorId : string ,
76
77
settings : PluggableMonitorSettings
77
- ) : Promise < PluggableMonitorSettings > {
78
+ ) : Promise < PluggableMonitorSettings | undefined > {
78
79
// wait for the service to complete the init
79
80
await this . ready . promise ;
80
81
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
+ }
85
89
this . monitorSettings [ monitorId ] = newSettings ;
86
90
87
91
await this . writeSettingsToFS ( ) ;
Original file line number Diff line number Diff line change 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' ;
3
3
4
4
export type PluggableMonitorSettings = Record < string , PluggableMonitorSetting > ;
5
5
export interface MonitorSettings {
@@ -13,8 +13,12 @@ export interface MonitorSettingsProvider {
13
13
monitorId : string ,
14
14
defaultSettings : PluggableMonitorSettings
15
15
) : 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
16
20
setSettings (
17
21
monitorId : string ,
18
22
settings : PluggableMonitorSettings
19
- ) : Promise < PluggableMonitorSettings > ;
23
+ ) : Promise < PluggableMonitorSettings | undefined > ;
20
24
}
You can’t perform that action at this time.
0 commit comments