Treat QmlCommerce as a singleton class

This commit is contained in:
Simon Walton 2019-01-22 17:13:36 -08:00
parent 3776472550
commit 3a5d550fa5
2 changed files with 7 additions and 4 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

@ -19,7 +19,9 @@
#include <QPixmap>
class QmlCommerce : public QObject {
#include <DependencyManager.h>
class QmlCommerce : public QObject, public Dependency {
Q_OBJECT
public: