export enum Theme { Light , Dark } export enum ComponentView { Hybrid , All , Components } export enum AnalyticsConsent { NotSet , Yes , No } export interface SimpleOptions { theme ? : Theme ; componentView ? : ComponentView ; analyticsConsent ? : AnalyticsConsent ; } export const defaultOptions = ( ) : SimpleOptions => { return { theme : Theme . Light , componentView : ComponentView . Hybrid , analyticsConsent : AnalyticsConsent . NotSet , } ; } ; export const loadOptions = ( ) : Promise < SimpleOptions > => { return loadFromStorage ( ) . then ( result => { const combined = Object . assign ( { } , defaultOptions ( ) , result ) ; switch ( < Theme | string > combined . theme ) { case 'light' : combined . theme = Theme . Light ; break ; case 'dark' : combined . theme = Theme . Dark ; break ; } return combined ; } ) ; } ; const loadFromStorage = ( ) : Promise < SimpleOptions > => { return new Promise ( resolve => { const keys = [ 'componentView' , 'theme' , 'analyticsConsent' ] ; chrome . storage . sync . get ( keys , ( result ) => { resolve ( result ) ; } ) ; } ) ; } ; export const saveOptions = ( options ) => { for ( const key of Object . keys ( options ) ) { chrome . storage . sync . set ( { [ key ] : options [ key ] } ) ; } } ;