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