From 10fa3fa346a2d8a54b650497f421200cdc4ada17 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 22 Feb 2018 16:09:01 -0800 Subject: [PATCH] It's working! --- .../hifi/commerce/purchases/PurchasedItem.qml | 15 ++++--- .../qml/hifi/commerce/purchases/Purchases.qml | 12 +++++ interface/src/commerce/QmlCommerce.cpp | 44 ++++++++++++------- interface/src/commerce/QmlCommerce.h | 6 +-- scripts/system/commerce/wallet.js | 2 +- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml index 76e2afd308..fb8e509cde 100644 --- a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml +++ b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml @@ -47,7 +47,7 @@ Item { property bool showConfirmation: false; property bool hasPermissionToRezThis; property bool permissionExplanationCardVisible; - property bool isInstalled: false; + property bool isInstalled; property string originalStatusText; property string originalStatusColor; @@ -69,6 +69,12 @@ Item { root.isInstalled = true; } } + + onAppUninstalled: { + if (appHref === root.itemHref) { + root.isInstalled = false; + } + } } Connections { @@ -88,10 +94,6 @@ Item { } else { root.hasPermissionToRezThis = true; } - - if (itemType === "app") { - root.isInstalled = Commerce.isAppInstalled(root.itemHref); - } } onPurchaseStatusChangedChanged: { @@ -496,6 +498,8 @@ Item { colorScheme: hifi.colorSchemes.light; anchors.top: parent.top; anchors.right: parent.right; + anchors.left: parent.left; + width: 92; height: 44; text: "OPEN" onClicked: { @@ -509,6 +513,7 @@ Item { colorScheme: hifi.colorSchemes.light; anchors.bottom: parent.bottom; anchors.right: parent.right; + anchors.left: parent.left; height: 44; text: "UNINSTALL" onClicked: { diff --git a/interface/resources/qml/hifi/commerce/purchases/Purchases.qml b/interface/resources/qml/hifi/commerce/purchases/Purchases.qml index 9b333a60cd..896200a8e6 100644 --- a/interface/resources/qml/hifi/commerce/purchases/Purchases.qml +++ b/interface/resources/qml/hifi/commerce/purchases/Purchases.qml @@ -36,6 +36,7 @@ Rectangle { property bool isShowingMyItems: false; property bool isDebuggingFirstUseTutorial: false; property int pendingItemCount: 0; + property var installedApps; // Style color: hifi.colors.white; Connections { @@ -61,6 +62,8 @@ Rectangle { root.activeView = "firstUseTutorial"; } else if (!Settings.getValue("isFirstUseOfPurchases", true) && root.activeView === "initialize") { root.activeView = "purchasesMain"; + root.installedApps = Commerce.getInstalledApps(); + console.log("ZRF! " + root.installedApps); Commerce.inventory(); } } else { @@ -269,6 +272,7 @@ Rectangle { case 'tutorial_finished': Settings.setValue("isFirstUseOfPurchases", false); root.activeView = "purchasesMain"; + root.installedApps = Commerce.getInstalledApps(); Commerce.inventory(); break; } @@ -394,6 +398,7 @@ Rectangle { limitedRun: model.limited_run; displayedItemCount: model.displayedItemCount; permissionExplanationCardVisible: model.permissionExplanationCardVisible; + isInstalled: model.isInstalled; itemType: { if (model.root_file_url.indexOf(".fst") > -1) { "avatar"; @@ -680,9 +685,16 @@ Rectangle { if (sameItemCount !== tempPurchasesModel.count || filterBar.text !== filterBar.previousText) { filteredPurchasesModel.clear(); + var currentId; for (var i = 0; i < tempPurchasesModel.count; i++) { + currentId = tempPurchasesModel.get(i).id; + console.log("ZRF HERE 2 " + root.installedApps); + console.log("ZRF HERE 3 " + currentId); + console.log("ZRF HERE 4 " + ((root.installedApps).indexOf(currentId) > -1)); + filteredPurchasesModel.append(tempPurchasesModel.get(i)); filteredPurchasesModel.setProperty(i, 'permissionExplanationCardVisible', false); + filteredPurchasesModel.setProperty(i, 'isInstalled', ((root.installedApps).indexOf(currentId) > -1)); } populateDisplayedItemCounts(); diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index f9bb0d2003..f80e88d175 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -45,7 +45,7 @@ QmlCommerce::QmlCommerce() { setPassphrase(""); }); - _appsPath = PathUtils::getAppDataPath() + "Apps"; + _appsPath = PathUtils::getAppDataPath() + "Apps/"; } void QmlCommerce::getWalletStatus() { @@ -190,26 +190,38 @@ void QmlCommerce::alreadyOwned(const QString& marketplaceId) { ledger->alreadyOwned(marketplaceId); } -bool QmlCommerce::isAppInstalled(const QString& itemHref) { - QUrl appHref(itemHref); +QStringList QmlCommerce::getInstalledApps() { + QStringList installedAppsFromMarketplace; + QStringList runningScripts = DependencyManager::get()->getRunningScripts(); - // First check if .app.json exists - QFileInfo appFile(_appsPath + "/" + appHref.fileName()); - if (!(appFile.exists() && appFile.isFile())) { - return false; - } + QDir directory(_appsPath); + qCDebug(commerce) << "ZRF FIXME" << _appsPath; + QStringList apps = directory.entryList(QStringList("*.app.json")); + foreach(QString appFileName, apps) { + installedAppsFromMarketplace.append(appFileName); + qCDebug(commerce) << "ZRF FIXME" << appFileName; + QFile appFile(_appsPath + appFileName); + if (appFile.open(QIODevice::ReadOnly)) { + QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(appFile.readAll()); - // Then check to see if script is running - auto runningScripts = DependencyManager::get()->getRunningScripts(); - foreach(const QString& runningScript, runningScripts) { - QUrl runningScriptURL = QUrl(runningScript); - qCDebug(commerce) << "ZRF FIXME" << runningScriptURL; - if (runningScriptURL == appHref) { - return true; + appFile.close(); + + QJsonObject appFileJsonObject = appFileJsonDocument.object(); + QString scriptURL = appFileJsonObject["scriptURL"].toString(); + + // If the script .app.json is on the user's local disk but the associated script isn't running + // for some reason, start that script again. + if (!runningScripts.contains(scriptURL)) { + if ((DependencyManager::get()->loadScript(scriptURL.trimmed())).isNull()) { + qCDebug(commerce) << "Couldn't start script while checking installed apps."; + } + } + } else { + qCDebug(commerce) << "Couldn't open local .app.json file for reading."; } } - return false; + return installedAppsFromMarketplace; } bool QmlCommerce::installApp(const QString& itemHref) { diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index e0c018878d..2bf4959177 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -51,8 +51,8 @@ signals: void contentSetChanged(const QString& contentSetHref); - void appInstalled(const QString& appFileName); - void appUninstalled(const QString& appFileName); + void appInstalled(const QString& appHref); + void appUninstalled(const QString& appHref); protected: Q_INVOKABLE void getWalletStatus(); @@ -81,7 +81,7 @@ protected: Q_INVOKABLE void replaceContentSet(const QString& itemHref); - Q_INVOKABLE bool isAppInstalled(const QString& appHref); + Q_INVOKABLE QStringList getInstalledApps(); Q_INVOKABLE bool installApp(const QString& appHref); Q_INVOKABLE bool uninstallApp(const QString& appHref); Q_INVOKABLE bool openApp(const QString& appHref); diff --git a/scripts/system/commerce/wallet.js b/scripts/system/commerce/wallet.js index 8cf5b72b9a..9ff7038c09 100644 --- a/scripts/system/commerce/wallet.js +++ b/scripts/system/commerce/wallet.js @@ -39,7 +39,7 @@ // for toolbar-mode: go back to home screen, this will close the window. tablet.gotoHomeScreen(); } else { - tablet.loadQMLSource(WALLET_QML_SOURCE); + tablet.loadQMLSource(MARKETPLACE_PURCHASES_QML_PATH); } }