|
1 | 1 | import { injectable, inject, postConstruct } from 'inversify';
|
2 | 2 | import URI from '@theia/core/lib/common/uri';
|
3 | 3 | import { Emitter } from '@theia/core/lib/common/event';
|
4 |
| -import { Deferred } from '@theia/core/lib/common/promise-util'; |
| 4 | +import { Deferred, timeout } from '@theia/core/lib/common/promise-util'; |
5 | 5 | import { deepClone } from '@theia/core/lib/common/objects';
|
6 | 6 | import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
7 | 7 | import { ThemeService } from '@theia/core/lib/browser/theming';
|
@@ -217,6 +217,11 @@ export class SettingsService {
|
217 | 217 | }
|
218 | 218 | }
|
219 | 219 |
|
| 220 | + private async savePreference(name: string, value: unknown): Promise<void> { |
| 221 | + await this.preferenceService.set(name, value, PreferenceScope.User); |
| 222 | + await timeout(5); |
| 223 | + } |
| 224 | + |
220 | 225 | async save(): Promise<string | true> {
|
221 | 226 | await this.ready.promise;
|
222 | 227 | const {
|
@@ -245,69 +250,29 @@ export class SettingsService {
|
245 | 250 | (config as any).network = network;
|
246 | 251 | (config as any).locale = currentLanguage;
|
247 | 252 |
|
248 |
| - await Promise.all([ |
249 |
| - this.preferenceService.set( |
250 |
| - 'editor.fontSize', |
251 |
| - editorFontSize, |
252 |
| - PreferenceScope.User |
253 |
| - ), |
254 |
| - this.preferenceService.set( |
255 |
| - 'workbench.colorTheme', |
256 |
| - themeId, |
257 |
| - PreferenceScope.User |
258 |
| - ), |
259 |
| - this.preferenceService.set( |
260 |
| - 'editor.autoSave', |
261 |
| - autoSave, |
262 |
| - PreferenceScope.User |
263 |
| - ), |
264 |
| - this.preferenceService.set( |
265 |
| - 'editor.quickSuggestions', |
266 |
| - quickSuggestions, |
267 |
| - PreferenceScope.User |
268 |
| - ), |
269 |
| - this.preferenceService.set( |
270 |
| - AUTO_SCALE_SETTING, |
271 |
| - autoScaleInterface, |
272 |
| - PreferenceScope.User |
273 |
| - ), |
274 |
| - this.preferenceService.set( |
275 |
| - ZOOM_LEVEL_SETTING, |
276 |
| - interfaceScale, |
277 |
| - PreferenceScope.User |
278 |
| - ), |
279 |
| - this.preferenceService.set( |
280 |
| - COMPILE_VERBOSE_SETTING, |
281 |
| - verboseOnCompile, |
282 |
| - PreferenceScope.User |
283 |
| - ), |
284 |
| - this.preferenceService.set( |
285 |
| - COMPILE_WARNINGS_SETTING, |
286 |
| - compilerWarnings, |
287 |
| - PreferenceScope.User |
288 |
| - ), |
289 |
| - this.preferenceService.set( |
290 |
| - UPLOAD_VERBOSE_SETTING, |
291 |
| - verboseOnUpload, |
292 |
| - PreferenceScope.User |
293 |
| - ), |
294 |
| - this.preferenceService.set( |
295 |
| - UPLOAD_VERIFY_SETTING, |
296 |
| - verifyAfterUpload, |
297 |
| - PreferenceScope.User |
298 |
| - ), |
299 |
| - this.preferenceService.set( |
300 |
| - SHOW_ALL_FILES_SETTING, |
301 |
| - sketchbookShowAllFiles, |
302 |
| - PreferenceScope.User |
303 |
| - ), |
304 |
| - this.configService.setConfiguration(config), |
305 |
| - ]); |
| 253 | + await this.savePreference('editor.fontSize', editorFontSize); |
| 254 | + await this.savePreference('workbench.colorTheme', themeId); |
| 255 | + await this.savePreference('editor.autoSave', autoSave); |
| 256 | + await this.savePreference('editor.quickSuggestions', quickSuggestions); |
| 257 | + await this.savePreference(AUTO_SCALE_SETTING, autoScaleInterface); |
| 258 | + await this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale); |
| 259 | + await this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale); |
| 260 | + await this.savePreference(COMPILE_VERBOSE_SETTING, verboseOnCompile); |
| 261 | + await this.savePreference(COMPILE_WARNINGS_SETTING, compilerWarnings); |
| 262 | + await this.savePreference(UPLOAD_VERBOSE_SETTING, verboseOnUpload); |
| 263 | + await this.savePreference(UPLOAD_VERIFY_SETTING, verifyAfterUpload); |
| 264 | + await this.savePreference(SHOW_ALL_FILES_SETTING, sketchbookShowAllFiles); |
| 265 | + await this.configService.setConfiguration(config); |
306 | 266 | this.onDidChangeEmitter.fire(this._settings);
|
307 | 267 |
|
308 | 268 | // after saving all the settings, if we need to change the language we need to perform a reload
|
309 |
| - if (currentLanguage !== nls.locale) { |
310 |
| - window.localStorage.setItem(nls.localeId, currentLanguage); |
| 269 | + // Only reload if the language differs from the current locale. `nls.locale === undefined` signals english as well |
| 270 | + if (currentLanguage !== nls.locale && !(currentLanguage === 'en' && nls.locale === undefined)) { |
| 271 | + if (currentLanguage === 'en') { |
| 272 | + window.localStorage.removeItem(nls.localeId); |
| 273 | + } else { |
| 274 | + window.localStorage.setItem(nls.localeId, currentLanguage); |
| 275 | + } |
311 | 276 | window.location.reload();
|
312 | 277 | }
|
313 | 278 |
|
|
0 commit comments