tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

eventonprefchange.sys.mjs (881B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs";
      6 
      7 const TEST_PREF = "remote.messagehandler.test.pref";
      8 
      9 class EventOnPrefChangeModule extends Module {
     10  constructor(messageHandler) {
     11    super(messageHandler);
     12    Services.prefs.addObserver(TEST_PREF, this.#onPreferenceUpdated);
     13  }
     14 
     15  destroy() {
     16    Services.prefs.removeObserver(TEST_PREF, this.#onPreferenceUpdated);
     17  }
     18 
     19  #onPreferenceUpdated = () => {
     20    this.emitEvent("preference-changed");
     21  };
     22 
     23  /**
     24   * Commands
     25   */
     26 
     27  ping() {
     28    // We only use this command to force creating the module.
     29    return 1;
     30  }
     31 }
     32 
     33 export const eventonprefchange = EventOnPrefChangeModule;