blob: 3676bcd710489962833ebd9ec38d399619c54c06 [file] [log] [blame]
Adrià Vilanova Martínezfe694782024-11-09 20:40:43 +01001import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
2import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
3import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
4import { injectDarkThemeButton } from '../../core/logic/darkTheme';
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02005
6/**
7 * Injects the dark theme button.
8 */
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +02009export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherHandler {
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020010 cssSelector = 'ec-app';
11
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +020012 constructor(private optionsProvider: OptionsProviderPort) {
13 super();
14 }
15
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020016 async onMutatedNode(mutation: NodeMutation) {
17 if (!(mutation.node instanceof Element)) return;
18
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +020019 const isEnabled = await this.optionsProvider.isEnabled('ccdarktheme');
20 const mode = await this.optionsProvider.getOptionValue('ccdarktheme_mode');
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +020021
22 // TODO(avm99963): make this feature dynamic.
23 if (isEnabled && mode === 'switch') {
24 const rightControl = mutation.node.querySelector('header .right-control');
25 if (rightControl === null) return;
26 injectDarkThemeButton(rightControl);
27 }
28 }
29}