blob: 67c0ce976812ede96c1b253e5dda83f974b94dd1 [file] [log] [blame]
Adrià Vilanova61f782f2024-05-31 22:57:24 +00001import DependenciesProviderSingleton, {
2 OptionsProviderDependency,
3 StartupDataStorageDependency,
Adrià Vilanova Martínez2d035552024-10-26 20:23:34 +02004} from '../../../../common/architecture/dependenciesProvider/DependenciesProvider';
5import Script from '../../../../common/architecture/scripts/Script';
Adrià Vilanova61f782f2024-05-31 22:57:24 +00006
7const SMEI_RCE_THREAD_INTEROP = 22;
8
Adrià Vilanova Martínez2d035552024-10-26 20:23:34 +02009export default class InteropThreadPageSetupScript extends Script {
10 page: never;
11 environment: never;
12 runPhase: never;
Adrià Vilanova61f782f2024-05-31 22:57:24 +000013
14 async execute() {
15 const dependenciesProvider = DependenciesProviderSingleton.getInstance();
16 const optionsProvider = dependenciesProvider.getDependency(
17 OptionsProviderDependency,
18 );
19 if (await optionsProvider.isEnabled('interopthreadpage')) {
20 const startupDataStorage = dependenciesProvider.getDependency(
21 StartupDataStorageDependency,
22 );
23 const mode = await optionsProvider.getOptionValue(
24 'interopthreadpage_mode',
25 );
26 startupDataStorage.enqueueModification((startupDataModel) => {
27 const index = startupDataModel.data[1][6].indexOf(
28 SMEI_RCE_THREAD_INTEROP,
29 );
30
31 switch (mode) {
32 case 'previous':
33 if (index > -1) {
34 startupDataModel.data[1][6].splice(index, 1);
35 }
36 break;
37
38 case 'next':
39 if (index == -1) {
40 startupDataModel.data[1][6].push(SMEI_RCE_THREAD_INTEROP);
41 }
42 break;
43 }
44 });
45 // NOTE: Workaround because otherwise the modifications would be applied too late.
46 startupDataStorage.applyModifications();
47 }
48 }
49}