refactor(cc-dark-theme): migrate to the new DI architecture
Bug: twpowertools:226
Change-Id: I735013393d1d99cadee48399bba53a22fe59e27c
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
index fee1ffd..355de3f 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/ecApp.handler.ts
@@ -1,20 +1,23 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+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';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
/**
* Injects the dark theme button.
*/
-export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+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 optionsProvider = this.options.optionsProvider;
- const isEnabled = await optionsProvider.isEnabled('ccdarktheme');
- const mode = await optionsProvider.getOptionValue('ccdarktheme_mode');
+ 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') {
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
index 42c7a59..56699e9 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/reportDialog.handler.ts
@@ -1,17 +1,25 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter';
import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
+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 CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+export default class CCDarkThemeReportDialogHandler extends CssSelectorNodeWatcherHandler {
cssSelector = 'iframe';
+ constructor(
+ private optionsProvider: OptionsProviderPort,
+ private reportDialogColorThemeFix: ReportDialogColorThemeFix,
+ ) {
+ super();
+ }
+
onMutatedNode(mutation: NodeMutation) {
- this.options.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
+ this.reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(
mutation.node,
- this.options.optionsProvider,
+ this.optionsProvider,
);
}
}
diff --git a/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts b/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
index 6343834..28b9753 100644
--- a/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
+++ b/src/features/ccDarkTheme/nodeWatcherHandlers/unifiedProfilesIframe.handler.ts
@@ -1,17 +1,21 @@
-import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler';
+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';
-import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script';
/**
* Redirect unified profile iframe to dark version if applicable
*/
-export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> {
+export default class CCDarkThemeUnifiedProfilesIframeHandler extends CssSelectorNodeWatcherHandler {
cssSelector = 'iframe';
+ constructor(private optionsProvider: OptionsProviderPort) {
+ super();
+ }
+
async onMutatedNode(mutation: NodeMutation) {
- const optionsValues = await this.options.optionsProvider.getOptionsValues();
+ const optionsValues = await this.optionsProvider.getOptionsValues();
if (
isDarkThemeOn(optionsValues) &&