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
This commit is contained in:

committed by
Florian Müllner

parent
4589da957b
commit
58806359ee
@ -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;
|
||||
@ -264,41 +263,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) {
|
||||
|
Reference in New Issue
Block a user