general.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict'
  2. import GLib from 'gi://GLib';
  3. import Adw from 'gi://Adw';
  4. import GObject from 'gi://GObject';
  5. import Gio from 'gi://Gio';
  6. import * as Utils from './utils.js';
  7. export const General = GObject.registerClass({
  8. GTypeName: 'GeneralPrefs',
  9. Template: GLib.Uri.resolve_relative(import.meta.url, '../ui/general.ui',GLib.UriFlags.NONE),
  10. InternalChildren: [
  11. 'indicator_mode',
  12. 'color_mode',
  13. 'show_values',
  14. 'show_notifications',
  15. 'reset_all',
  16. 'reset_dialog',
  17. ],
  18. }, class General extends Adw.PreferencesPage {
  19. constructor(window) {
  20. super({});
  21. Utils.bindAdwComboRow(this._indicator_mode, window._settings, 'indicator-mode');
  22. window._settings.bind(
  23. 'color-mode',
  24. this._color_mode,
  25. 'active',
  26. Gio.SettingsBindFlags.DEFAULT
  27. );
  28. window._settings.bind(
  29. 'show-current-values',
  30. this._show_values,
  31. 'active',
  32. Gio.SettingsBindFlags.DEFAULT
  33. );
  34. window._settings.bind(
  35. 'show-notifications',
  36. this._show_notifications,
  37. 'active',
  38. Gio.SettingsBindFlags.DEFAULT
  39. );
  40. this._reset_dialog.connect('response', (obj, response, data) => {
  41. if (response === 'reset') {
  42. this._resetSettings(window._settings);
  43. window._driver.enableAll();
  44. }
  45. });
  46. this._reset_all.connect('clicked', () => {
  47. this._reset_dialog.transientFor = this.root;
  48. this._reset_dialog.present();
  49. });
  50. }
  51. /**
  52. * Reset all (recursively) settings values to default
  53. *
  54. * @param {Gio.Settings} settings Settings to reset
  55. */
  56. _resetSettings(settings) {
  57. const keys = settings.settings_schema.list_keys();
  58. keys.forEach(key => {
  59. settings.reset(key);
  60. });
  61. const childrens = settings.settings_schema.list_children();
  62. childrens.forEach(children => {
  63. const childrenSettings = settings.get_child(children);
  64. this._resetSettings(childrenSettings);
  65. });
  66. }
  67. });