extensionUtils: Include arrays and objects in serialization

We currently only handle simple types when (de)serializing,
which means we miss keys like "shell-version" and "session-modes".

While there is no immediate use for those, handing arrays and
objects will allow to support the newly added "donate" metadata
in the Extensions app in the future.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6575

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3379>
This commit is contained in:
Florian Müllner 2024-06-20 20:46:18 +02:00 committed by Marge Bot
parent ad0e2c940b
commit 0188c453b9

View File

@ -36,6 +36,7 @@ const SERIALIZED_PROPERTIES = [
'hasPrefs',
'hasUpdate',
'canChange',
'sessionModes',
];
/**
@ -52,9 +53,7 @@ export function serializeExtension(extension) {
obj[prop] = extension[prop];
});
let res = {};
for (let key in obj) {
let val = obj[key];
function packValue(val) {
let type;
switch (typeof val) {
case 'string':
@ -66,13 +65,28 @@ export function serializeExtension(extension) {
case 'boolean':
type = 'b';
break;
default:
continue;
case 'object':
if (Array.isArray(val)) {
type = 'av';
val = val.map(v => packValue(v));
} else {
type = 'a{sv}';
let res = {};
for (let key in val) {
let packed = packValue(val[key]);
if (packed)
res[key] = packed;
}
res[key] = GLib.Variant.new(type, val);
val = res;
}
break;
default:
return null;
}
return GLib.Variant.new(type, val);
}
return res;
return packValue(obj).deepUnpack();
}
/**
@ -84,7 +98,7 @@ export function serializeExtension(extension) {
export function deserializeExtension(variant) {
let res = {metadata: {}};
for (let prop in variant) {
let val = variant[prop].unpack();
let val = variant[prop].recursiveUnpack();
if (SERIALIZED_PROPERTIES.includes(prop))
res[prop] = val;
else