refactor: place all presentation code in a presentation folder
Some features didn't have this folder.
Bug: twpowertools:226
Change-Id: Ic9803e7ee66a15c6c9e083509e059e453a26ed0f
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts
new file mode 100644
index 0000000..3676bcd
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/ecApp.handler.ts
@@ -0,0 +1,29 @@
+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);
+ }
+ }
+}