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);
+ }
+ }
+}
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts
new file mode 100644
index 0000000..89ccdf2
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/reportDialog.handler.ts
@@ -0,0 +1,25 @@
+import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
+import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+import ReportDialogColorThemeFix from '../../core/logic/reportDialog';
+
+/**
+ * Sets the report dialog iframe's theme to the appropriate theme.
+ */
+export default class CCDarkThemeReportDialogHandler extends CssSelectorNodeWatcherHandler {
+ cssSelector = 'iframe';
+
+ constructor(
+ private optionsProvider: OptionsProviderPort,
+ private reportDialogColorThemeFix: ReportDialogColorThemeFix,
+ ) {
+ super();
+ }
+
+ onMutatedNode(mutation: NodeMutation) {
+ this.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
+ mutation.node,
+ this.optionsProvider,
+ );
+ }
+}
diff --git a/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
new file mode 100644
index 0000000..13b6cc9
--- /dev/null
+++ b/src/features/ccDarkTheme/presentation/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
@@ -0,0 +1,27 @@
+import CssSelectorNodeWatcherHandler from '../../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
+import { NodeMutation } from '../../../../presentation/nodeWatcher/NodeWatcherHandler';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+import { isDarkThemeOn } from '../../core/logic/darkTheme';
+import { unifiedProfilesFix } from '../../core/logic/unifiedProfiles';
+
+/**
+ * Redirect unified profile iframe to dark version if applicable
+ */
+export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
+ cssSelector = 'iframe';
+
+ constructor(private optionsProvider: OptionsProviderPort) {
+ super();
+ }
+
+ async onMutatedNode(mutation: NodeMutation) {
+ const optionsValues = await this.optionsProvider.getOptionsValues();
+
+ if (
+ isDarkThemeOn(optionsValues) &&
+ unifiedProfilesFix.checkIframe(mutation.node)
+ ) {
+ unifiedProfilesFix.fixIframe(mutation.node);
+ }
+ }
+}