refactor(ui-spacing): migrate to the new DI architecture
With this migration we also get for free that this option is now
dynamic, so changing it will automatically update the applied styles.
Bug: twpowertools:176, twpowertools:61
Change-Id: Icac4f829745a06c95439931955be6c52c7303482
diff --git a/src/contentScripts/communityConsole/start.js b/src/contentScripts/communityConsole/start.js
deleted file mode 100644
index 8cb89e8..0000000
--- a/src/contentScripts/communityConsole/start.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import {injectStylesheet} from '../../common/contentScriptsUtils';
-import {getOptions} from '../../common/options/optionsUtils.js';
-
-getOptions(null).then(options => {
- if (options.uispacing) {
- injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
- injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
- }
-});
diff --git a/src/contentScripts/publicThreadStart.js b/src/contentScripts/publicThreadStart.js
index 40cd302..9c7f06c 100644
--- a/src/contentScripts/publicThreadStart.js
+++ b/src/contentScripts/publicThreadStart.js
@@ -1,12 +1,6 @@
-import {injectStylesheet} from '../common/contentScriptsUtils';
import {getOptions} from '../common/options/optionsUtils.js';
import {setUpRedirectIfEnabled} from '../redirect/setup.js';
-getOptions(['uispacing', 'redirect']).then(options => {
- if (options.uispacing) {
- injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
- injectStylesheet(chrome.runtime.getURL('css/ui_spacing/twbasic.css'));
- }
-
+getOptions(['redirect']).then(options => {
setUpRedirectIfEnabled(options);
});
diff --git a/src/entryPoints/communityConsole/contentScripts/start.ts b/src/entryPoints/communityConsole/contentScripts/start.ts
index 21ef427..355fb0b 100644
--- a/src/entryPoints/communityConsole/contentScripts/start.ts
+++ b/src/entryPoints/communityConsole/contentScripts/start.ts
@@ -1,6 +1,3 @@
-// Run legacy Javascript entry point
-import '../../../contentScripts/communityConsole/start';
-
import DependenciesProviderSingleton, {
AutoRefreshDependency,
ExtraInfoDependency,
@@ -26,6 +23,8 @@
import ThreadPageDesignWarningSetUpScript from '../../../features/threadPageDesignWarning/presentation/scripts/setUp.script';
import FlattenThreadsSetUpReplyActionHandlerScript from '../../../features/flattenThreads/presentation/scripts/setUpReplyActionHandler.script';
import FlattenThreadsReplyActionHandler from '../../../features/flattenThreads/core/replyActionHandler';
+import UiSpacingSharedStylesScript from '../../../features/uiSpacing/presentation/scripts/sharedStyles.script';
+import UiSpacingConsoleStylesScript from '../../../features/uiSpacing/presentation/scripts/consoleStyles.script';
const scriptRunner = createScriptRunner();
scriptRunner.run();
@@ -61,6 +60,8 @@
new InteropThreadPageSetupScript(),
new ThreadPageDesignWarningSetUpScript(threadPageDesignWarning),
new LoadDraftsSetupScript(optionsProvider, startupDataStorage),
+ new UiSpacingConsoleStylesScript(),
+ new UiSpacingSharedStylesScript(),
new WorkflowsImportSetUpScript(workflowsImport),
// Standalone scripts
diff --git a/src/entryPoints/twBasic/thread/start.ts b/src/entryPoints/twBasic/thread/start.ts
new file mode 100644
index 0000000..d3fa2ea
--- /dev/null
+++ b/src/entryPoints/twBasic/thread/start.ts
@@ -0,0 +1,24 @@
+// Run legacy Javascript entry point
+import '../../../contentScripts/publicThreadStart';
+
+import UiSpacingSharedStylesScript from '../../../features/uiSpacing/presentation/scripts/sharedStyles.script';
+import UiSpacingTwBasicStylesScript from '../../../features/uiSpacing/presentation/scripts/twBasicStyles.script';
+import ScriptRunner from '../../../infrastructure/presentation/scripts/ScriptRunner';
+import ScriptSorterAdapter from '../../../infrastructure/presentation/scripts/ScriptSorter.adapter';
+import { SortedScriptsProviderAdapter } from '../../../infrastructure/presentation/scripts/SortedScriptsProvider.adapter';
+
+const scriptRunner = createScriptRunner();
+scriptRunner.run();
+
+function createScriptRunner() {
+ return new ScriptRunner(
+ new SortedScriptsProviderAdapter(
+ [
+ // Individual feature scripts
+ new UiSpacingSharedStylesScript(),
+ new UiSpacingTwBasicStylesScript(),
+ ],
+ new ScriptSorterAdapter(),
+ ).getScripts(),
+ );
+}
diff --git a/src/features/uiSpacing/presentation/scripts/consoleStyles.script.ts b/src/features/uiSpacing/presentation/scripts/consoleStyles.script.ts
new file mode 100644
index 0000000..6ba12c4
--- /dev/null
+++ b/src/features/uiSpacing/presentation/scripts/consoleStyles.script.ts
@@ -0,0 +1,13 @@
+import StylesheetScript from '../../../../common/architecture/scripts/stylesheet/StylesheetScript';
+import UiSpacingSharedStylesScript from './sharedStyles.script';
+
+export default class UiSpacingConsoleStylesScript extends StylesheetScript {
+ stylesheet = 'css/ui_spacing/console.css';
+
+ runAfter = [UiSpacingSharedStylesScript];
+ page: never;
+
+ async shouldBeInjected(): Promise<boolean> {
+ return await this.optionsProvider.isEnabled('uispacing');
+ }
+}
diff --git a/src/features/uiSpacing/presentation/scripts/sharedStyles.script.ts b/src/features/uiSpacing/presentation/scripts/sharedStyles.script.ts
new file mode 100644
index 0000000..e2caafc
--- /dev/null
+++ b/src/features/uiSpacing/presentation/scripts/sharedStyles.script.ts
@@ -0,0 +1,10 @@
+import StylesheetScript from '../../../../common/architecture/scripts/stylesheet/StylesheetScript';
+
+export default class UiSpacingSharedStylesScript extends StylesheetScript {
+ stylesheet = 'css/ui_spacing/shared.css';
+ page: never;
+
+ async shouldBeInjected(): Promise<boolean> {
+ return await this.optionsProvider.isEnabled('uispacing');
+ }
+}
diff --git a/src/features/uiSpacing/presentation/scripts/twBasicStyles.script.ts b/src/features/uiSpacing/presentation/scripts/twBasicStyles.script.ts
new file mode 100644
index 0000000..20e6dc9
--- /dev/null
+++ b/src/features/uiSpacing/presentation/scripts/twBasicStyles.script.ts
@@ -0,0 +1,13 @@
+import StylesheetScript from '../../../../common/architecture/scripts/stylesheet/StylesheetScript';
+import UiSpacingSharedStylesScript from './sharedStyles.script';
+
+export default class UiSpacingTwBasicStylesScript extends StylesheetScript {
+ stylesheet = 'css/ui_spacing/twbasic.css';
+
+ runAfter = [UiSpacingSharedStylesScript];
+ page: never;
+
+ async shouldBeInjected(): Promise<boolean> {
+ return await this.optionsProvider.isEnabled('uispacing');
+ }
+}
diff --git a/webpack.config.js b/webpack.config.js
index 1eb49ba..0413c5f 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -47,7 +47,7 @@
'./src/entryPoints/communityConsole/contentScripts/start.ts',
publicForum: './src/contentScripts/publicForum.js',
publicThread: './src/contentScripts/publicThread.js',
- publicThreadStart: './src/contentScripts/publicThreadStart.js',
+ publicThreadStart: './src/entryPoints/twBasic/thread/start.ts',
publicGuide: './src/contentScripts/publicGuide.js',
publicGuideStart: './src/contentScripts/publicGuideStart.js',
publicProfile: './src/contentScripts/publicProfile.js',