Re: retrieving contact list: works in looking-glass, not in extension



Il 23 aprile 2012 06:33, Amy C <mathematical coffee gmail com> ha scritto:
> Hi gnome-mailing-list,
>
> I've recently delved into the world of writing gnome shell extensions.
> Pretty fun, but quite frustrating.
>
> As an introductory exercise I wanted to retrieve a list of all the
> contacts I have (from gnome-contacts, I guess).
>
> In any case, with looking-glass I was able to experiment and discover
> the following two snippets of code that both return a list of contact
> IDs. These are similar to what the overview uses when you search to
> display matching contacts. I searched on '' to get the entire contact
> list:
>
> // METHOD 1:
> const ContactDisplay = imports.ui.contactDisplay;
> let csp = new ContactDisplay.ContactSearchProvider();
> let contacts = csp.getInitialResultSet(['']);
> contacts.length // 120 contacts
>
> // METHOD 2:
> const ContactSystem = Shell.ContactSystem;
> let cs = ContactSystem.get_default();
> let contacts2 = cs.initial_search(['']);
> contacts2.length // 120 contacts
>
> However, when I put this exact same code into a gnome shell extension
> (say the enable() method of extension.js) and `global.log(
> contacts.length )`, I *always* get 0, that is, it didn't find any
> contacts.
>
> Can anyone tell me why this is and how I can work around it? Do the
> extensions operate in some sort of quarantined little sandbox that the
> looking glass doesn't?

There is no kind of sandboxing for extensions, whatever you're doing
from lg should be available from extensions. Note though that enable()
is called very early, and contact lists are loaded asynchronously by
libfolks. It may be possible contacts are not yet available by the
time your extension is loaded.
Currently ShellContactSystem does not notify of completed loading
(even though libfolks does). You can file a bug and ask for a signal
if you need it. You could also try bypassing ShellContactSystem, but I
don't recommend it.

Giovanni


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]