refactor(interop-thread-page): migrate to the new DI architecture
Bug: twpowertools:226
Change-Id: Ie2a5e57574a1d986efc6e1c7a64a562d435e956e
diff --git a/src/features/interopThreadPage/presentation/scripts/setup.script.ts b/src/features/interopThreadPage/presentation/scripts/setup.script.ts
new file mode 100644
index 0000000..67c0ce9
--- /dev/null
+++ b/src/features/interopThreadPage/presentation/scripts/setup.script.ts
@@ -0,0 +1,49 @@
+import DependenciesProviderSingleton, {
+ OptionsProviderDependency,
+ StartupDataStorageDependency,
+} from '../../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import Script from '../../../../common/architecture/scripts/Script';
+
+const SMEI_RCE_THREAD_INTEROP = 22;
+
+export default class InteropThreadPageSetupScript extends Script {
+ page: never;
+ environment: never;
+ runPhase: never;
+
+ async execute() {
+ const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+ const optionsProvider = dependenciesProvider.getDependency(
+ OptionsProviderDependency,
+ );
+ if (await optionsProvider.isEnabled('interopthreadpage')) {
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
+ const mode = await optionsProvider.getOptionValue(
+ 'interopthreadpage_mode',
+ );
+ startupDataStorage.enqueueModification((startupDataModel) => {
+ const index = startupDataModel.data[1][6].indexOf(
+ SMEI_RCE_THREAD_INTEROP,
+ );
+
+ switch (mode) {
+ case 'previous':
+ if (index > -1) {
+ startupDataModel.data[1][6].splice(index, 1);
+ }
+ break;
+
+ case 'next':
+ if (index == -1) {
+ startupDataModel.data[1][6].push(SMEI_RCE_THREAD_INTEROP);
+ }
+ break;
+ }
+ });
+ // NOTE: Workaround because otherwise the modifications would be applied too late.
+ startupDataStorage.applyModifications();
+ }
+ }
+}