blob: ff70c112e4467aa5a0d4638bb1c41dc82206ad9c [file] [log] [blame]
Adrià Vilanova Martínezf92172f2024-10-19 15:55:15 +02001import DependenciesProviderSingleton, {
2 AutoRefreshDependency,
3} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
4import { Context } from '../../../common/architecture/entrypoint/Context';
5import {
6 ScriptEnvironment,
7 ScriptPage,
8 ScriptRunPhase,
9} from '../../../common/architecture/scripts/Script';
10import AutoRefreshThreadListHideHandler from '../../../features/autoRefresh/presentation/nodeWatcherHandlers/threadListHide.handler';
11import AutoRefreshThreadListSetUpHandler from '../../../features/autoRefresh/presentation/nodeWatcherHandlers/threadListSetUp.handler';
12import AutoRefreshStylesScript from '../../../features/autoRefresh/presentation/scripts/styles.script';
13import Features from '../../../features/Features';
14import { NodeWatcherAdapter } from '../../../infrastructure/presentation/nodeWatcher/NodeWatcher.adapter';
15import NodeWatcherScriptAdapter from '../../../infrastructure/presentation/scripts/NodeWatcherScript.adapter';
16import ScriptRunner from '../../../infrastructure/presentation/scripts/ScriptRunner';
17import ScriptSorterAdapter from '../../../infrastructure/presentation/scripts/ScriptSorter.adapter';
18import { SortedScriptsProviderAdapter } from '../../../infrastructure/presentation/scripts/SortedScriptsProvider.adapter';
19import { NodeWatcherHandler } from '../../../presentation/nodeWatcher/NodeWatcherHandler';
20import StandaloneScripts from '../../../scripts/Scripts';
21
22// Run legacy Javascript entry point
23import '../../../contentScripts/communityConsole/main';
24
25const scriptRunner = createScriptRunner();
26scriptRunner.run();
27
28function createScriptRunner() {
29 const dependenciesProvider = DependenciesProviderSingleton.getInstance();
30 const autoRefresh = dependenciesProvider.getDependency(AutoRefreshDependency);
31
32 const context: Context = {
33 page: ScriptPage.CommunityConsole,
34 environment: ScriptEnvironment.ContentScript,
35 runPhase: ScriptRunPhase.Main,
36 };
37
38 return new ScriptRunner(
39 new SortedScriptsProviderAdapter(
40 [
41 // Node watcher script with handlers
42 new NodeWatcherScriptAdapter(
43 new NodeWatcherAdapter(),
44 new Map<string, NodeWatcherHandler>([
45 [
46 'autoRefreshThreadListSetUp',
47 new AutoRefreshThreadListSetUpHandler(autoRefresh),
48 ],
49 [
50 'autoRefreshThreadListHide',
51 new AutoRefreshThreadListHideHandler(autoRefresh),
52 ],
53 ]),
54 ),
55
56 // Individual feature scripts
57 new AutoRefreshStylesScript(),
58
59 // Non-DI scripts (legacy, should be migrated to use a DI approach)
60 ...new Features().getScripts(context),
61 ...new StandaloneScripts().getScripts(context),
62 ],
63 new ScriptSorterAdapter(),
64 ).getScripts(),
65 );
66}