Make sure that there is only one connection created for web events, so downloads from CLARA IO not duplicated

This commit is contained in:
Vladyslav Stelmakhovskyi 2017-05-28 19:54:41 +02:00
parent bc44a03e13
commit bcee25acc7
5 changed files with 45 additions and 18 deletions

View file

@ -170,20 +170,24 @@ Item {
objectName: "loader"
asynchronous: false
width: parent.width
height: parent.height
// Hook up callback for clara.io download from the marketplace.
Connections {
id: eventBridgeConnection
target: null
onWebEventReceived: {
if (message.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(message.slice(18));
}
}
}
onLoaded: {
if (loader.item.hasOwnProperty("eventBridge")) {
loader.item.eventBridge = eventBridge;
// Hook up callback for clara.io download from the marketplace.
eventBridge.webEventReceived.connect(function (event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
}
});
eventBridgeConnection.target = eventBridge
}
if (loader.item.hasOwnProperty("sendToScript")) {
loader.item.sendToScript.connect(tabletRoot.sendToScript);

View file

@ -90,16 +90,21 @@ Windows.ScrollingWindow {
anchors.left: parent.left
anchors.top: parent.top
// Hook up callback for clara.io download from the marketplace.
Connections {
id: eventBridgeConnection
target: null
onWebEventReceived: {
if (message.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(message.slice(18));
}
}
}
onLoaded: {
if (loader.item.hasOwnProperty("eventBridge")) {
loader.item.eventBridge = eventBridge;
// Hook up callback for clara.io download from the marketplace.
eventBridge.webEventReceived.connect(function (event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
}
});
eventBridgeConnection.target = eventBridge
}
if (loader.item.hasOwnProperty("sendToScript")) {
loader.item.sendToScript.connect(tabletRoot.sendToScript);

View file

@ -2100,7 +2100,13 @@ function selectParticleEntity(entityID) {
}
entityListTool.webView.webEventReceived.connect(function (data) {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
print("edit.js: Error parsing JSON: " + e.name + " data " + data)
return;
}
if (data.type === 'parent') {
parentSelectedEntities();
} else if(data.type === 'unparent') {

View file

@ -109,7 +109,13 @@ EntityListTool = function(opts) {
};
webView.webEventReceived.connect(function(data) {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
print("entityList.js: Error parsing JSON: " + e.name + " data " + data)
return;
}
if (data.type == "selectionUpdate") {
var ids = data.entityIds;
var entityIDs = [];

View file

@ -238,7 +238,13 @@ GridTool = function(opts) {
});
webView.webEventReceived.connect(function(data) {
data = JSON.parse(data);
try {
data = JSON.parse(data);
} catch(e) {
print("gridTool.js: Error parsing JSON: " + e.name + " data " + data)
return;
}
if (data.type == "init") {
horizontalGrid.emitUpdate();
} else if (data.type == "update") {