extensionPrefs: Hook up kill switch to D-Bus property

Now that the org.gnome.Shell.Extensions interface exposes the
disable-user-extensions setting on D-Bus, we can use that instead
of the shell's GSettings.

In a future where we distribute the app separately as flatpak, this
will require one less hole in the sandbox.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1081
This commit is contained in:
Florian Müllner 2020-03-05 18:46:18 +01:00 committed by Florian Müllner
parent 4340260c49
commit 5c031200ce
2 changed files with 27 additions and 10 deletions

View File

@ -90,8 +90,9 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSwitch" id="killSwitch"> <object class="GtkSwitch">
<property name="visible">True</property> <property name="visible">True</property>
<property name="action-name">win.user-extensions-enabled</property>
</object> </object>
<packing> <packing>
<property name="pack_type">end</property> <property name="pack_type">end</property>

View File

@ -36,6 +36,11 @@ function stripPrefix(string, prefix) {
return string; return string;
} }
function toggleState(action) {
let state = action.get_state();
action.change_state(new GLib.Variant('b', !state.get_boolean()));
}
var Application = GObject.registerClass( var Application = GObject.registerClass(
class Application extends Gtk.Application { class Application extends Gtk.Application {
_init() { _init() {
@ -94,7 +99,6 @@ var ExtensionsWindow = GObject.registerClass({
InternalChildren: [ InternalChildren: [
'userList', 'userList',
'systemList', 'systemList',
'killSwitch',
'mainBox', 'mainBox',
'mainStack', 'mainStack',
'scrolledWindow', 'scrolledWindow',
@ -121,10 +125,15 @@ var ExtensionsWindow = GObject.registerClass({
action.connect('activate', this._logout.bind(this)); action.connect('activate', this._logout.bind(this));
this.add_action(action); this.add_action(action);
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' }); action = new Gio.SimpleAction({
this._settings.bind('disable-user-extensions', name: 'user-extensions-enabled',
this._killSwitch, 'active', state: new GLib.Variant('b', false),
Gio.SettingsBindFlags.DEFAULT | Gio.SettingsBindFlags.INVERT_BOOLEAN); });
action.connect('activate', toggleState);
action.connect('change-state', (a, state) => {
this._shellProxy.UserExtensionsEnabled = state.get_boolean();
});
this.add_action(action);
this._userList.set_sort_func(this._sortList.bind(this)); this._userList.set_sort_func(this._sortList.bind(this));
this._userList.set_header_func(this._updateHeader.bind(this)); this._userList.set_header_func(this._updateHeader.bind(this));
@ -135,6 +144,10 @@ var ExtensionsWindow = GObject.registerClass({
this._shellProxy.connectSignal('ExtensionStateChanged', this._shellProxy.connectSignal('ExtensionStateChanged',
this._onExtensionStateChanged.bind(this)); this._onExtensionStateChanged.bind(this));
this._shellProxy.connect('g-properties-changed',
this._onUserExtensionsEnabledChanged.bind(this));
this._onUserExtensionsEnabledChanged();
this._scanExtensions(); this._scanExtensions();
} }
@ -388,6 +401,12 @@ var ExtensionsWindow = GObject.registerClass({
].find(c => c.uuid === uuid); ].find(c => c.uuid === uuid);
} }
_onUserExtensionsEnabledChanged() {
let action = this.lookup_action('user-extensions-enabled');
action.set_state(
new GLib.Variant('b', this._shellProxy.UserExtensionsEnabled));
}
_onExtensionStateChanged(proxy, senderName, [uuid, newState]) { _onExtensionStateChanged(proxy, senderName, [uuid, newState]) {
let extension = ExtensionUtils.deserializeExtension(newState); let extension = ExtensionUtils.deserializeExtension(newState);
let row = this._findExtensionRow(uuid); let row = this._findExtensionRow(uuid);
@ -632,10 +651,7 @@ var ExtensionRow = GObject.registerClass({
name: 'enabled', name: 'enabled',
state: new GLib.Variant('b', false), state: new GLib.Variant('b', false),
}); });
action.connect('activate', () => { action.connect('activate', toggleState);
let state = action.get_state();
action.change_state(new GLib.Variant('b', !state.get_boolean()));
});
action.connect('change-state', (a, state) => { action.connect('change-state', (a, state) => {
if (state.get_boolean()) if (state.get_boolean())
this._app.shellProxy.EnableExtensionRemote(this.uuid); this._app.shellProxy.EnableExtensionRemote(this.uuid);