refactor(load-drafts): migrate to the new DI architecture
Bug: twpowertools:226
Change-Id: Ia85adb1af9440182323bebf4516bbd5ee3efbe4d
diff --git a/src/entryPoints/communityConsole/contentScripts/start.ts b/src/entryPoints/communityConsole/contentScripts/start.ts
index baea65b..c408b9f 100644
--- a/src/entryPoints/communityConsole/contentScripts/start.ts
+++ b/src/entryPoints/communityConsole/contentScripts/start.ts
@@ -3,6 +3,8 @@
import DependenciesProviderSingleton, {
AutoRefreshDependency,
+ OptionsProviderDependency,
+ StartupDataStorageDependency,
} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
import { Context } from '../../../common/architecture/entrypoint/Context';
import {
@@ -19,6 +21,7 @@
import ScriptSorterAdapter from '../../../infrastructure/presentation/scripts/ScriptSorter.adapter';
import { SortedScriptsProviderAdapter } from '../../../infrastructure/presentation/scripts/SortedScriptsProvider.adapter';
import StandaloneScripts from '../../../scripts/Scripts';
+import LoadDraftsSetupScript from '../../../features/loadDrafts/presentation/scripts/setup.script';
const scriptRunner = createScriptRunner();
scriptRunner.run();
@@ -26,6 +29,12 @@
function createScriptRunner() {
const dependenciesProvider = DependenciesProviderSingleton.getInstance();
const autoRefresh = dependenciesProvider.getDependency(AutoRefreshDependency);
+ const optionsProvider = dependenciesProvider.getDependency(
+ OptionsProviderDependency,
+ );
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
const context: Context = {
page: ScriptPage.CommunityConsole,
@@ -41,6 +50,7 @@
new CCDarkThemeInjectAutoDarkTheme(),
new CCDarkThemeInjectForcedDarkTheme(),
new InteropThreadPageSetupScript(),
+ new LoadDraftsSetupScript(optionsProvider, startupDataStorage),
// Non-DI scripts (legacy, should be migrated to use a DI approach)
...new Features().getScripts(context),
diff --git a/src/features/Features.ts b/src/features/Features.ts
index 2f38f34..7f2a061 100644
--- a/src/features/Features.ts
+++ b/src/features/Features.ts
@@ -2,14 +2,12 @@
import ScriptFilterListProvider from '../common/architecture/scripts/ScriptFilterListProvider';
import ExtraInfoFeature from './extraInfo/extraInfo.feature';
import WorkflowsFeature from './workflows/workflows.feature';
-import LoadDraftsFeature from './loadDrafts/loadDrafts.feature';
export type ConcreteFeatureClass = { new (): Feature };
export default class Features extends ScriptFilterListProvider {
private features: ConcreteFeatureClass[] = [
ExtraInfoFeature,
- LoadDraftsFeature,
WorkflowsFeature,
];
private initializedFeatures: Feature[];
diff --git a/src/features/loadDrafts/loadDrafts.feature.ts b/src/features/loadDrafts/loadDrafts.feature.ts
deleted file mode 100644
index 23f6873..0000000
--- a/src/features/loadDrafts/loadDrafts.feature.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import Feature from '../../common/architecture/features/Feature';
-import { ConcreteScript } from '../../common/architecture/scripts/Script';
-import { OptionCodename } from '../../common/options/optionsPrototype';
-import EnableLoadDraftsFlagInDataStartupScript from './scripts/setThreadPageInDataStartupScript.script';
-
-export default class LoadDraftsFeature extends Feature {
- public readonly scripts: ConcreteScript[] = [
- EnableLoadDraftsFlagInDataStartupScript,
- ];
-
- readonly codename = 'loadDrafts';
- readonly relatedOptions: OptionCodename[] = ['loaddrafts'];
-}
diff --git a/src/features/loadDrafts/presentation/scripts/setup.script.ts b/src/features/loadDrafts/presentation/scripts/setup.script.ts
new file mode 100644
index 0000000..9195ebd
--- /dev/null
+++ b/src/features/loadDrafts/presentation/scripts/setup.script.ts
@@ -0,0 +1,26 @@
+import Script from '../../../../common/architecture/scripts/Script';
+import { StartupDataStoragePort } from '../../../../services/communityConsole/StartupDataStorage.port';
+import { OptionsProviderPort } from '../../../../services/options/OptionsProvider';
+
+export default class LoadDraftsSetupScript extends Script {
+ page: never;
+ environment: never;
+ runPhase: never;
+
+ constructor(
+ private optionsProvider: OptionsProviderPort,
+ private startupDataStorage: StartupDataStoragePort,
+ ) {
+ super();
+ }
+
+ async execute() {
+ if (await this.optionsProvider.isEnabled('loaddrafts')) {
+ this.startupDataStorage.enqueueModification((startupDataModel) => {
+ startupDataModel.data[4][13] = true;
+ });
+ // NOTE: Workaround because otherwise the modifications would be applied too late.
+ this.startupDataStorage.applyModifications();
+ }
+ }
+}
diff --git a/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts b/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts
deleted file mode 100644
index 6319fb7..0000000
--- a/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import DependenciesProviderSingleton, {
- OptionsProviderDependency,
- StartupDataStorageDependency,
-} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
-import Script, {
- ScriptEnvironment,
- ScriptPage,
- ScriptRunPhase,
-} from '../../../common/architecture/scripts/Script';
-
-export default class EnableLoadDraftsFlagInDataStartupScript extends Script {
- page = ScriptPage.CommunityConsole;
- environment = ScriptEnvironment.ContentScript;
- runPhase = ScriptRunPhase.Start;
-
- async execute() {
- const dependenciesProvider = DependenciesProviderSingleton.getInstance();
- const optionsProvider = dependenciesProvider.getDependency(
- OptionsProviderDependency,
- );
- if (await optionsProvider.isEnabled('loaddrafts')) {
- const startupDataStorage = dependenciesProvider.getDependency(
- StartupDataStorageDependency,
- );
- startupDataStorage.enqueueModification((startupDataModel) => {
- startupDataModel.data[4][13] = true;
- });
- // NOTE: Workaround because otherwise the modifications would be applied too late.
- startupDataStorage.applyModifications();
- }
- }
-}