mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 22:35:14 +02:00
Merge pull request #14760 from SimonWalton-HiFi/qmlcommerce-singleton
Treat QmlCommerce as a singleton class
This commit is contained in:
commit
5fa033473e
3 changed files with 13 additions and 12 deletions
|
@ -919,6 +919,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||||
DependencyManager::set<Wallet>();
|
DependencyManager::set<Wallet>();
|
||||||
DependencyManager::set<WalletScriptingInterface>();
|
DependencyManager::set<WalletScriptingInterface>();
|
||||||
DependencyManager::set<TTSScriptingInterface>();
|
DependencyManager::set<TTSScriptingInterface>();
|
||||||
|
DependencyManager::set<QmlCommerce>();
|
||||||
|
|
||||||
DependencyManager::set<FadeEffect>();
|
DependencyManager::set<FadeEffect>();
|
||||||
DependencyManager::set<ResourceRequestObserver>();
|
DependencyManager::set<ResourceRequestObserver>();
|
||||||
|
@ -2598,6 +2599,7 @@ void Application::cleanupBeforeQuit() {
|
||||||
DependencyManager::destroy<ContextOverlayInterface>(); // Must be destroyed before TabletScriptingInterface
|
DependencyManager::destroy<ContextOverlayInterface>(); // Must be destroyed before TabletScriptingInterface
|
||||||
|
|
||||||
// stop QML
|
// stop QML
|
||||||
|
DependencyManager::destroy<QmlCommerce>();
|
||||||
DependencyManager::destroy<TabletScriptingInterface>();
|
DependencyManager::destroy<TabletScriptingInterface>();
|
||||||
DependencyManager::destroy<ToolbarScriptingInterface>();
|
DependencyManager::destroy<ToolbarScriptingInterface>();
|
||||||
DependencyManager::destroy<OffscreenUi>();
|
DependencyManager::destroy<OffscreenUi>();
|
||||||
|
@ -2886,7 +2888,7 @@ void Application::initializeUi() {
|
||||||
Tooltip::registerType();
|
Tooltip::registerType();
|
||||||
UpdateDialog::registerType();
|
UpdateDialog::registerType();
|
||||||
QmlContextCallback commerceCallback = [](QQmlContext* context) {
|
QmlContextCallback commerceCallback = [](QQmlContext* context) {
|
||||||
context->setContextProperty("Commerce", new QmlCommerce());
|
context->setContextProperty("Commerce", DependencyManager::get<QmlCommerce>().data());
|
||||||
};
|
};
|
||||||
OffscreenQmlSurface::addWhitelistContextHandler({
|
OffscreenQmlSurface::addWhitelistContextHandler({
|
||||||
QUrl{ "hifi/commerce/checkout/Checkout.qml" },
|
QUrl{ "hifi/commerce/checkout/Checkout.qml" },
|
||||||
|
@ -8014,8 +8016,7 @@ void Application::openUrl(const QUrl& url) const {
|
||||||
if (url.scheme() == URL_SCHEME_HIFI) {
|
if (url.scheme() == URL_SCHEME_HIFI) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||||
} else if (url.scheme() == URL_SCHEME_HIFIAPP) {
|
} else if (url.scheme() == URL_SCHEME_HIFIAPP) {
|
||||||
QmlCommerce commerce;
|
DependencyManager::get<QmlCommerce>()->openSystemApp(url.path());
|
||||||
commerce.openSystemApp(url.path());
|
|
||||||
} else {
|
} else {
|
||||||
// address manager did not handle - ask QDesktopServices to handle
|
// address manager did not handle - ask QDesktopServices to handle
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
|
|
|
@ -22,7 +22,9 @@
|
||||||
#include <ui/TabletScriptingInterface.h>
|
#include <ui/TabletScriptingInterface.h>
|
||||||
#include "scripting/HMDScriptingInterface.h"
|
#include "scripting/HMDScriptingInterface.h"
|
||||||
|
|
||||||
QmlCommerce::QmlCommerce() {
|
QmlCommerce::QmlCommerce() :
|
||||||
|
_appsPath(PathUtils::getAppDataPath() + "Apps/")
|
||||||
|
{
|
||||||
auto ledger = DependencyManager::get<Ledger>();
|
auto ledger = DependencyManager::get<Ledger>();
|
||||||
auto wallet = DependencyManager::get<Wallet>();
|
auto wallet = DependencyManager::get<Wallet>();
|
||||||
connect(ledger.data(), &Ledger::buyResult, this, &QmlCommerce::buyResult);
|
connect(ledger.data(), &Ledger::buyResult, this, &QmlCommerce::buyResult);
|
||||||
|
@ -44,22 +46,18 @@ QmlCommerce::QmlCommerce() {
|
||||||
|
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() { setPassphrase(""); });
|
connect(accountManager.data(), &AccountManager::usernameChanged, this, [&]() { setPassphrase(""); });
|
||||||
|
|
||||||
_appsPath = PathUtils::getAppDataPath() + "Apps/";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void QmlCommerce::openSystemApp(const QString& appName) {
|
void QmlCommerce::openSystemApp(const QString& appName) {
|
||||||
static QMap<QString, QString> systemApps {
|
static const QMap<QString, QString> systemApps {
|
||||||
{"GOTO", "hifi/tablet/TabletAddressDialog.qml"},
|
{"GOTO", "hifi/tablet/TabletAddressDialog.qml"},
|
||||||
{"PEOPLE", "hifi/Pal.qml"},
|
{"PEOPLE", "hifi/Pal.qml"},
|
||||||
{"WALLET", "hifi/commerce/wallet/Wallet.qml"},
|
{"WALLET", "hifi/commerce/wallet/Wallet.qml"},
|
||||||
{"MARKET", "/marketplace.html"}
|
{"MARKET", "/marketplace.html"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static QMap<QString, QString> systemInject{
|
static const QMap<QString, QString> systemInject{
|
||||||
{"MARKET", "/scripts/system/html/js/marketplacesInject.js"}
|
{"MARKET", "/scripts/system/html/js/marketplacesInject.js"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
class QmlCommerce : public QObject {
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
|
class QmlCommerce : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -98,7 +100,7 @@ protected:
|
||||||
Q_INVOKABLE void updateItem(const QString& certificateId);
|
Q_INVOKABLE void updateItem(const QString& certificateId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _appsPath;
|
const QString _appsPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_QmlCommerce_h
|
#endif // hifi_QmlCommerce_h
|
||||||
|
|
Loading…
Reference in a new issue