Skip to content Skip to sidebar Skip to footer

Unpacking Gvariant In Javascript

I have an array stored as a GVariant of type a(ss) in GSettings, that I want to use in a Cinnamon Applet. I can retrieve the value successfully using the following code: let schem

Solution 1:

A bit late, but my_value.unpack() works absolutely fine.

my_value.deep_unpack() will recursively unpack the arrays and their elements.

Solution 2:

From your type of setting I guess you want to store/retrieve an array of strings? In this case, there is an easier method using Gio.Settings.get_strv(String key):

// Read the array (will create a real JS array):let string_array = settings.get_strv("myvalue");
// Now do something with it...// Store it:
settings.set_strv("myvalue", string_array);
Gio.Settings.sync(); // Important!

In your schema, you would then include an entry like this:

<keyname="myvalue"type="as"><default>[]</default><summary>Some array.</summary><description>An Array of strings.</description></key>

I use the same technique in my extension: Read/Write | Schema

Post a Comment for "Unpacking Gvariant In Javascript"