@@ -8,6 +8,8 @@ interface ISettingsWithVersion {
8
8
}
9
9
10
10
export class SettingsManager {
11
+ private static _isUpdatingSettings : boolean = false ;
12
+
11
13
/**
12
14
* A list of handlers that will be fired when the settings change.
13
15
* @type {Array }
@@ -50,7 +52,7 @@ export class SettingsManager {
50
52
}
51
53
52
54
public static updateSettings ( config : Configuration , version ?: number ) : void {
53
- if ( ! config || ! config . enabled ) {
55
+ if ( ! config || ! config . enabled || this . _isUpdatingSettings ) {
54
56
return ;
55
57
}
56
58
@@ -65,34 +67,39 @@ export class SettingsManager {
65
67
}
66
68
67
69
config . log . info ( `Checking for updated settings from: v${ version } .` ) ;
70
+ this . _isUpdatingSettings = true ;
68
71
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
+ }
73
77
74
- config . settings = Utils . merge ( config . settings , response . settings ) ;
78
+ config . settings = Utils . merge ( config . settings , response . settings ) ;
75
79
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
+ }
83
87
84
- delete config . settings [ key ] ;
85
- }
88
+ delete config . settings [ key ] ;
89
+ }
86
90
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
+ } ;
91
95
92
- config . storage . settings . save ( newSettings ) ;
96
+ config . storage . settings . save ( newSettings ) ;
93
97
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
+ }
96
103
} ) ;
97
104
}
98
105
0 commit comments