简体   繁体   中英

Unable to create a GArray in Gjs

I try to create a GArray but I have always the same error :

const GLib = imports.gi.GLib;

var garray = new GLib.Array(true, true, 1); // Unable to construct boxed type Array since it has no zero-args , can only wrap an existing one

var garray = new GLib.Array(); // Unable to construct boxed type Array since it has no zero-args , can only wrap an existing one

I need a GArray to use it in the GnomeKeyring.item_create_sync method :

GnomeKeyring.item_create_sync( "login", 4, "name", new GLib.Array(true, true, 1) "pass", true);

I tried other type of array instead of GArray, here are the errors

  • [] -> Object 0xb5d120d0 is not a subclass of (null), it's a Array
  • new Array() -> Object 0xb5e12138 is not a subclass of (null), it's a Array
  • {} -> Object 0xb5d0b1b0 is not a subclass of (null), it's a Object
  • 5 -> Unhandled GType GArray unpacking GArgument from Number
  • "5" -> Expected type interface for Argument 'attributes' but got type 'string'

If anyone has a solution for GArray or for GnomeKeyring.item_create_sync

Read /usr/share/gir-1.0/GnomeKeyring-1.0.gir and search for function name="item_create_sync" . You have all required parameters there and it seems to me that you need a plain list. GnomeObjectIntrospection will translate it to the GArray when needed.

The GNOME Shell's retrospection will convert between JS and GNOME types on its own accord where possible and required. If you create an array in the JS space and pass it to a function that requires a GArray, the Shell will convert if you pass the array as argument.

The only objects that aren't converted are those whose classes exist in one space, but not the other. Like the GNOME File Objects, as JS has no native filehandlers. You can use the .toString() method on filestreams to get their contents as a string, or call the reading methods to get the binary values as an array of integers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM