blob: 355de3f11241f8627300e253a11c665796ebfc76 [file] [log] [blame]
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +02001import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
Adrià Vilanova Martínez43c75202024-10-19 15:55:15 +02002import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
Adrià Vilanova Martínez6ecaa0d2024-10-26 17:04:32 +02003import { OptionsProviderPort } from '../../../services/options/OptionsProvider';
Adrià Vilanova Martínez917797e2024-05-25 22:41:25 +02004import { 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}