It's working!

This commit is contained in:
Zach Fox 2018-02-22 16:09:01 -08:00
parent de0eee52d6
commit 10fa3fa346
5 changed files with 54 additions and 25 deletions

View file

@ -47,7 +47,7 @@ Item {
property bool showConfirmation: false; property bool showConfirmation: false;
property bool hasPermissionToRezThis; property bool hasPermissionToRezThis;
property bool permissionExplanationCardVisible; property bool permissionExplanationCardVisible;
property bool isInstalled: false; property bool isInstalled;
property string originalStatusText; property string originalStatusText;
property string originalStatusColor; property string originalStatusColor;
@ -69,6 +69,12 @@ Item {
root.isInstalled = true; root.isInstalled = true;
} }
} }
onAppUninstalled: {
if (appHref === root.itemHref) {
root.isInstalled = false;
}
}
} }
Connections { Connections {
@ -88,10 +94,6 @@ Item {
} else { } else {
root.hasPermissionToRezThis = true; root.hasPermissionToRezThis = true;
} }
if (itemType === "app") {
root.isInstalled = Commerce.isAppInstalled(root.itemHref);
}
} }
onPurchaseStatusChangedChanged: { onPurchaseStatusChangedChanged: {
@ -496,6 +498,8 @@ Item {
colorScheme: hifi.colorSchemes.light; colorScheme: hifi.colorSchemes.light;
anchors.top: parent.top; anchors.top: parent.top;
anchors.right: parent.right; anchors.right: parent.right;
anchors.left: parent.left;
width: 92;
height: 44; height: 44;
text: "OPEN" text: "OPEN"
onClicked: { onClicked: {
@ -509,6 +513,7 @@ Item {
colorScheme: hifi.colorSchemes.light; colorScheme: hifi.colorSchemes.light;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
anchors.right: parent.right; anchors.right: parent.right;
anchors.left: parent.left;
height: 44; height: 44;
text: "UNINSTALL" text: "UNINSTALL"
onClicked: { onClicked: {

View file

@ -36,6 +36,7 @@ Rectangle {
property bool isShowingMyItems: false; property bool isShowingMyItems: false;
property bool isDebuggingFirstUseTutorial: false; property bool isDebuggingFirstUseTutorial: false;
property int pendingItemCount: 0; property int pendingItemCount: 0;
property var installedApps;
// Style // Style
color: hifi.colors.white; color: hifi.colors.white;
Connections { Connections {
@ -61,6 +62,8 @@ Rectangle {
root.activeView = "firstUseTutorial"; root.activeView = "firstUseTutorial";
} else if (!Settings.getValue("isFirstUseOfPurchases", true) && root.activeView === "initialize") { } else if (!Settings.getValue("isFirstUseOfPurchases", true) && root.activeView === "initialize") {
root.activeView = "purchasesMain"; root.activeView = "purchasesMain";
root.installedApps = Commerce.getInstalledApps();
console.log("ZRF! " + root.installedApps);
Commerce.inventory(); Commerce.inventory();
} }
} else { } else {
@ -269,6 +272,7 @@ Rectangle {
case 'tutorial_finished': case 'tutorial_finished':
Settings.setValue("isFirstUseOfPurchases", false); Settings.setValue("isFirstUseOfPurchases", false);
root.activeView = "purchasesMain"; root.activeView = "purchasesMain";
root.installedApps = Commerce.getInstalledApps();
Commerce.inventory(); Commerce.inventory();
break; break;
} }
@ -394,6 +398,7 @@ Rectangle {
limitedRun: model.limited_run; limitedRun: model.limited_run;
displayedItemCount: model.displayedItemCount; displayedItemCount: model.displayedItemCount;
permissionExplanationCardVisible: model.permissionExplanationCardVisible; permissionExplanationCardVisible: model.permissionExplanationCardVisible;
isInstalled: model.isInstalled;
itemType: { itemType: {
if (model.root_file_url.indexOf(".fst") > -1) { if (model.root_file_url.indexOf(".fst") > -1) {
"avatar"; "avatar";
@ -680,9 +685,16 @@ Rectangle {
if (sameItemCount !== tempPurchasesModel.count || filterBar.text !== filterBar.previousText) { if (sameItemCount !== tempPurchasesModel.count || filterBar.text !== filterBar.previousText) {
filteredPurchasesModel.clear(); filteredPurchasesModel.clear();
var currentId;
for (var i = 0; i < tempPurchasesModel.count; i++) { 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.append(tempPurchasesModel.get(i));
filteredPurchasesModel.setProperty(i, 'permissionExplanationCardVisible', false); filteredPurchasesModel.setProperty(i, 'permissionExplanationCardVisible', false);
filteredPurchasesModel.setProperty(i, 'isInstalled', ((root.installedApps).indexOf(currentId) > -1));
} }
populateDisplayedItemCounts(); populateDisplayedItemCounts();

View file

@ -45,7 +45,7 @@ QmlCommerce::QmlCommerce() {
setPassphrase(""); setPassphrase("");
}); });
_appsPath = PathUtils::getAppDataPath() + "Apps"; _appsPath = PathUtils::getAppDataPath() + "Apps/";
} }
void QmlCommerce::getWalletStatus() { void QmlCommerce::getWalletStatus() {
@ -190,26 +190,38 @@ void QmlCommerce::alreadyOwned(const QString& marketplaceId) {
ledger->alreadyOwned(marketplaceId); ledger->alreadyOwned(marketplaceId);
} }
bool QmlCommerce::isAppInstalled(const QString& itemHref) { QStringList QmlCommerce::getInstalledApps() {
QUrl appHref(itemHref); QStringList installedAppsFromMarketplace;
QStringList runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();
// First check if .app.json exists QDir directory(_appsPath);
QFileInfo appFile(_appsPath + "/" + appHref.fileName()); qCDebug(commerce) << "ZRF FIXME" << _appsPath;
if (!(appFile.exists() && appFile.isFile())) { QStringList apps = directory.entryList(QStringList("*.app.json"));
return false; 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 appFile.close();
auto runningScripts = DependencyManager::get<ScriptEngines>()->getRunningScripts();
foreach(const QString& runningScript, runningScripts) { QJsonObject appFileJsonObject = appFileJsonDocument.object();
QUrl runningScriptURL = QUrl(runningScript); QString scriptURL = appFileJsonObject["scriptURL"].toString();
qCDebug(commerce) << "ZRF FIXME" << runningScriptURL;
if (runningScriptURL == appHref) { // If the script .app.json is on the user's local disk but the associated script isn't running
return true; // for some reason, start that script again.
if (!runningScripts.contains(scriptURL)) {
if ((DependencyManager::get<ScriptEngines>()->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) { bool QmlCommerce::installApp(const QString& itemHref) {

View file

@ -51,8 +51,8 @@ signals:
void contentSetChanged(const QString& contentSetHref); void contentSetChanged(const QString& contentSetHref);
void appInstalled(const QString& appFileName); void appInstalled(const QString& appHref);
void appUninstalled(const QString& appFileName); void appUninstalled(const QString& appHref);
protected: protected:
Q_INVOKABLE void getWalletStatus(); Q_INVOKABLE void getWalletStatus();
@ -81,7 +81,7 @@ protected:
Q_INVOKABLE void replaceContentSet(const QString& itemHref); 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 installApp(const QString& appHref);
Q_INVOKABLE bool uninstallApp(const QString& appHref); Q_INVOKABLE bool uninstallApp(const QString& appHref);
Q_INVOKABLE bool openApp(const QString& appHref); Q_INVOKABLE bool openApp(const QString& appHref);

View file

@ -39,7 +39,7 @@
// for toolbar-mode: go back to home screen, this will close the window. // for toolbar-mode: go back to home screen, this will close the window.
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
} else { } else {
tablet.loadQMLSource(WALLET_QML_SOURCE); tablet.loadQMLSource(MARKETPLACE_PURCHASES_QML_PATH);
} }
} }