@@ -426,33 +426,38 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
426
426
427
427
public setColorTheme ( themeIdOrTheme : string | undefined | IWorkbenchColorTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchColorTheme | null > {
428
428
return this . colorThemeSequencer . queue ( async ( ) => {
429
- if ( ! themeIdOrTheme ) {
430
- return null ;
431
- }
432
- const themeId = types . isString ( themeIdOrTheme ) ? validateThemeId ( themeIdOrTheme ) : themeIdOrTheme . id ;
433
- if ( this . currentColorTheme . isLoaded && themeId === this . currentColorTheme . id ) {
434
- if ( settingsTarget !== 'preview' ) {
435
- this . currentColorTheme . toStorage ( this . storageService ) ;
436
- }
437
- return this . settings . setColorTheme ( this . currentColorTheme , settingsTarget ) ;
438
- }
429
+ return this . internalSetColorTheme ( themeIdOrTheme , settingsTarget ) ;
430
+ } ) ;
431
+ }
439
432
440
- let themeData = this . colorThemeRegistry . findThemeById ( themeId ) ;
441
- if ( ! themeData ) {
442
- if ( themeIdOrTheme instanceof ColorThemeData ) {
443
- themeData = themeIdOrTheme ;
444
- } else {
445
- return null ;
446
- }
433
+ private async internalSetColorTheme ( themeIdOrTheme : string | undefined | IWorkbenchColorTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchColorTheme | null > {
434
+ if ( ! themeIdOrTheme ) {
435
+ return null ;
436
+ }
437
+ const themeId = types . isString ( themeIdOrTheme ) ? validateThemeId ( themeIdOrTheme ) : themeIdOrTheme . id ;
438
+ if ( this . currentColorTheme . isLoaded && themeId === this . currentColorTheme . id ) {
439
+ if ( settingsTarget !== 'preview' ) {
440
+ this . currentColorTheme . toStorage ( this . storageService ) ;
447
441
}
448
- try {
449
- await themeData . ensureLoaded ( this . extensionResourceLoaderService ) ;
450
- themeData . setCustomizations ( this . settings ) ;
451
- return this . applyTheme ( themeData , settingsTarget ) ;
452
- } catch ( error ) {
453
- throw new Error ( nls . localize ( 'error.cannotloadtheme' , "Unable to load {0}: {1}" , themeData . location ?. toString ( ) , error . message ) ) ;
442
+ return this . settings . setColorTheme ( this . currentColorTheme , settingsTarget ) ;
443
+ }
444
+
445
+ let themeData = this . colorThemeRegistry . findThemeById ( themeId ) ;
446
+ if ( ! themeData ) {
447
+ if ( themeIdOrTheme instanceof ColorThemeData ) {
448
+ themeData = themeIdOrTheme ;
449
+ } else {
450
+ return null ;
454
451
}
455
- } ) ;
452
+ }
453
+ try {
454
+ await themeData . ensureLoaded ( this . extensionResourceLoaderService ) ;
455
+ themeData . setCustomizations ( this . settings ) ;
456
+ return this . applyTheme ( themeData , settingsTarget ) ;
457
+ } catch ( error ) {
458
+ throw new Error ( nls . localize ( 'error.cannotloadtheme' , "Unable to load {0}: {1}" , themeData . location ?. toString ( ) , error . message ) ) ;
459
+ }
460
+
456
461
}
457
462
458
463
private reloadCurrentColorTheme ( ) {
@@ -474,7 +479,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
474
479
const theme = this . colorThemeRegistry . findThemeBySettingsId ( settingId ) ;
475
480
if ( theme ) {
476
481
if ( settingId !== this . currentColorTheme . settingsId ) {
477
- await this . setColorTheme ( theme . id , undefined ) ;
482
+ await this . internalSetColorTheme ( theme . id , undefined ) ;
478
483
} else if ( theme !== this . currentColorTheme ) {
479
484
theme . setCustomizations ( this . settings ) ;
480
485
await this . applyTheme ( theme , undefined , true ) ;
@@ -589,34 +594,38 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
589
594
590
595
public async setFileIconTheme ( iconThemeOrId : string | undefined | IWorkbenchFileIconTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchFileIconTheme > {
591
596
return this . fileIconThemeSequencer . queue ( async ( ) => {
592
- if ( iconThemeOrId === undefined ) {
593
- iconThemeOrId = '' ;
594
- }
595
- const themeId = types . isString ( iconThemeOrId ) ? iconThemeOrId : iconThemeOrId . id ;
596
- if ( themeId !== this . currentFileIconTheme . id || ! this . currentFileIconTheme . isLoaded ) {
597
+ return this . internalSetFileIconTheme ( iconThemeOrId , settingsTarget ) ;
598
+ } ) ;
599
+ }
597
600
598
- let newThemeData = this . fileIconThemeRegistry . findThemeById ( themeId ) ;
599
- if ( ! newThemeData && iconThemeOrId instanceof FileIconThemeData ) {
600
- newThemeData = iconThemeOrId ;
601
- }
602
- if ( ! newThemeData ) {
603
- newThemeData = FileIconThemeData . noIconTheme ;
604
- }
605
- await newThemeData . ensureLoaded ( this . extensionResourceLoaderService ) ;
601
+ private async internalSetFileIconTheme ( iconThemeOrId : string | undefined | IWorkbenchFileIconTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchFileIconTheme > {
602
+ if ( iconThemeOrId === undefined ) {
603
+ iconThemeOrId = '' ;
604
+ }
605
+ const themeId = types . isString ( iconThemeOrId ) ? iconThemeOrId : iconThemeOrId . id ;
606
+ if ( themeId !== this . currentFileIconTheme . id || ! this . currentFileIconTheme . isLoaded ) {
606
607
607
- this . applyAndSetFileIconTheme ( newThemeData ) ; // updates this.currentFileIconTheme
608
+ let newThemeData = this . fileIconThemeRegistry . findThemeById ( themeId ) ;
609
+ if ( ! newThemeData && iconThemeOrId instanceof FileIconThemeData ) {
610
+ newThemeData = iconThemeOrId ;
611
+ }
612
+ if ( ! newThemeData ) {
613
+ newThemeData = FileIconThemeData . noIconTheme ;
608
614
}
615
+ await newThemeData . ensureLoaded ( this . extensionResourceLoaderService ) ;
609
616
610
- const themeData = this . currentFileIconTheme ;
617
+ this . applyAndSetFileIconTheme ( newThemeData ) ; // updates this.currentFileIconTheme
618
+ }
611
619
612
- // remember theme data for a quick restore
613
- if ( themeData . isLoaded && settingsTarget !== 'preview' && ( ! themeData . location || ! getRemoteAuthority ( themeData . location ) ) ) {
614
- themeData . toStorage ( this . storageService ) ;
615
- }
616
- await this . settings . setFileIconTheme ( this . currentFileIconTheme , settingsTarget ) ;
620
+ const themeData = this . currentFileIconTheme ;
617
621
618
- return themeData ;
619
- } ) ;
622
+ // remember theme data for a quick restore
623
+ if ( themeData . isLoaded && settingsTarget !== 'preview' && ( ! themeData . location || ! getRemoteAuthority ( themeData . location ) ) ) {
624
+ themeData . toStorage ( this . storageService ) ;
625
+ }
626
+ await this . settings . setFileIconTheme ( this . currentFileIconTheme , settingsTarget ) ;
627
+
628
+ return themeData ;
620
629
}
621
630
622
631
public async getMarketplaceFileIconThemes ( publisher : string , name : string , version : string ) : Promise < IWorkbenchFileIconTheme [ ] > {
@@ -645,7 +654,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
645
654
const theme = this . fileIconThemeRegistry . findThemeBySettingsId ( settingId ) ;
646
655
if ( theme ) {
647
656
if ( settingId !== this . currentFileIconTheme . settingsId ) {
648
- await this . setFileIconTheme ( theme . id , undefined ) ;
657
+ await this . internalSetFileIconTheme ( theme . id , undefined ) ;
649
658
} else if ( theme !== this . currentFileIconTheme ) {
650
659
this . applyAndSetFileIconTheme ( theme , true ) ;
651
660
}
@@ -691,32 +700,37 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
691
700
692
701
public async setProductIconTheme ( iconThemeOrId : string | undefined | IWorkbenchProductIconTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchProductIconTheme > {
693
702
return this . productIconThemeSequencer . queue ( async ( ) => {
694
- if ( iconThemeOrId === undefined ) {
695
- iconThemeOrId = '' ;
696
- }
697
- const themeId = types . isString ( iconThemeOrId ) ? iconThemeOrId : iconThemeOrId . id ;
698
- if ( themeId !== this . currentProductIconTheme . id || ! this . currentProductIconTheme . isLoaded ) {
699
- let newThemeData = this . productIconThemeRegistry . findThemeById ( themeId ) ;
700
- if ( ! newThemeData && iconThemeOrId instanceof ProductIconThemeData ) {
701
- newThemeData = iconThemeOrId ;
702
- }
703
- if ( ! newThemeData ) {
704
- newThemeData = ProductIconThemeData . defaultTheme ;
705
- }
706
- await newThemeData . ensureLoaded ( this . extensionResourceLoaderService , this . logService ) ;
703
+ return this . internalSetProductIconTheme ( iconThemeOrId , settingsTarget ) ;
704
+ } ) ;
705
+ }
707
706
708
- this . applyAndSetProductIconTheme ( newThemeData ) ; // updates this.currentProductIconTheme
707
+ private async internalSetProductIconTheme ( iconThemeOrId : string | undefined | IWorkbenchProductIconTheme , settingsTarget : ThemeSettingTarget ) : Promise < IWorkbenchProductIconTheme > {
708
+ if ( iconThemeOrId === undefined ) {
709
+ iconThemeOrId = '' ;
710
+ }
711
+ const themeId = types . isString ( iconThemeOrId ) ? iconThemeOrId : iconThemeOrId . id ;
712
+ if ( themeId !== this . currentProductIconTheme . id || ! this . currentProductIconTheme . isLoaded ) {
713
+ let newThemeData = this . productIconThemeRegistry . findThemeById ( themeId ) ;
714
+ if ( ! newThemeData && iconThemeOrId instanceof ProductIconThemeData ) {
715
+ newThemeData = iconThemeOrId ;
709
716
}
710
- const themeData = this . currentProductIconTheme ;
711
-
712
- // remember theme data for a quick restore
713
- if ( themeData . isLoaded && settingsTarget !== 'preview' && ( ! themeData . location || ! getRemoteAuthority ( themeData . location ) ) ) {
714
- themeData . toStorage ( this . storageService ) ;
717
+ if ( ! newThemeData ) {
718
+ newThemeData = ProductIconThemeData . defaultTheme ;
715
719
}
716
- await this . settings . setProductIconTheme ( this . currentProductIconTheme , settingsTarget ) ;
720
+ await newThemeData . ensureLoaded ( this . extensionResourceLoaderService , this . logService ) ;
721
+
722
+ this . applyAndSetProductIconTheme ( newThemeData ) ; // updates this.currentProductIconTheme
723
+ }
724
+ const themeData = this . currentProductIconTheme ;
725
+
726
+ // remember theme data for a quick restore
727
+ if ( themeData . isLoaded && settingsTarget !== 'preview' && ( ! themeData . location || ! getRemoteAuthority ( themeData . location ) ) ) {
728
+ themeData . toStorage ( this . storageService ) ;
729
+ }
730
+ await this . settings . setProductIconTheme ( this . currentProductIconTheme , settingsTarget ) ;
731
+
732
+ return themeData ;
717
733
718
- return themeData ;
719
- } ) ;
720
734
}
721
735
722
736
public async getMarketplaceProductIconThemes ( publisher : string , name : string , version : string ) : Promise < IWorkbenchProductIconTheme [ ] > {
@@ -745,7 +759,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
745
759
const theme = this . productIconThemeRegistry . findThemeBySettingsId ( settingId ) ;
746
760
if ( theme ) {
747
761
if ( settingId !== this . currentProductIconTheme . settingsId ) {
748
- await this . setProductIconTheme ( theme . id , undefined ) ;
762
+ await this . internalSetProductIconTheme ( theme . id , undefined ) ;
749
763
} else if ( theme !== this . currentProductIconTheme ) {
750
764
this . applyAndSetProductIconTheme ( theme , true ) ;
751
765
}
0 commit comments