Adrià Vilanova MartÃnez | 917797e | 2024-05-25 22:41:25 +0200 | [diff] [blame^] | 1 | import CssSelectorNodeWatcherScriptHandler from '../../../common/architecture/scripts/nodeWatcher/handlers/CssSelectorNodeWatcherScriptHandler'; |
| 2 | import { NodeMutation } from '../../../common/nodeWatcher/NodeWatcherHandler'; |
| 3 | import { injectDarkThemeButton } from '../core/logic/darkTheme'; |
| 4 | import { CCDarkThemeNodeWatcherDependencies } from '../scripts/nodeWatcher.script'; |
| 5 | |
| 6 | /** |
| 7 | * Injects the dark theme button. |
| 8 | */ |
| 9 | export default class CCDarkThemeEcAppHandler extends CssSelectorNodeWatcherScriptHandler<CCDarkThemeNodeWatcherDependencies> { |
| 10 | cssSelector = 'ec-app'; |
| 11 | |
| 12 | async onMutatedNode(mutation: NodeMutation) { |
| 13 | if (!(mutation.node instanceof Element)) return; |
| 14 | |
| 15 | const optionsProvider = this.options.optionsProvider; |
| 16 | const isEnabled = await optionsProvider.isEnabled('ccdarktheme'); |
| 17 | const mode = await optionsProvider.getOptionValue('ccdarktheme_mode'); |
| 18 | |
| 19 | // TODO(avm99963): make this feature dynamic. |
| 20 | if (isEnabled && mode === 'switch') { |
| 21 | const rightControl = mutation.node.querySelector('header .right-control'); |
| 22 | if (rightControl === null) return; |
| 23 | injectDarkThemeButton(rightControl); |
| 24 | } |
| 25 | } |
| 26 | } |