Merge pull request #14760 from SimonWalton-HiFi/qmlcommerce-singleton

Treat QmlCommerce as a singleton class
This commit is contained in:
Jeff Clinton 2019-01-23 13:07:17 -08:00 committed by GitHub
commit 5fa033473e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View file

@ -919,6 +919,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<Wallet>();
DependencyManager::set<WalletScriptingInterface>();
DependencyManager::set<TTSScriptingInterface>();
DependencyManager::set<QmlCommerce>();
DependencyManager::set<FadeEffect>();
DependencyManager::set<ResourceRequestObserver>();
@ -2598,6 +2599,7 @@ void Application::cleanupBeforeQuit() {
DependencyManager::destroy<ContextOverlayInterface>(); // Must be destroyed before TabletScriptingInterface
// stop QML
DependencyManager::destroy<QmlCommerce>();
DependencyManager::destroy<TabletScriptingInterface>();
DependencyManager::destroy<ToolbarScriptingInterface>();
DependencyManager::destroy<OffscreenUi>();
@ -2886,7 +2888,7 @@ void Application::initializeUi() {
Tooltip::registerType();
UpdateDialog::registerType();
QmlContextCallback commerceCallback = [](QQmlContext* context) {
context->setContextProperty("Commerce", new QmlCommerce());
context->setContextProperty("Commerce", DependencyManager::get<QmlCommerce>().data());
};
OffscreenQmlSurface::addWhitelistContextHandler({
QUrl{ "hifi/commerce/checkout/Checkout.qml" },
@ -8014,8 +8016,7 @@ void Application::openUrl(const QUrl& url) const {
if (url.scheme() == URL_SCHEME_HIFI) {
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
} else if (url.scheme() == URL_SCHEME_HIFIAPP) {
QmlCommerce commerce;
commerce.openSystemApp(url.path());
DependencyManager::get<QmlCommerce>()->openSystemApp(url.path());
} else {
// address manager did not handle - ask QDesktopServices to handle
QDesktopServices::openUrl(url);

View file

@ -22,7 +22,9 @@
#include <ui/TabletScriptingInterface.h>
#include "scripting/HMDScriptingInterface.h"
QmlCommerce::QmlCommerce() {
QmlCommerce::QmlCommerce() :
_appsPath(PathUtils::getAppDataPath() + "Apps/")
{
auto ledger = DependencyManager::get<Ledger>();
auto wallet = DependencyManager::get<Wallet>();
connect(ledger.data(), &Ledger::buyResult, this, &QmlCommerce::buyResult);
@ -44,22 +46,18 @@ QmlCommerce::QmlCommerce() {
auto accountManager = DependencyManager::get<AccountManager>();
connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() { setPassphrase(""); });
_appsPath = PathUtils::getAppDataPath() + "Apps/";
}
void QmlCommerce::openSystemApp(const QString& appName) {
static QMap<QString, QString> systemApps {
static const QMap<QString, QString> systemApps {
{"GOTO", "hifi/tablet/TabletAddressDialog.qml"},
{"PEOPLE", "hifi/Pal.qml"},
{"WALLET", "hifi/commerce/wallet/Wallet.qml"},
{"MARKET", "/marketplace.html"}
};
static QMap<QString, QString> systemInject{
static const QMap<QString, QString> systemInject{
{"MARKET", "/scripts/system/html/js/marketplacesInject.js"}
};

View file

@ -19,7 +19,9 @@
#include <QPixmap>
class QmlCommerce : public QObject {
#include <DependencyManager.h>
class QmlCommerce : public QObject, public Dependency {
Q_OBJECT
public:
@ -98,7 +100,7 @@ protected:
Q_INVOKABLE void updateItem(const QString& certificateId);
private:
QString _appsPath;
const QString _appsPath;
};
#endif // hifi_QmlCommerce_h