[Sugar-devel] sugar-web: env.js questions

Daniel Narvaez dwnarvaez at gmail.com
Fri Nov 22 17:22:28 EST 2013


On 22 November 2013 22:59, Rogelio Mita <rogeliomita at activitycentral.com>wrote:

>
> About the logic, unfortunately checking window.sugar won't work because we
> can't assume window.sugar has been already set when getEnvironment is
> called... the python code you linked might be called after getEnvironment
> has been called and will erroneously think we are in standalone mode.
>
> you are right. I thought for a moment that this fragment is executed to
> begging before activity.setup(), I'm still in doubt, are you sure about
> this?
>

The python code is executed when the page (with all it's resources) has
been loaded. And I think that can happen either after or before javascript
activity.setup(), depending on the page, hardware etc.


>
>
>>
>> That's why I suggested to check if window.location starts with
>> activity://. It's a bit ugly but it will always work.
>>
>
> Seems to be a good start, if I understand what you say, it would result
> there is no need to use callbacks in this method, ie: we can return object
> environment on sugar environment or null in other case
>

Nope. getEnvironment will still need to be async because in the
non-standalone case you need to wait for that python code to be executed.
You could have a env.isStandalone() method (no callback) but I have the
feeling that would make the code using env.getEnvironment more complicated.

Actually I think we should probably have both. Add env.isStandalone() and
when that's true make getEnvironment() pass {} to the callback. How does
that sound?

This is all super-icky and difficult to explain, if you don't understand
something I can try to clarify further.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20131122/d231e79f/attachment.html>


More information about the Sugar-devel mailing list