From 6029380267879eb6491a9f429afa22b380da4fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 16 Dec 2024 14:33:00 +0100 Subject: [PATCH] status/a11y: Simplify switch setup Almost all switches represent boolean settings, which means we can use bindings instead of fiddling with signal handlers. As menu items have a `:sensitive` property, this also deals with handling keys' writability. Part-of: --- js/ui/status/accessibility.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js index b36c64868..5e6c447f3 100644 --- a/js/ui/status/accessibility.js +++ b/js/ui/status/accessibility.js @@ -118,17 +118,12 @@ class ATIndicator extends PanelMenu.Button { } _buildItem(string, schema, key) { - let settings = new Gio.Settings({schema_id: schema}); - let widget = this._buildItemExtended(string, - settings.get_boolean(key), - settings.is_writable(key), - enabled => settings.set_boolean(key, enabled)); + const settings = new Gio.Settings({schema_id: schema}); + const widget = new PopupMenu.PopupSwitchMenuItem(string, false); + settings.bind(key, widget, 'state', Gio.SettingsBindFlags.DEFAULT); - settings.connect(`changed::${key}`, () => { - widget.setToggleState(settings.get_boolean(key)); - - this._queueSyncMenuVisibility(); - }); + widget.connect('toggled', + () => this._queueSyncMenuVisibility()); return widget; }