[gnome-shell/wip/rstrode/login-screen-extensions: 39/134] extensionUtils: Add functions to (de)serialize extensions
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/rstrode/login-screen-extensions: 39/134] extensionUtils: Add functions to (de)serialize extensions
- Date: Thu, 26 Aug 2021 19:30:58 +0000 (UTC)
commit 3b1a2f0e9414f5d26c430e3a2abc2e17f576fba4
Author: Didier Roche <didrocks ubuntu com>
Date: Thu Nov 1 13:55:17 2018 +0100
extensionUtils: Add functions to (de)serialize extensions
Serializing an extension for sending over D-Bus is currently done by the
appropriate D-Bus method implementations. Split out the code as utility
function and add a corresponding deserialization function, which we will
soon use when consuming the D-Bus extension API from the extension-prefs
tool.
https://bugzilla.gnome.org/show_bug.cgi?id=789852
js/misc/extensionUtils.js | 53 +++++++++++++++++++++++++++++++++++++++++++++--
js/ui/shellDBus.js | 38 ++-------------------------------
2 files changed, 53 insertions(+), 38 deletions(-)
---
diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js
index dc6e74cf80..bc9c36f4e9 100644
--- a/js/misc/extensionUtils.js
+++ b/js/misc/extensionUtils.js
@@ -3,11 +3,12 @@
// Common utils for the extension system and the extension
// preferences tool
+const { Gio, GLib } = imports.gi;
+
const Gettext = imports.gettext;
+const Lang = imports.lang;
const Signals = imports.signals;
-const Gio = imports.gi.Gio;
-
const Config = imports.misc.config;
const FileUtils = imports.misc.fileUtils;
@@ -30,6 +31,8 @@ var ExtensionState = {
UNINSTALLED: 99
};
+const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs'];
+
// Maps uuid -> metadata object
var extensions = {};
@@ -225,6 +228,52 @@ function createExtensionObject(uuid, dir, type) {
return extension;
}
+function serializeExtension(extension) {
+ let obj = {};
+ Lang.copyProperties(extension.metadata, obj);
+
+ SERIALIZED_PROPERTIES.forEach(prop => {
+ obj[prop] = extension[prop];
+ });
+
+ let res = {};
+ for (let key in obj) {
+ let val = obj[key];
+ let type;
+ switch (typeof val) {
+ case 'string':
+ type = 's';
+ break;
+ case 'number':
+ type = 'd';
+ break;
+ case 'boolean':
+ type = 'b';
+ break;
+ default:
+ continue;
+ }
+ res[key] = GLib.Variant.new(type, val);
+ }
+
+ return res;
+}
+
+function deserializeExtension(variant) {
+ let res = { metadata: {} };
+ for (let prop in variant) {
+ let val = variant[prop].unpack();
+ if (SERIALIZED_PROPERTIES.includes(prop))
+ res[prop] = val;
+ else
+ res.metadata[prop] = val;
+ }
+ // add the 2 additional properties to create a valid extension object, as createExtensionObject()
+ res.uuid = res.metadata.uuid;
+ res.dir = Gio.File.new_for_path(res.path);
+ return res;
+}
+
function installImporter(extension) {
let oldSearchPath = imports.searchPath.slice(); // make a copy
imports.searchPath = [extension.dir.get_parent().get_path()];
diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js
index 0ded84874b..af5889789d 100644
--- a/js/ui/shellDBus.js
+++ b/js/ui/shellDBus.js
@@ -1,7 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const { Gio, GLib, Meta, Shell } = imports.gi;
-const Lang = imports.lang;
const Config = imports.misc.config;
const ExtensionDownloader = imports.ui.extensionDownloader;
@@ -263,41 +262,8 @@ var GnomeShellExtensions = class {
}
GetExtensionInfo(uuid) {
- let extension = ExtensionUtils.extensions[uuid];
- if (!extension)
- return {};
-
- let obj = {};
- Lang.copyProperties(extension.metadata, obj);
-
- // Only serialize the properties that we actually need.
- const serializedProperties = ["type", "state", "path", "error", "hasPrefs"];
-
- serializedProperties.forEach(prop => {
- obj[prop] = extension[prop];
- });
-
- let out = {};
- for (let key in obj) {
- let val = obj[key];
- let type;
- switch (typeof val) {
- case 'string':
- type = 's';
- break;
- case 'number':
- type = 'd';
- break;
- case 'boolean':
- type = 'b';
- break;
- default:
- continue;
- }
- out[key] = GLib.Variant.new(type, val);
- }
-
- return out;
+ let extension = ExtensionUtils.extensions[uuid] || {};
+ return ExtensionUtils.serializeExtension(extension);
}
GetExtensionErrors(uuid) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]