Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 1 | // Most options are dynamic, which means whenever they are enabled or disabled, |
| 2 | // the effect is immediate. However, some features aren't controlled directly in |
| 3 | // content scripts or injected scripts but instead in the background |
| 4 | // script/service worker. |
| 5 | // |
Adrià Vilanova Martínez | 879d44a | 2024-05-17 15:30:03 +0200 | [diff] [blame] | 6 | // An example was the "blockdrafts" feature, which when enabled enabled the |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 7 | // static ruleset blocking *DraftMessages requests. |
Adrià Vilanova Martínez | 879d44a | 2024-05-17 15:30:03 +0200 | [diff] [blame] | 8 | // |
| 9 | // The "blockdrafts" feature was removed, but this logic has been kept in case |
| 10 | // it is needed in the future. |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 11 | |
Adrià Vilanova Martínez | b523be9 | 2024-05-25 19:14:19 +0200 | [diff] [blame^] | 12 | import {isOptionEnabled} from '../common/options/optionsUtils.js'; |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 13 | |
| 14 | // List of features controled in the background: |
Adrià Vilanova Martínez | 879d44a | 2024-05-17 15:30:03 +0200 | [diff] [blame] | 15 | export var bgFeatures = []; |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 16 | |
| 17 | export function handleBgOptionChange(feature) { |
| 18 | isOptionEnabled(feature) |
Adrià Vilanova Martínez | 879d44a | 2024-05-17 15:30:03 +0200 | [diff] [blame] | 19 | // eslint-disable-next-line no-unused-vars |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 20 | .then(enabled => { |
Adrià Vilanova Martínez | 879d44a | 2024-05-17 15:30:03 +0200 | [diff] [blame] | 21 | // eslint-disable-next-line no-empty |
| 22 | switch (feature) {} |
Adrià Vilanova Martínez | a4dd5fd | 2022-01-05 04:23:44 +0100 | [diff] [blame] | 23 | }) |
| 24 | .catch(err => { |
| 25 | console.error( |
| 26 | 'handleBgOptionChange: error while handling feature "' + feature + |
| 27 | '": ', |
| 28 | err); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | export function handleBgOptionsOnStart() { |
| 33 | for (let feature of bgFeatures) handleBgOptionChange(feature); |
| 34 | } |