Take certID from backend instead of query params; Better loading; Uninstall app before updating

This commit is contained in:
Zach Fox 2018-03-07 11:10:47 -08:00
parent 91e0af9b46
commit d07d02b2bc
4 changed files with 23 additions and 13 deletions

View file

@ -52,6 +52,7 @@ Rectangle {
property string referrer;
property bool isInstalled;
property bool isUpdating;
property string baseAppURL;
// Style
color: hifi.colors.white;
Connections {
@ -106,9 +107,9 @@ Rectangle {
if (result.status !== 'success') {
console.log("Failed to get balance", result.data.message);
} else {
root.balanceReceived = true;
root.balanceAfterPurchase = result.data.balance - root.itemPrice;
root.refreshBuyUI();
root.balanceReceived = true;
}
}
@ -116,7 +117,6 @@ Rectangle {
if (result.status !== 'success') {
console.log("Failed to get Already Owned status", result.data.message);
} else {
root.ownershipStatusReceived = true;
if (result.data.marketplace_item_id === root.itemId) {
root.alreadyOwned = result.data.already_owned;
} else {
@ -124,6 +124,7 @@ Rectangle {
root.alreadyOwned = false;
}
root.refreshBuyUI();
root.ownershipStatusReceived = true;
}
}
@ -137,13 +138,20 @@ Rectangle {
if (result.status !== 'success') {
console.log("Failed to get Available Updates", result.data.message);
} else {
root.availableUpdatesReceived = true;
for (var i = 0; i < result.data.updates.length; i++) {
if (result.data.updates[i].item_id === root.itemId) {
// If the ItemID of the item we're looking at matches EITHER the ID of a "base" item
// OR the ID of an "upgrade" item, we're updating.
if (root.itemId === result.data.updates[i].item_id ||
root.itemId === result.data.updates[i].updated_item_id) {
root.isUpdating = true;
root.certificateId = result.data.updates[i].certificate_id;
if (root.itemType === "app") {
root.baseAppURL = result.data.updates[i].base_download_url;
}
break;
}
}
root.availableUpdatesReceived = true;
}
}
@ -587,6 +595,11 @@ Rectangle {
(viewInMyPurchasesButton.visible ? "Buy It Again" : "Confirm Purchase") : "--") : "Get Item"));
onClicked: {
if (root.isUpdating) {
// If we're updating an app, the existing app needs to be uninstalled.
// This call will fail/return `false` if the app isn't installed, but that's OK.
if (root.itemType === "app") {
Commerce.uninstallApp(root.baseAppURL);
}
Commerce.updateItem(root.certificateId);
} else if (root.isCertified) {
if (!root.shouldBuyWithControlledFailure) {
@ -1047,7 +1060,6 @@ Rectangle {
root.itemHref = message.params.itemHref;
root.referrer = message.params.referrer;
root.itemAuthor = message.params.itemAuthor;
root.certificateId = message.params.certificateId;
refreshBuyUI();
break;
default:

View file

@ -681,7 +681,7 @@ Item {
verticalAlignment: Text.AlignVCenter;
onLinkActivated: {
sendToPurchases({method: 'updateItemClicked', itemId: root.itemId, itemEdition: root.itemEdition, upgradeUrl: root.upgradeUrl, certificateId: root.certificateId});
sendToPurchases({method: 'updateItemClicked', itemId: root.itemId, itemEdition: root.itemEdition, upgradeUrl: root.upgradeUrl});
}
}
}

View file

@ -255,7 +255,7 @@
}));
}
function updateButtonClicked(id, name, author, href, referrer, certId) {
function updateButtonClicked(id, name, author, href, referrer) {
EventBridge.emitWebEvent(JSON.stringify({
type: "UPDATE",
isUpdating: true,
@ -264,8 +264,7 @@
itemPrice: 0,
itemHref: href,
referrer: referrer,
itemAuthor: author,
certificateId: certId
itemAuthor: author
}));
}
@ -436,13 +435,12 @@
purchaseButton.on('click', function () {
var urlParams = new URLSearchParams(window.location.search);
if (window.location.href.indexOf('certificateId=' != -1)) {
if (window.location.href.indexOf('edition=' != -1)) { // "Upgrading" case
updateButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(),
$('#creator').find('.value').text(),
href,
"itemPage",
urlParams.get('certificateId'));
"itemPage");
} else if ('available' === availability) {
buyButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(),

View file

@ -564,7 +564,7 @@ var selectionDisplay = null; // for gridTool.js to ignore
tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
break;
case 'updateItemClicked':
tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition + "&certificateId=" + message.certificateId.replace(/\+/g, "%2B"),
tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition,
MARKETPLACES_INJECT_SCRIPT_URL);
break;
case 'passphrasePopup_cancelClicked':