blob: 32c17eb3feac2c8721cfde61f5f3c8407b5d4232 [file] [log] [blame]
import DependenciesProviderSingleton, {
OptionsProviderDependency,
StartupDataStorageDependency,
} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
import Script, {
ScriptEnvironment,
ScriptPage,
ScriptRunPhase,
} from '../../../common/architecture/scripts/Script';
const SMEI_RCE_THREAD_INTEROP = 22;
export default class SetThreadPageInDataStartupScript 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('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();
}
}
}