[gnome-shell/gnome-3-36] extensionUtils: Add openPrefs() convenience method
- From: Robert Mader <rmader src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gnome-3-36] extensionUtils: Add openPrefs() convenience method
- Date: Fri, 3 Apr 2020 15:01:32 +0000 (UTC)
commit 856adfd1f1f271da27a270603b9d72e99a91600b
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Apr 1 21:08:38 2020 +0200
extensionUtils: Add openPrefs() convenience method
Opening their own preferences is a reasonable desire for extensions,
so make up for breaking it by adding a convenience method for that
action.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1163
(cherry picked from commit 8030d9ad323e5c3e45a158a3d09faa75b3c880d8)
js/misc/extensionUtils.js | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js
index af2338f450..e9697d4684 100644
--- a/js/misc/extensionUtils.js
+++ b/js/misc/extensionUtils.js
@@ -1,7 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported ExtensionState, ExtensionType, getCurrentExtension,
- getSettings, initTranslations, isOutOfDate, installImporter,
- serializeExtension, deserializeExtension */
+ getSettings, initTranslations, openPrefs, isOutOfDate,
+ installImporter, serializeExtension, deserializeExtension */
// Common utils for the extension system and the extension
// preferences tool
@@ -153,6 +153,27 @@ function getSettings(schema) {
return new Gio.Settings({ settings_schema: schemaObj });
}
+/**
+ * openPrefs:
+ *
+ * Open the preference dialog of the current extension
+ */
+function openPrefs() {
+ const extension = getCurrentExtension();
+
+ if (!extension)
+ throw new Error('openPrefs() can only be called from extensions');
+
+ try {
+ const extensionManager = imports.ui.main.extensionManager;
+ extensionManager.openExtensionPrefs(extension.uuid, '', {});
+ } catch (e) {
+ if (e.name === 'ImportError')
+ throw new Error('openPrefs() cannot be called from preferences');
+ logError(e, 'Failed to open extension preferences');
+ }
+}
+
/**
* versionCheck:
* @param {string[]} required - an array of versions we're compatible with
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]