@@ -8,6 +8,8 @@ interface ISettingsWithVersion {
88}
99
1010export class SettingsManager {
11+ private static _isUpdatingSettings : boolean = false ;
12+
1113 /**
1214 * A list of handlers that will be fired when the settings change.
1315 * @type {Array }
@@ -50,7 +52,7 @@ export class SettingsManager {
5052 }
5153
5254 public static updateSettings ( config : Configuration , version ?: number ) : void {
53- if ( ! config || ! config . enabled ) {
55+ if ( ! config || ! config . enabled || this . _isUpdatingSettings ) {
5456 return ;
5557 }
5658
@@ -65,34 +67,39 @@ export class SettingsManager {
6567 }
6668
6769 config . log . info ( `Checking for updated settings from: v${ version } .` ) ;
70+ this . _isUpdatingSettings = true ;
6871 config . submissionClient . getSettings ( config , version , ( response : SettingsResponse ) => {
69- if ( ! config || ! response || ! response . success || ! response . settings ) {
70- config . log . warn ( `${ unableToUpdateMessage } : ${ response . message } ` ) ;
71- return ;
72- }
72+ try {
73+ if ( ! config || ! response || ! response . success || ! response . settings ) {
74+ config . log . warn ( `${ unableToUpdateMessage } : ${ response . message } ` ) ;
75+ return ;
76+ }
7377
74- config . settings = Utils . merge ( config . settings , response . settings ) ;
78+ config . settings = Utils . merge ( config . settings , response . settings ) ;
7579
76- // TODO: Store snapshot of settings after reading from config and attributes and use that to revert to defaults.
77- // Remove any existing server settings that are not in the new server settings.
78- const savedServerSettings = SettingsManager . getSavedServerSettings ( config ) ;
79- for ( const key in savedServerSettings ) {
80- if ( response . settings [ key ] ) {
81- continue ;
82- }
80+ // TODO: Store snapshot of settings after reading from config and attributes and use that to revert to defaults.
81+ // Remove any existing server settings that are not in the new server settings.
82+ const savedServerSettings = SettingsManager . getSavedServerSettings ( config ) ;
83+ for ( const key in savedServerSettings ) {
84+ if ( response . settings [ key ] ) {
85+ continue ;
86+ }
8387
84- delete config . settings [ key ] ;
85- }
88+ delete config . settings [ key ] ;
89+ }
8690
87- const newSettings : ISettingsWithVersion = {
88- version : response . settingsVersion ,
89- settings : response . settings
90- } ;
91+ const newSettings : ISettingsWithVersion = {
92+ version : response . settingsVersion ,
93+ settings : response . settings
94+ } ;
9195
92- config . storage . settings . save ( newSettings ) ;
96+ config . storage . settings . save ( newSettings ) ;
9397
94- config . log . info ( `Updated settings: v${ newSettings . version } ` ) ;
95- this . changed ( config ) ;
98+ config . log . info ( `Updated settings: v${ newSettings . version } ` ) ;
99+ this . changed ( config ) ;
100+ } finally {
101+ this . _isUpdatingSettings = false ;
102+ }
96103 } ) ;
97104 }
98105
0 commit comments