extensions-app: Use property bindings in row

Now that extensions are represented as GObjects, we can update
the UI via property bindings instead of manually handling the
logic in the code.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3067>
This commit is contained in:
Florian Müllner
2023-12-19 18:57:37 +01:00
committed by Marge Bot
parent 1f7ca2bf38
commit 2c592059bc
2 changed files with 37 additions and 26 deletions

View File

@ -17,11 +17,7 @@ export const ExtensionRow = GObject.registerClass({
},
InternalChildren: [
'detailsPopover',
'descriptionLabel',
'versionLabel',
'errorLabel',
'errorButton',
'updatesButton',
'switch',
'actionsBox',
],
@ -78,14 +74,14 @@ export const ExtensionRow = GObject.registerClass({
this._actionGroup.add_action_entries(actionEntries);
this._bindActionEnabled(actionEntries);
this.title = extension.name;
this._extension.bind_property_full('version',
this._versionLabel, 'label',
GObject.BindingFlags.SYNC_CREATE,
(bind, source) => [true, _('Version %s').format(source)],
null);
this._descriptionLabel.label = extension.description;
this.connect('destroy', this._onDestroy.bind(this));
this._extensionStateChangedId = this._app.extensionManager.connect(
`extension-changed::${extension.uuid}`, () => this._updateState());
this._extension.connect('notify::state',
() => this._updateState());
this._updateState();
}
@ -126,18 +122,5 @@ export const ExtensionRow = GObject.registerClass({
if (!action.enabled)
this._switch.active = state;
this._updatesButton.visible = this._extension.hasUpdate;
this._errorButton.visible = this._extension.hasError;
this._errorLabel.label = this._extension.error;
this._versionLabel.label = _('Version %s').format(this._extension.version);
this._versionLabel.visible = this._extension.version !== '';
}
_onDestroy() {
if (this._extensionStateChangedId)
this._app.extensionManager.disconnect(this._extensionStateChangedId);
delete this._extensionStateChangedId;
}
});