Adrià Vilanova Martínez | 6ecaa0d | 2024-10-26 17:04:32 +0200 | [diff] [blame] | 1 | import CssSelectorNodeWatcherHandler from '../../../infrastructure/presentation/nodeWatcher/handlers/CssSelectorHandler.adapter'; |
Adrià Vilanova Martínez | 43c7520 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 2 | import { NodeMutation } from '../../../presentation/nodeWatcher/NodeWatcherHandler'; |
Adrià Vilanova Martínez | 6ecaa0d | 2024-10-26 17:04:32 +0200 | [diff] [blame] | 3 | import { OptionsProviderPort } from '../../../services/options/OptionsProvider'; |
Adrià Vilanova Martínez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame] | 4 | import { injectDarkThemeButton } from '../core/logic/darkTheme'; |
Adrià Vilanova Martínez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame] | 5 | |
| 6 | /** |
| 7 | * Injects the dark theme button. |
| 8 | */ |
Adrià Vilanova Martínez | 6ecaa0d | 2024-10-26 17:04:32 +0200 | [diff] [blame] | 9 | export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherHandler { |
Adrià Vilanova Martínez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame] | 10 | cssSelector = 'ec-app'; |
| 11 | |
Adrià Vilanova Martínez | 6ecaa0d | 2024-10-26 17:04:32 +0200 | [diff] [blame] | 12 | constructor(private optionsProvider: OptionsProviderPort) { |
| 13 | super(); |
| 14 | } |
| 15 | |
Adrià Vilanova Martínez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame] | 16 | async onMutatedNode(mutation: NodeMutation) { |
| 17 | if (!(mutation.node instanceof Element)) return; |
| 18 | |
Adrià Vilanova Martínez | 6ecaa0d | 2024-10-26 17:04:32 +0200 | [diff] [blame] | 19 | const isEnabled = await this.optionsProvider.isEnabled('ccdarktheme'); |
| 20 | const mode = await this.optionsProvider.getOptionValue('ccdarktheme_mode'); |
Adrià Vilanova Martínez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame] | 21 | |
| 22 | // TODO(avm99963): make this feature dynamic. |
| 23 | if (isEnabled && mode === 'switch') { |
| 24 | const rightControl = mutation.node.querySelector('header .right-control'); |
| 25 | if (rightControl === null) return; |
| 26 | injectDarkThemeButton(rightControl); |
| 27 | } |
| 28 | } |
| 29 | } |