import { Subject , Observable , of } from 'rxjs' ; import { shareReplay , takeUntil } from 'rxjs/operators' ; import { InjectedMetadataSetup } from '../injected_metadata' ; import type { CoreTheme , ThemeServiceSetup , ThemeServiceStart } from './types' ; export interface SetupDeps { injectedMetadata : InjectedMetadataSetup ; } export class ThemeService { private theme$ ? : Observable < CoreTheme > ; private stop$ = new Subject ( ) ; public setup ( { injectedMetadata } ) { const theme = injectedMetadata . getTheme ( ) ; this . theme$ = of ( { darkMode : theme . darkMode } ) ; return { theme$ : this . theme$ . pipe ( takeUntil ( this . stop$ ) , shareReplay ( 1 ) ) , } ; } public start ( ) { if ( ! this . theme$ ) { throw new Error ( 'setup must be called before start' ) ; } return { theme$ : this . theme$ . pipe ( takeUntil ( this . stop$ ) , shareReplay ( 1 ) ) , } ; } public stop ( ) { this . stop$ . next ( ) ; } }