Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 1 | import MainWorldContentScriptBridgeClient from '../mainWorldContentScriptBridge/Client.js'; |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 2 | |
| 3 | // Main World OptionsWatcher client (used in scripts injected into the Main |
| 4 | // World (MW) to get the options). |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 5 | export default class MWOptionsWatcherClient extends |
| 6 | MainWorldContentScriptBridgeClient { |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 7 | constructor(options, CSTarget, MWTarget, timeout) { |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 8 | super(CSTarget, MWTarget, timeout); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 9 | this.#setUp(options); |
| 10 | } |
| 11 | |
| 12 | #setUp(options) { |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 13 | this._sendRequestWithoutCallback('setUp', {options}); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | async getOption(option) { |
| 17 | if (!option) return null; |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 18 | return this._sendRequest('getOption', {option}); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | async getOptions(options) { |
| 22 | if (!options || options?.length === 0) return []; |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 23 | return this._sendRequest('getOptions', {options}); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | async isEnabled(option) { |
| 27 | if (!option) return null; |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 28 | return this._sendRequest('isEnabled', {option}); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | async areEnabled(options) { |
| 32 | if (!options || options?.length === 0) return []; |
Adrià Vilanova Martínez | 2548e44 | 2023-03-05 18:45:30 +0100 | [diff] [blame] | 33 | return this._sendRequest('areEnabled', {options}); |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 34 | } |
| 35 | } |