Adrià Vilanova | 61f782f | 2024-05-31 22:57:24 +0000 | [diff] [blame] | 1 | import DependenciesProviderSingleton, { |
| 2 | OptionsProviderDependency, |
| 3 | StartupDataStorageDependency, |
Adrià Vilanova Martínez | 2d03555 | 2024-10-26 20:23:34 +0200 | [diff] [blame] | 4 | } from '../../../../common/architecture/dependenciesProvider/DependenciesProvider'; |
| 5 | import Script from '../../../../common/architecture/scripts/Script'; |
Adrià Vilanova | 61f782f | 2024-05-31 22:57:24 +0000 | [diff] [blame] | 6 | |
| 7 | const SMEI_RCE_THREAD_INTEROP = 22; |
| 8 | |
Adrià Vilanova Martínez | 2d03555 | 2024-10-26 20:23:34 +0200 | [diff] [blame] | 9 | export default class InteropThreadPageSetupScript extends Script { |
| 10 | page: never; |
| 11 | environment: never; |
| 12 | runPhase: never; |
Adrià Vilanova | 61f782f | 2024-05-31 22:57:24 +0000 | [diff] [blame] | 13 | |
| 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 | } |