module Sfx { export class ThemeService extends Observable { private currentThemeName : string ; public constructor ( private storage ) { super ( ) ; this . currentThemeName = storage . getValueString ( Constants . ThemeNameStorageKey , Constants . DefaultThemeName ) ; } public getActiveThemeName ( ) { return this . currentThemeName ; } public changeToTheme ( name , saveAsUserPreference = false ) { if ( name !== this . currentThemeName ) { let oldThemeName = this . currentThemeName ; this . currentThemeName = name ; this . notify ( Constants . ThemeNameMonitorPropertyName , oldThemeName , name ) ; if ( saveAsUserPreference ) { this . storage . setValue ( Constants . ThemeNameStorageKey , name ) ; } } } public resolveAndChangeToTheme ( themeSrc , themeName ) { if ( ! _ . isString ( themeSrc ) || ! themeSrc || ! _ . isString ( themeName ) || ! themeName ) { return ; } themeSrc = themeSrc . toLowerCase ( ) ; themeName = themeName . toLowerCase ( ) ; let matchingThemeName = "" ; switch ( themeSrc ) { case "vs" : matchingThemeName = this . resolveVsTheme ( themeName ) ; break ; case "azure" : matchingThemeName = this . resolveAzureTheme ( themeName ) ; break ; } if ( ! matchingThemeName ) { console . log ( "Unrecognized theme source '" + themeSrc + "' and theme name '" + themeName + "'." ) ; return ; } this . changeToTheme ( matchingThemeName , false ) ; } private resolveVsTheme ( vsThemeName ) { switch ( vsThemeName ) { case "blue" : case "light" : return "light" ; case "dark" : return "dark" ; default : return "" ; } } private resolveAzureTheme ( azureThemeName ) { switch ( azureThemeName ) { case "azure" : case "blue" : case "light" : return "light" ; case "dark" : return "dark" ; default : return "" ; } } } ( function ( ) { let module = angular . module ( "themeService" , [ "storageService" ] ) ; module . factory ( "theme" , [ "storage" , ( storage ) => new ThemeService ( storage ) ] ) ; } ) ( ) ; }