blob: fee1ffdf0af7d806b62f6afd6a21477a825115ff [file] [log] [blame]
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02001import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +02002import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02003import { 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}