Adrià Vilanova MartÃnez | 825888a | 2023-07-23 01:53:48 +0200 | [diff] [blame] | 1 | import InternalKillSwitchWatcher from '../killSwitch/internalKillSwitchWatcher.js'; |
| 2 | |
| 3 | export const KILL_SWITCH = 'killswitch_xhrproxy'; |
| 4 | export const KILL_SWITCH_LOCALSTORAGE_KEY = 'TWPTKillSwitchXHRProxyEnabled'; |
| 5 | export const KILL_SWITCH_LOCALSTORAGE_VALUE = 'true'; |
| 6 | |
| 7 | export default class XHRProxyKillSwitchHandler { |
| 8 | constructor() { |
| 9 | this.watcher = |
| 10 | new InternalKillSwitchWatcher(KILL_SWITCH, this.onChange, true); |
| 11 | } |
| 12 | |
| 13 | onChange(isActive) { |
| 14 | if (isActive) { |
| 15 | window.localStorage.setItem( |
| 16 | KILL_SWITCH_LOCALSTORAGE_KEY, KILL_SWITCH_LOCALSTORAGE_VALUE); |
| 17 | } else { |
| 18 | window.localStorage.removeItem(KILL_SWITCH_LOCALSTORAGE_KEY); |
| 19 | } |
| 20 | } |
| 21 | } |