blob: 3676bcd710489962833ebd9ec38d399619c54c06 [file] [log] [blame]
import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
import { injectDarkThemeButton } from '../../core/logic/darkTheme';
/**
* Injects the dark theme button.
*/
export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherHandler {
cssSelector = 'ec-app';
constructor(private optionsProvider: OptionsProviderPort) {
super();
}
async onMutatedNode(mutation: NodeMutation) {
if (!(mutation.node instanceof Element)) return;
const isEnabled = await this.optionsProvider.isEnabled('ccdarktheme');
const mode = await this.optionsProvider.getOptionValue('ccdarktheme_mode');
// TODO(avm99963): make this feature dynamic.
if (isEnabled && mode === 'switch') {
const rightControl = mutation.node.querySelector('header .right-control');
if (rightControl === null) return;
injectDarkThemeButton(rightControl);
}
}
}