blob: 02df59b40472ad0661085344a46552fbfe66ce65 [file] [log] [blame]
Adrià Vilanova Martínez825888a2023-07-23 01:53:48 +02001import InternalKillSwitchWatcher from '../killSwitch/internalKillSwitchWatcher.js';
2
3export const KILL_SWITCH = 'killswitch_xhrproxy';
4export const KILL_SWITCH_LOCALSTORAGE_KEY = 'TWPTKillSwitchXHRProxyEnabled';
5export const KILL_SWITCH_LOCALSTORAGE_VALUE = 'true';
6
7export 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}