2019-01-31 14:07:06 +00:00
|
|
|
/* exported main */
|
Specify API versions for all public GIR APIs, except GLib
If one of these libraries breaks its GIR API in future, then upgrading
packages unrelated to gnome-shell might pull in the newer version,
causing gnome-shell to crash when it gets a newer GIR API that is
incompatible with its expectations. For example, this seems to be
happening in Debian testing at the moment, when GNOME Shell 41.4
imports GWeather and can get version 4.0 instead of the version 3.0 that
it expected.
Adding explicit API versions at the time the newer version is released
is too late, because that will still let the newer version of the GIR API
break pre-existing GNOME Shell packages. Prevent similar crashes in
future by making the desired versions explicit.
This is done for all third-party libraries except GLib, similar to the
common practice in Python code; if GLib breaks API, then that will be
a disruptive change to the whole GLib/GObject ecosystem, regardless.
Gvc, Meta, Shell, Shew, St are not included because they're private
(only exist in a non-default search path entry).
Clutter and Cogl *are* included, because we need to import the fork of
them that comes with Meta, as opposed to their deprecated standalone
versions.
Signed-off-by: Simon McVittie <smcv@debian.org>
Bug-Debian: https://bugs.debian.org/1008926
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2261>
2022-04-04 10:26:43 +00:00
|
|
|
imports.gi.versions.Adw = '1';
|
2020-04-15 18:27:15 +00:00
|
|
|
imports.gi.versions.Gtk = '4.0';
|
2019-08-21 17:36:42 +00:00
|
|
|
|
2012-01-19 02:21:56 +00:00
|
|
|
const Gettext = imports.gettext;
|
2020-03-19 19:38:16 +00:00
|
|
|
const Package = imports.package;
|
2022-01-05 13:51:53 +00:00
|
|
|
const { Adw, GLib, Gio, GObject, Gtk, Shew } = imports.gi;
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2020-03-19 19:38:16 +00:00
|
|
|
Package.initFormat();
|
2012-01-19 02:21:56 +00:00
|
|
|
|
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
|
|
|
2019-11-30 05:06:08 +00:00
|
|
|
const { ExtensionState, ExtensionType } = ExtensionUtils;
|
2018-11-01 12:55:17 +00:00
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const GnomeShellIface = loadInterfaceXML('org.gnome.Shell.Extensions');
|
2012-01-19 02:21:56 +00:00
|
|
|
const GnomeShellProxy = Gio.DBusProxy.makeProxyWrapper(GnomeShellIface);
|
|
|
|
|
2022-02-10 23:09:54 +00:00
|
|
|
Gio._promisify(Gio.DBusConnection.prototype, 'call');
|
|
|
|
Gio._promisify(Shew.WindowExporter.prototype, 'export');
|
2020-03-05 17:01:38 +00:00
|
|
|
|
2020-03-07 18:26:06 +00:00
|
|
|
function loadInterfaceXML(iface) {
|
2022-02-07 14:14:06 +00:00
|
|
|
const uri = `resource:///org/gnome/Extensions/dbus-interfaces/${iface}.xml`;
|
2020-03-07 18:26:06 +00:00
|
|
|
const f = Gio.File.new_for_uri(uri);
|
|
|
|
|
|
|
|
try {
|
|
|
|
let [ok_, bytes] = f.load_contents(null);
|
2021-08-12 14:38:57 +00:00
|
|
|
return new TextDecoder().decode(bytes);
|
2020-03-07 18:26:06 +00:00
|
|
|
} catch (e) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Failed to load D-Bus interface ${iface}`);
|
2020-03-07 18:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-05 17:46:18 +00:00
|
|
|
function toggleState(action) {
|
|
|
|
let state = action.get_state();
|
|
|
|
action.change_state(new GLib.Variant('b', !state.get_boolean()));
|
|
|
|
}
|
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var Application = GObject.registerClass(
|
2021-10-04 13:18:51 +00:00
|
|
|
class Application extends Adw.Application {
|
2019-05-28 21:22:37 +00:00
|
|
|
_init() {
|
2020-04-10 02:27:31 +00:00
|
|
|
GLib.set_prgname('gnome-extensions-app');
|
2021-01-22 21:08:41 +00:00
|
|
|
super._init({ application_id: Package.name });
|
2020-11-18 01:16:26 +00:00
|
|
|
|
|
|
|
this.connect('window-removed', (a, window) => window.run_dispose());
|
2019-11-30 01:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get shellProxy() {
|
|
|
|
return this._shellProxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_activate() {
|
2020-01-26 23:47:18 +00:00
|
|
|
this._shellProxy.CheckForUpdatesRemote();
|
2019-11-30 01:48:18 +00:00
|
|
|
this._window.present();
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_startup() {
|
|
|
|
super.vfunc_startup();
|
|
|
|
|
2020-10-28 20:42:48 +00:00
|
|
|
const action = new Gio.SimpleAction({ name: 'quit' });
|
|
|
|
action.connect('activate', () => this._window.close());
|
|
|
|
this.add_action(action);
|
|
|
|
|
|
|
|
this.set_accels_for_action('app.quit', ['<Primary>q']);
|
|
|
|
|
2020-03-04 04:05:08 +00:00
|
|
|
this._shellProxy = new GnomeShellProxy(Gio.DBus.session,
|
|
|
|
'org.gnome.Shell.Extensions', '/org/gnome/Shell/Extensions');
|
|
|
|
|
2019-11-30 01:48:18 +00:00
|
|
|
this._window = new ExtensionsWindow({ application: this });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-30 01:48:18 +00:00
|
|
|
var ExtensionsWindow = GObject.registerClass({
|
|
|
|
GTypeName: 'ExtensionsWindow',
|
2020-03-05 16:44:27 +00:00
|
|
|
Template: 'resource:///org/gnome/Extensions/ui/extensions-window.ui',
|
2019-11-30 01:48:18 +00:00
|
|
|
InternalChildren: [
|
2021-10-18 13:18:11 +00:00
|
|
|
'userGroup',
|
2019-11-30 07:08:05 +00:00
|
|
|
'userList',
|
2021-10-18 13:18:11 +00:00
|
|
|
'systemGroup',
|
2019-11-30 07:08:05 +00:00
|
|
|
'systemList',
|
2019-11-30 01:48:18 +00:00
|
|
|
'mainStack',
|
2020-11-11 01:37:20 +00:00
|
|
|
'searchBar',
|
|
|
|
'searchButton',
|
|
|
|
'searchEntry',
|
2019-11-30 14:20:04 +00:00
|
|
|
'updatesBar',
|
|
|
|
'updatesLabel',
|
2019-11-30 01:48:18 +00:00
|
|
|
],
|
|
|
|
}, class ExtensionsWindow extends Gtk.ApplicationWindow {
|
2019-11-30 01:48:18 +00:00
|
|
|
_init(params) {
|
|
|
|
super._init(params);
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
this._updatesCheckId = 0;
|
2019-11-30 01:48:18 +00:00
|
|
|
|
2020-03-05 17:01:38 +00:00
|
|
|
this._exporter = new Shew.WindowExporter({ window: this });
|
|
|
|
this._exportedHandle = '';
|
|
|
|
|
2019-11-30 05:51:35 +00:00
|
|
|
let action;
|
|
|
|
action = new Gio.SimpleAction({ name: 'show-about' });
|
|
|
|
action.connect('activate', this._showAbout.bind(this));
|
|
|
|
this.add_action(action);
|
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
action = new Gio.SimpleAction({ name: 'logout' });
|
|
|
|
action.connect('activate', this._logout.bind(this));
|
|
|
|
this.add_action(action);
|
|
|
|
|
2020-03-05 17:46:18 +00:00
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'user-extensions-enabled',
|
|
|
|
state: new GLib.Variant('b', false),
|
|
|
|
});
|
|
|
|
action.connect('activate', toggleState);
|
|
|
|
action.connect('change-state', (a, state) => {
|
|
|
|
this._shellProxy.UserExtensionsEnabled = state.get_boolean();
|
|
|
|
});
|
|
|
|
this.add_action(action);
|
2019-11-30 01:48:18 +00:00
|
|
|
|
2020-11-11 01:37:20 +00:00
|
|
|
this._searchTerms = [];
|
|
|
|
this._searchEntry.connect('search-changed', () => {
|
|
|
|
const { text } = this._searchEntry;
|
|
|
|
if (text === '')
|
|
|
|
this._searchTerms = [];
|
|
|
|
else
|
|
|
|
[this._searchTerms] = GLib.str_tokenize_and_fold(text, null);
|
|
|
|
|
|
|
|
this._userList.invalidate_filter();
|
|
|
|
this._systemList.invalidate_filter();
|
|
|
|
});
|
|
|
|
|
2019-11-30 07:08:05 +00:00
|
|
|
this._userList.set_sort_func(this._sortList.bind(this));
|
2020-11-11 01:37:20 +00:00
|
|
|
this._userList.set_filter_func(this._filterList.bind(this));
|
|
|
|
this._userList.set_placeholder(new Gtk.Label({
|
|
|
|
label: _('No Matches'),
|
2020-04-15 18:27:15 +00:00
|
|
|
margin_start: 12,
|
|
|
|
margin_end: 12,
|
|
|
|
margin_top: 12,
|
|
|
|
margin_bottom: 12,
|
2020-11-11 01:37:20 +00:00
|
|
|
}));
|
2022-01-18 12:04:55 +00:00
|
|
|
this._userList.connect('row-activated', (_list, row) => row.activate());
|
2019-11-30 07:08:05 +00:00
|
|
|
|
|
|
|
this._systemList.set_sort_func(this._sortList.bind(this));
|
2020-11-11 01:37:20 +00:00
|
|
|
this._systemList.set_filter_func(this._filterList.bind(this));
|
|
|
|
this._systemList.set_placeholder(new Gtk.Label({
|
|
|
|
label: _('No Matches'),
|
2020-04-15 18:27:15 +00:00
|
|
|
margin_start: 12,
|
|
|
|
margin_end: 12,
|
|
|
|
margin_top: 12,
|
|
|
|
margin_bottom: 12,
|
2020-11-11 01:37:20 +00:00
|
|
|
}));
|
2022-01-18 12:04:55 +00:00
|
|
|
this._systemList.connect('row-activated', (_list, row) => row.activate());
|
2019-11-30 01:48:18 +00:00
|
|
|
|
|
|
|
this._shellProxy.connectSignal('ExtensionStateChanged',
|
|
|
|
this._onExtensionStateChanged.bind(this));
|
|
|
|
|
2020-03-05 17:46:18 +00:00
|
|
|
this._shellProxy.connect('g-properties-changed',
|
|
|
|
this._onUserExtensionsEnabledChanged.bind(this));
|
|
|
|
this._onUserExtensionsEnabledChanged();
|
|
|
|
|
2019-11-30 01:48:18 +00:00
|
|
|
this._scanExtensions();
|
2018-11-01 12:55:17 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 01:48:18 +00:00
|
|
|
get _shellProxy() {
|
|
|
|
return this.application.shellProxy;
|
|
|
|
}
|
|
|
|
|
2019-11-30 05:06:08 +00:00
|
|
|
uninstall(uuid) {
|
|
|
|
let row = this._findExtensionRow(uuid);
|
|
|
|
|
|
|
|
let dialog = new Gtk.MessageDialog({
|
|
|
|
transient_for: this,
|
|
|
|
modal: true,
|
|
|
|
text: _('Remove “%s”?').format(row.name),
|
|
|
|
secondary_text: _('If you remove the extension, you need to return to download it if you want to enable it again'),
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.add_button(_('Cancel'), Gtk.ResponseType.CANCEL);
|
|
|
|
dialog.add_button(_('Remove'), Gtk.ResponseType.ACCEPT)
|
|
|
|
.get_style_context().add_class('destructive-action');
|
|
|
|
|
|
|
|
dialog.connect('response', (dlg, response) => {
|
|
|
|
if (response === Gtk.ResponseType.ACCEPT)
|
|
|
|
this._shellProxy.UninstallExtensionRemote(uuid);
|
|
|
|
dialog.destroy();
|
|
|
|
});
|
|
|
|
dialog.present();
|
|
|
|
}
|
|
|
|
|
2020-03-05 17:01:38 +00:00
|
|
|
async openPrefs(uuid) {
|
|
|
|
if (!this._exportedHandle) {
|
|
|
|
try {
|
|
|
|
this._exportedHandle = await this._exporter.export();
|
|
|
|
} catch (e) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Failed to export window: ${e.message}`);
|
2020-03-05 17:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 04:05:08 +00:00
|
|
|
this._shellProxy.OpenExtensionPrefsRemote(uuid,
|
2020-03-05 17:01:38 +00:00
|
|
|
this._exportedHandle,
|
2020-03-04 04:05:08 +00:00
|
|
|
{ modal: new GLib.Variant('b', true) });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2019-11-30 05:51:35 +00:00
|
|
|
_showAbout() {
|
|
|
|
let aboutDialog = new Gtk.AboutDialog({
|
|
|
|
authors: [
|
|
|
|
'Florian Müllner <fmuellner@gnome.org>',
|
|
|
|
'Jasper St. Pierre <jstpierre@mecheye.net>',
|
|
|
|
'Didier Roche <didrocks@ubuntu.com>',
|
2022-01-18 12:24:21 +00:00
|
|
|
'Romain Vigier <contact@romainvigier.fr>',
|
2019-11-30 05:51:35 +00:00
|
|
|
],
|
|
|
|
translator_credits: _('translator-credits'),
|
2020-01-24 16:00:24 +00:00
|
|
|
program_name: _('Extensions'),
|
2019-11-30 05:51:35 +00:00
|
|
|
comments: _('Manage your GNOME Extensions'),
|
|
|
|
license_type: Gtk.License.GPL_2_0,
|
2021-01-22 21:08:41 +00:00
|
|
|
logo_icon_name: Package.name,
|
|
|
|
version: Package.version,
|
2019-11-30 05:51:35 +00:00
|
|
|
|
|
|
|
transient_for: this,
|
|
|
|
modal: true,
|
|
|
|
});
|
|
|
|
aboutDialog.present();
|
|
|
|
}
|
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
_logout() {
|
|
|
|
this.application.get_dbus_connection().call(
|
|
|
|
'org.gnome.SessionManager',
|
|
|
|
'/org/gnome/SessionManager',
|
|
|
|
'org.gnome.SessionManager',
|
|
|
|
'Logout',
|
|
|
|
new GLib.Variant('(u)', [0]),
|
|
|
|
null,
|
|
|
|
Gio.DBusCallFlags.NONE,
|
|
|
|
-1,
|
2019-12-19 19:50:37 +00:00
|
|
|
null);
|
2019-11-30 14:20:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sortList(row1, row2) {
|
2018-11-01 12:50:30 +00:00
|
|
|
return row1.name.localeCompare(row2.name);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-05-23 02:49:37 +00:00
|
|
|
|
2020-11-11 01:37:20 +00:00
|
|
|
_filterList(row) {
|
|
|
|
return this._searchTerms.every(
|
|
|
|
t => row.keywords.some(k => k.startsWith(t)));
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
_findExtensionRow(uuid) {
|
2019-11-30 07:08:05 +00:00
|
|
|
return [
|
2020-04-15 18:27:15 +00:00
|
|
|
...this._userList,
|
|
|
|
...this._systemList,
|
2019-11-30 07:08:05 +00:00
|
|
|
].find(c => c.uuid === uuid);
|
2018-11-01 12:55:17 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 17:46:18 +00:00
|
|
|
_onUserExtensionsEnabledChanged() {
|
|
|
|
let action = this.lookup_action('user-extensions-enabled');
|
|
|
|
action.set_state(
|
|
|
|
new GLib.Variant('b', this._shellProxy.UserExtensionsEnabled));
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
_onExtensionStateChanged(proxy, senderName, [uuid, newState]) {
|
2019-11-30 05:01:44 +00:00
|
|
|
let extension = ExtensionUtils.deserializeExtension(newState);
|
2018-11-01 12:55:17 +00:00
|
|
|
let row = this._findExtensionRow(uuid);
|
2019-11-30 05:01:44 +00:00
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
this._queueUpdatesCheck();
|
|
|
|
|
2019-11-30 07:08:05 +00:00
|
|
|
// the extension's type changed; remove the corresponding row
|
|
|
|
// and reset the variable to null so that we create a new row
|
|
|
|
// below and add it to the appropriate list
|
|
|
|
if (row && row.type !== extension.type) {
|
2020-04-15 18:27:15 +00:00
|
|
|
row.get_parent().remove(row);
|
2019-11-30 07:08:05 +00:00
|
|
|
row = null;
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
if (row) {
|
2019-11-30 05:01:44 +00:00
|
|
|
if (extension.state === ExtensionState.UNINSTALLED)
|
2020-04-15 18:27:15 +00:00
|
|
|
row.get_parent().remove(row);
|
2020-03-12 21:55:43 +00:00
|
|
|
} else {
|
|
|
|
this._addExtensionRow(extension);
|
2018-11-01 12:55:17 +00:00
|
|
|
}
|
2020-03-12 21:55:43 +00:00
|
|
|
|
|
|
|
this._syncListVisibility();
|
2018-11-01 12:55:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_scanExtensions() {
|
2018-11-01 12:55:17 +00:00
|
|
|
this._shellProxy.ListExtensionsRemote(([extensionsMap], e) => {
|
|
|
|
if (e) {
|
|
|
|
if (e instanceof Gio.DBusError) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`Failed to connect to shell proxy: ${e}`);
|
2018-11-01 12:55:17 +00:00
|
|
|
this._mainStack.visible_child_name = 'noshell';
|
2019-08-20 00:51:42 +00:00
|
|
|
} else {
|
2018-11-01 12:55:17 +00:00
|
|
|
throw e;
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2018-11-01 12:55:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let uuid in extensionsMap) {
|
|
|
|
let extension = ExtensionUtils.deserializeExtension(extensionsMap[uuid]);
|
|
|
|
this._addExtensionRow(extension);
|
|
|
|
}
|
|
|
|
this._extensionsLoaded();
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
_addExtensionRow(extension) {
|
2018-11-01 12:50:30 +00:00
|
|
|
let row = new ExtensionRow(extension);
|
2019-11-30 07:08:05 +00:00
|
|
|
|
|
|
|
if (row.type === ExtensionType.PER_USER)
|
2020-04-15 18:27:15 +00:00
|
|
|
this._userList.append(row);
|
2019-11-30 07:08:05 +00:00
|
|
|
else
|
2020-04-15 18:27:15 +00:00
|
|
|
this._systemList.append(row);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-04 21:14:18 +00:00
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
_queueUpdatesCheck() {
|
|
|
|
if (this._updatesCheckId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._updatesCheckId = GLib.timeout_add_seconds(
|
|
|
|
GLib.PRIORITY_DEFAULT, 1, () => {
|
|
|
|
this._checkUpdates();
|
|
|
|
|
|
|
|
this._updatesCheckId = 0;
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-12 21:55:43 +00:00
|
|
|
_syncListVisibility() {
|
2021-10-18 13:18:11 +00:00
|
|
|
this._userGroup.visible = [...this._userList].length > 1;
|
|
|
|
this._systemGroup.visible = [...this._systemList].length > 1;
|
2020-03-12 21:55:43 +00:00
|
|
|
|
2021-10-18 13:18:11 +00:00
|
|
|
if (this._userGroup.visible || this._systemGroup.visible)
|
2020-03-12 21:55:43 +00:00
|
|
|
this._mainStack.visible_child_name = 'main';
|
|
|
|
else
|
|
|
|
this._mainStack.visible_child_name = 'placeholder';
|
|
|
|
}
|
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
_checkUpdates() {
|
2020-04-15 18:27:15 +00:00
|
|
|
let nUpdates = [...this._userList].filter(c => c.hasUpdate).length;
|
2019-11-30 14:20:04 +00:00
|
|
|
|
|
|
|
this._updatesLabel.label = Gettext.ngettext(
|
|
|
|
'%d extension will be updated on next login.',
|
2020-02-04 17:51:57 +00:00
|
|
|
'%d extensions will be updated on next login.',
|
2019-11-30 14:20:04 +00:00
|
|
|
nUpdates).format(nUpdates);
|
2020-04-15 18:27:15 +00:00
|
|
|
this._updatesBar.revealed = nUpdates > 0;
|
2019-11-30 14:20:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_extensionsLoaded() {
|
2020-03-12 21:55:43 +00:00
|
|
|
this._syncListVisibility();
|
2019-11-30 14:20:04 +00:00
|
|
|
this._checkUpdates();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2019-05-28 21:22:37 +00:00
|
|
|
});
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2019-11-30 03:12:54 +00:00
|
|
|
var ExtensionRow = GObject.registerClass({
|
|
|
|
GTypeName: 'ExtensionRow',
|
2020-03-05 16:44:27 +00:00
|
|
|
Template: 'resource:///org/gnome/Extensions/ui/extension-row.ui',
|
2019-11-30 03:12:54 +00:00
|
|
|
InternalChildren: [
|
|
|
|
'nameLabel',
|
|
|
|
'descriptionLabel',
|
2019-11-30 17:11:03 +00:00
|
|
|
'versionLabel',
|
2020-05-11 13:31:29 +00:00
|
|
|
'errorLabel',
|
|
|
|
'errorIcon',
|
2019-11-30 14:20:04 +00:00
|
|
|
'updatesIcon',
|
2020-05-18 12:24:16 +00:00
|
|
|
'switch',
|
2022-01-18 12:00:03 +00:00
|
|
|
'actionsBox',
|
2019-11-30 03:12:54 +00:00
|
|
|
],
|
|
|
|
}, class ExtensionRow extends Gtk.ListBoxRow {
|
2018-11-01 12:50:30 +00:00
|
|
|
_init(extension) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2014-05-23 02:49:37 +00:00
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
this._app = Gio.Application.get_default();
|
2018-11-01 12:50:30 +00:00
|
|
|
this._extension = extension;
|
|
|
|
this._prefsModule = null;
|
2014-05-23 02:49:37 +00:00
|
|
|
|
2020-11-11 01:37:20 +00:00
|
|
|
[this._keywords] = GLib.str_tokenize_and_fold(this.name, null);
|
|
|
|
|
2019-11-30 03:24:39 +00:00
|
|
|
this._actionGroup = new Gio.SimpleActionGroup();
|
|
|
|
this.insert_action_group('row', this._actionGroup);
|
2019-11-30 03:12:54 +00:00
|
|
|
|
2019-11-30 03:24:39 +00:00
|
|
|
let action;
|
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'show-prefs',
|
|
|
|
enabled: this.hasPrefs,
|
|
|
|
});
|
2020-04-15 18:27:15 +00:00
|
|
|
action.connect('activate', () => this.get_root().openPrefs(this.uuid));
|
2019-11-30 03:24:39 +00:00
|
|
|
this._actionGroup.add_action(action);
|
2019-11-30 03:12:54 +00:00
|
|
|
|
2019-11-30 17:11:03 +00:00
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'show-url',
|
|
|
|
enabled: this.url !== '',
|
|
|
|
});
|
|
|
|
action.connect('activate', () => {
|
|
|
|
Gio.AppInfo.launch_default_for_uri(
|
|
|
|
this.url, this.get_display().get_app_launch_context());
|
|
|
|
});
|
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
2019-11-30 05:06:08 +00:00
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'uninstall',
|
|
|
|
enabled: this.type === ExtensionType.PER_USER,
|
|
|
|
});
|
2020-04-15 18:27:15 +00:00
|
|
|
action.connect('activate', () => this.get_root().uninstall(this.uuid));
|
2019-11-30 05:06:08 +00:00
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
2019-11-30 03:24:39 +00:00
|
|
|
action = new Gio.SimpleAction({
|
|
|
|
name: 'enabled',
|
|
|
|
state: new GLib.Variant('b', false),
|
|
|
|
});
|
2020-03-05 17:46:18 +00:00
|
|
|
action.connect('activate', toggleState);
|
2019-11-30 03:24:39 +00:00
|
|
|
action.connect('change-state', (a, state) => {
|
|
|
|
if (state.get_boolean())
|
2019-11-30 03:12:54 +00:00
|
|
|
this._app.shellProxy.EnableExtensionRemote(this.uuid);
|
|
|
|
else
|
|
|
|
this._app.shellProxy.DisableExtensionRemote(this.uuid);
|
|
|
|
});
|
2019-11-30 03:24:39 +00:00
|
|
|
this._actionGroup.add_action(action);
|
|
|
|
|
2020-03-03 23:26:04 +00:00
|
|
|
this._nameLabel.label = this.name;
|
2019-11-30 03:24:39 +00:00
|
|
|
|
2021-02-10 01:18:19 +00:00
|
|
|
const desc = this._extension.metadata.description.split('\n')[0];
|
2019-11-30 03:24:39 +00:00
|
|
|
this._descriptionLabel.label = desc;
|
2021-02-10 01:18:19 +00:00
|
|
|
this._descriptionLabel.tooltip_text = desc;
|
2019-09-09 15:06:55 +00:00
|
|
|
|
2019-11-30 03:12:54 +00:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2019-09-09 15:06:55 +00:00
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
this._extensionStateChangedId = this._app.shellProxy.connectSignal(
|
|
|
|
'ExtensionStateChanged', (p, sender, [uuid, newState]) => {
|
|
|
|
if (this.uuid !== uuid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._extension = ExtensionUtils.deserializeExtension(newState);
|
2019-11-30 03:12:54 +00:00
|
|
|
this._updateState();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2019-11-30 03:12:54 +00:00
|
|
|
this._updateState();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2014-05-23 02:49:37 +00:00
|
|
|
|
2022-01-18 12:04:55 +00:00
|
|
|
vfunc_activate() {
|
|
|
|
this._switch.mnemonic_activate(false);
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:50:30 +00:00
|
|
|
get uuid() {
|
|
|
|
return this._extension.uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return this._extension.metadata.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasPrefs() {
|
|
|
|
return this._extension.hasPrefs;
|
|
|
|
}
|
2014-05-23 02:49:37 +00:00
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
get hasUpdate() {
|
|
|
|
return this._extension.hasUpdate || false;
|
|
|
|
}
|
|
|
|
|
2020-05-11 13:31:29 +00:00
|
|
|
get hasError() {
|
|
|
|
const { state } = this._extension;
|
|
|
|
return state === ExtensionState.OUT_OF_DATE ||
|
|
|
|
state === ExtensionState.ERROR;
|
|
|
|
}
|
|
|
|
|
2019-11-30 05:06:08 +00:00
|
|
|
get type() {
|
|
|
|
return this._extension.type;
|
|
|
|
}
|
|
|
|
|
2019-11-30 17:11:03 +00:00
|
|
|
get creator() {
|
|
|
|
return this._extension.metadata.creator || '';
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:50:30 +00:00
|
|
|
get url() {
|
2019-11-30 17:11:03 +00:00
|
|
|
return this._extension.metadata.url || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
get version() {
|
|
|
|
return this._extension.metadata.version || '';
|
2018-11-01 12:50:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 13:31:29 +00:00
|
|
|
get error() {
|
|
|
|
if (!this.hasError)
|
|
|
|
return '';
|
|
|
|
|
|
|
|
if (this._extension.state === ExtensionState.OUT_OF_DATE)
|
|
|
|
return _('The extension is incompatible with the current GNOME version');
|
|
|
|
|
|
|
|
return this._extension.error
|
|
|
|
? this._extension.error : _('The extension had an error');
|
|
|
|
}
|
|
|
|
|
2020-11-11 01:37:20 +00:00
|
|
|
get keywords() {
|
|
|
|
return this._keywords;
|
|
|
|
}
|
|
|
|
|
2019-11-30 03:12:54 +00:00
|
|
|
_updateState() {
|
|
|
|
let state = this._extension.state === ExtensionState.ENABLED;
|
|
|
|
|
2019-11-30 03:24:39 +00:00
|
|
|
let action = this._actionGroup.lookup('enabled');
|
|
|
|
action.set_state(new GLib.Variant('b', state));
|
|
|
|
action.enabled = this._canToggle();
|
2019-11-30 17:11:03 +00:00
|
|
|
|
2020-05-18 12:24:16 +00:00
|
|
|
if (!action.enabled)
|
|
|
|
this._switch.active = state;
|
|
|
|
|
2019-11-30 14:20:04 +00:00
|
|
|
this._updatesIcon.visible = this.hasUpdate;
|
2020-05-11 13:31:29 +00:00
|
|
|
this._errorIcon.visible = this.hasError;
|
|
|
|
|
2022-01-18 12:00:03 +00:00
|
|
|
this._descriptionLabel.visible = !this.hasError;
|
|
|
|
|
2020-05-11 13:31:29 +00:00
|
|
|
this._errorLabel.label = this.error;
|
|
|
|
this._errorLabel.visible = this.error !== '';
|
2019-11-30 14:20:04 +00:00
|
|
|
|
2020-02-19 18:25:35 +00:00
|
|
|
this._versionLabel.label = this.version.toString();
|
2019-11-30 17:11:03 +00:00
|
|
|
this._versionLabel.visible = this.version !== '';
|
2019-11-30 03:12:54 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 12:55:17 +00:00
|
|
|
_onDestroy() {
|
|
|
|
if (!this._app.shellProxy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._extensionStateChangedId)
|
|
|
|
this._app.shellProxy.disconnectSignal(this._extensionStateChangedId);
|
|
|
|
this._extensionStateChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_canToggle() {
|
|
|
|
return this._extension.canChange;
|
2014-05-23 02:49:37 +00:00
|
|
|
}
|
2020-03-06 00:03:45 +00:00
|
|
|
});
|
|
|
|
|
2012-01-19 02:21:56 +00:00
|
|
|
function initEnvironment() {
|
|
|
|
// Monkey-patch in a "global" object that fakes some Shell utilities
|
|
|
|
// that ExtensionUtils depends on.
|
2020-04-23 23:06:36 +00:00
|
|
|
globalThis.global = {
|
2019-02-12 11:24:30 +00:00
|
|
|
log(...args) {
|
|
|
|
print(args.join(', '));
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
logError(s) {
|
2022-02-07 14:14:06 +00:00
|
|
|
log(`ERROR: ${s}`);
|
2012-01-19 02:21:56 +00:00
|
|
|
},
|
|
|
|
|
2019-08-20 21:43:54 +00:00
|
|
|
userdatadir: GLib.build_filenamev([GLib.get_user_data_dir(), 'gnome-shell']),
|
2012-01-19 02:21:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(argv) {
|
|
|
|
initEnvironment();
|
2020-03-19 19:38:16 +00:00
|
|
|
Package.initGettext();
|
2012-01-19 02:21:56 +00:00
|
|
|
|
2019-05-28 21:22:37 +00:00
|
|
|
new Application().run(argv);
|
2012-01-19 02:21:56 +00:00
|
|
|
}
|