blob: 12d50bb36cb85d9e5bec011bc96b836f8359eccc [file] [log] [blame]
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02001import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
2import { NodeMutation } from '../../../common/nodeWatcher/NodeWatcherHandler';
3import { injectDarkThemeButton } from '../core/logic/darkTheme';
4import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
5
6/**
7 * Injects the dark theme button.
8 */
9export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
10 cssSelector = 'ec-app';
11
12 async onMutatedNode(mutation: NodeMutation) {
13 if (!(mutation.node instanceof Element)) return;
14
15 const optionsProvider = this.options.optionsProvider;
16 const isEnabled = await optionsProvider.isEnabled('ccdarktheme');
17 const mode = await optionsProvider.getOptionValue('ccdarktheme_mode');
18
19 // TODO(avm99963): make this feature dynamic.
20 if (isEnabled && mode === 'switch') {
21 const rightControl = mutation.node.querySelector('header .right-control');
22 if (rightControl === null) return;
23 injectDarkThemeButton(rightControl);
24 }
25 }
26}