Send bundleId and objectId to javascript

Also use the json module to generate the environemnt
dictionary string. This takes care of a None objectId
cleanly.
This commit is contained in:
Daniel Narvaez 2013-06-04 21:36:01 +02:00
parent 58bab9cf6a
commit 9396b09ee4

View File

@ -15,6 +15,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import json
import os import os
from gi.repository import Gdk from gi.repository import Gdk
@ -32,6 +33,7 @@ class WebActivity(Gtk.Window):
Gtk.Window.__init__(self) Gtk.Window.__init__(self)
self._activity_id = handle.activity_id self._activity_id = handle.activity_id
self._object_id = handle.object_id
self._bundle_id = os.environ["SUGAR_BUNDLE_ID"] self._bundle_id = os.environ["SUGAR_BUNDLE_ID"]
self._bundle_path = os.environ["SUGAR_BUNDLE_PATH"] self._bundle_path = os.environ["SUGAR_BUNDLE_PATH"]
self._inspector_visible = False self._inspector_visible = False
@ -69,20 +71,24 @@ class WebActivity(Gtk.Window):
key = os.environ["SUGAR_APISOCKET_KEY"] key = os.environ["SUGAR_APISOCKET_KEY"]
port = os.environ["SUGAR_APISOCKET_PORT"] port = os.environ["SUGAR_APISOCKET_PORT"]
env_json = json.dumps({"apiSocketKey": key,
"apiSocketPort": port,
"activityId": self._activity_id,
"bundleId": self._bundle_id,
"objectId": self._object_id})
script = """ script = """
var environment = {apiSocketKey: "%s", var environment = %s;
apiSocketPort: "%s",
activityId: "%s"};
if (window.sugar === undefined) { if (window.sugar === undefined) {
window.sugar = {}; window.sugar = {};
} }
window.sugar.environment = environment; window.sugar.environment = environment;
if (window.sugar.onEnvironmentSet) if (window.sugar.onEnvironmentSet)
window.sugar.onEnvironmentSet(); window.sugar.onEnvironmentSet();
""" % (key, port, self._activity_id) """ % env_json
self._web_view.run_javascript(script, None, None, None) self._web_view.run_javascript(script, None, None, None)