2023-12-19 15:14:19 +01:00
|
|
|
import Adw from 'gi://Adw?version=1';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
import {ExtensionState} from './misc/extensionUtils.js';
|
2023-12-19 18:45:04 +01:00
|
|
|
import {Extension} from './extensionManager.js';
|
2023-12-19 15:14:19 +01:00
|
|
|
|
|
|
|
export const ExtensionRow = GObject.registerClass({
|
|
|
|
GTypeName: 'ExtensionRow',
|
|
|
|
Template: 'resource:///org/gnome/Extensions/ui/extension-row.ui',
|
2023-12-19 18:45:04 +01:00
|
|
|
Properties: {
|
|
|
|
'extension': GObject.ParamSpec.object(
|
|
|
|
'extension', null, null,
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
Extension),
|
|
|
|
},
|
2023-12-19 15:14:19 +01:00
|
|
|
InternalChildren: [
|
|
|
|
'detailsPopover',
|
|
|
|
'descriptionLabel',
|
|
|
|
'versionLabel',
|
|
|
|
'errorLabel',
|
|
|
|
'errorButton',
|
|
|
|
'updatesButton',
|
|
|
|
'switch',
|
|
|
|
'actionsBox',
|
|
|
|
],
|
|
|
|
}, class ExtensionRow extends Adw.ActionRow {
|
2023-12-19 18:45:04 +01:00
|
|
|
constructor(extension) {
|
|
|
|
super({extension});
|
2023-12-19 15:14:19 +01:00
|
|
|
|
|
|
|
this._app = Gio.Application.get_default();
|
|
|
|
|
|
|
|
this._actionGroup = new Gio.SimpleActionGroup();
|
|
|
|
this.insert_action_group('row', this._actionGroup);
|
|
|
|
|
|
|
|
let action;
|
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'show-prefs',
|
2023-12-18 20:20:26 +01:00
|
|
|
enabled: extension.hasPrefs,
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
action.connect('activate', () => {
|
|
|
|
this._detailsPopover.popdown();
|
2023-12-18 20:20:26 +01:00
|
|
|
this.get_root().openPrefs(extension);
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'show-url',
|
2023-12-18 20:20:26 +01:00
|
|
|
enabled: extension.url !== '',
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
action.connect('activate', () => {
|
|
|
|
this._detailsPopover.popdown();
|
|
|
|
Gio.AppInfo.launch_default_for_uri(
|
2023-12-18 20:20:26 +01:00
|
|
|
extension.url, this.get_display().get_app_launch_context());
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'uninstall',
|
2023-12-18 20:20:26 +01:00
|
|
|
enabled: extension.isUser,
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
action.connect('activate', () => {
|
|
|
|
this._detailsPopover.popdown();
|
2023-12-18 20:20:26 +01:00
|
|
|
this.get_root().uninstall(extension);
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'enabled',
|
|
|
|
state: new GLib.Variant('b', false),
|
|
|
|
});
|
|
|
|
action.connect('activate', () => {
|
|
|
|
const state = action.get_state();
|
|
|
|
action.change_state(new GLib.Variant('b', !state.get_boolean()));
|
|
|
|
});
|
|
|
|
action.connect('change-state', (a, state) => {
|
2023-12-18 20:20:26 +01:00
|
|
|
const {uuid} = this._extension;
|
2023-12-19 15:14:19 +01:00
|
|
|
if (state.get_boolean())
|
2023-12-18 20:20:26 +01:00
|
|
|
this._app.extensionManager.enableExtension(uuid);
|
2023-12-19 15:14:19 +01:00
|
|
|
else
|
2023-12-18 20:20:26 +01:00
|
|
|
this._app.extensionManager.disableExtension(uuid);
|
2023-12-19 15:14:19 +01:00
|
|
|
});
|
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
this.title = extension.name;
|
2023-12-19 15:14:19 +01:00
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
this._descriptionLabel.label = extension.description;
|
2023-12-19 15:14:19 +01:00
|
|
|
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
this._extensionStateChangedId = this._app.extensionManager.connect(
|
|
|
|
`extension-changed::${extension.uuid}`, () => this._updateState());
|
2023-12-19 15:14:19 +01:00
|
|
|
this._updateState();
|
|
|
|
}
|
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
get extension() {
|
2023-12-19 18:45:04 +01:00
|
|
|
return this._extension ?? null;
|
|
|
|
}
|
|
|
|
|
|
|
|
set extension(ext) {
|
|
|
|
this._extension = ext;
|
2023-12-19 15:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_updateState() {
|
|
|
|
const state = this._extension.state === ExtensionState.ENABLED;
|
|
|
|
|
|
|
|
const action = this._actionGroup.lookup_action('enabled');
|
|
|
|
action.set_state(new GLib.Variant('b', state));
|
|
|
|
action.enabled = this._extension.canChange;
|
|
|
|
|
|
|
|
if (!action.enabled)
|
|
|
|
this._switch.active = state;
|
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
this._updatesButton.visible = this._extension.hasUpdate;
|
|
|
|
this._errorButton.visible = this._extension.hasError;
|
|
|
|
this._errorLabel.label = this._extension.error;
|
2023-12-19 15:14:19 +01:00
|
|
|
|
2023-12-18 20:20:26 +01:00
|
|
|
this._versionLabel.label = _('Version %s').format(this._extension.version);
|
|
|
|
this._versionLabel.visible = this._extension.version !== '';
|
2023-12-19 15:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_onDestroy() {
|
|
|
|
if (this._extensionStateChangedId)
|
2023-12-18 20:20:26 +01:00
|
|
|
this._app.extensionManager.disconnect(this._extensionStateChangedId);
|
|
|
|
delete this._extensionStateChangedId;
|
2023-12-19 15:14:19 +01:00
|
|
|
}
|
|
|
|
});
|