From 0188c453b9e544ea84e16190991f65db7524cc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 20 Jun 2024 20:46:18 +0200 Subject: [PATCH] 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: --- js/misc/extensionUtils.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js index dc227801f..09338a182 100644 --- a/js/misc/extensionUtils.js +++ b/js/misc/extensionUtils.js @@ -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; + 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; + } + val = res; + } + break; default: - continue; + return null; } - res[key] = GLib.Variant.new(type, val); + 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