Devices.jsm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. "use strict";
  5. Components.utils.import("resource://devtools/shared/event-emitter.js");
  6. const EXPORTED_SYMBOLS = ["Devices"];
  7. var addonInstalled = false;
  8. const Devices = {
  9. _devices: {},
  10. get helperAddonInstalled() {
  11. return addonInstalled;
  12. },
  13. set helperAddonInstalled(v) {
  14. addonInstalled = v;
  15. if (!addonInstalled) {
  16. for (let name in this._devices) {
  17. this.unregister(name);
  18. }
  19. }
  20. this.emit("addon-status-updated", v);
  21. },
  22. register: function (name, device) {
  23. this._devices[name] = device;
  24. this.emit("register");
  25. },
  26. unregister: function (name) {
  27. delete this._devices[name];
  28. this.emit("unregister");
  29. },
  30. available: function () {
  31. return Object.keys(this._devices).sort();
  32. },
  33. getByName: function (name) {
  34. return this._devices[name];
  35. }
  36. };
  37. Object.defineProperty(this, "Devices", {
  38. value: Devices,
  39. enumerable: true,
  40. writable: false
  41. });
  42. EventEmitter.decorate(Devices);