settingsManager.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of the AppIndicator/KStatusNotifierItem GNOME Shell extension
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation; either version 2
  6. // of the License, or (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. let settingsManager;
  17. export class SettingsManager {
  18. static initialize(extension) {
  19. SettingsManager._settingsManager = new SettingsManager(extension);
  20. }
  21. static destroy() {
  22. SettingsManager._settingsManager.destroy();
  23. SettingsManager._settingsManager = null;
  24. }
  25. static getDefault() {
  26. return this._settingsManager;
  27. }
  28. get gsettings() {
  29. return this._gsettings;
  30. }
  31. constructor(extension) {
  32. if (settingsManager)
  33. throw new Error('SettingsManager is already constructed');
  34. this._gsettings = extension.getSettings();
  35. }
  36. destroy() {
  37. this._gsettings = null;
  38. }
  39. }
  40. export function getDefault() {
  41. return SettingsManager.getDefault();
  42. }
  43. export function getDefaultGSettings() {
  44. return SettingsManager.getDefault().gsettings;
  45. }