Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to firebase_sdk_cpp_4.1.0; #32

Merged
merged 1 commit into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/platformutils.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#include "platformutils.h"

#include "google_play_services/availability.h"

#include <QDebug>

PlatformUtils::PlatformUtils()
{

}

bool PlatformUtils::googleServiceAvailable()
{

#if defined(Q_OS_ANDROID)
QAndroidJniEnvironment env;
QAndroidJniObject activity = QtAndroid::androidActivity();

auto availablity = ::google_play_services::CheckAvailability(env, activity.object());
qDebug() << "PlatformUtils::googleServiceAvailable() result :" << availablity << " (0 is kAvailabilityAvailable)";
return ::google_play_services::kAvailabilityAvailable == availablity;
#endif
return false;
}

#if defined(Q_OS_ANDROID)
jobject PlatformUtils::getNativeWindow()
{
Expand Down
2 changes: 2 additions & 0 deletions src/platformutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class PlatformUtils
public:
PlatformUtils();

static bool googleServiceAvailable();

#if defined(Q_OS_IOS)
static void* getNativeWindow();
#elif defined(Q_OS_ANDROID)
Expand Down
2 changes: 2 additions & 0 deletions src/qtfirebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ QtFirebase::QtFirebase(QObject* parent) : QObject(parent)
{
_ready = false;

qDebug() << self << ":QtFirebase(QObject* parent)" ;

Q_ASSERT_X(!self, "QtFirebase", "there should be only one firebase object");
QtFirebase::self = this;

Expand Down
1 change: 1 addition & 0 deletions src/qtfirebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "firebase/app.h"
#include "firebase/future.h"
#include "firebase/util.h"

#include <QMap>
#include <QObject>
Expand Down
47 changes: 39 additions & 8 deletions src/qtfirebaseremoteconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "qtfirebaseremoteconfig.h"
#include <memory>

#include "google_play_services/availability.h"

namespace remote_config = ::firebase::remote_config;

QtFirebaseRemoteConfig *QtFirebaseRemoteConfig::self = 0;
Expand All @@ -13,14 +15,22 @@ QtFirebaseRemoteConfig::QtFirebaseRemoteConfig(QObject *parent) :
__appId(nullptr)
{
__QTFIREBASE_ID = QString().sprintf("%8p", this);

if(self == 0)
{
self = this;
qDebug() << self << "::QtFirebaseRemoteConfig" << "singleton";
}

QTimer::singleShot(500, this, SLOT(beforeInit()));
connect(qFirebase,&QtFirebase::futureEvent, this, &QtFirebaseRemoteConfig::onFutureEvent);
if (PlatformUtils::googleServiceAvailable()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll pull it it. I'll add an issue to add this to the other modules depending on Google Services:
https://firebase.google.com/docs/cpp/setup#requiring_google_play_services

qDebug() << this << " Google Service is available, now init remote_config" ;

//Call init outside of constructor, otherwise signal readyChanged not emited
QTimer::singleShot(500, this, SLOT(beforeInit()));
connect(qFirebase,&QtFirebase::futureEvent, this, &QtFirebaseRemoteConfig::onFutureEvent);
} else {
qDebug() << this << " Google Service is NOT available, CANNOT use remote_config" ;
}
}

bool QtFirebaseRemoteConfig::checkInstance(const char *function)
Expand All @@ -39,7 +49,6 @@ void QtFirebaseRemoteConfig::beforeInit()
{
if(qFirebase->ready())
{
//Call init outside of constructor, otherwise signal readyChanged not emited
qDebug() << this << " beforeInit : QtFirebase is ready, call init." ;
init();
}
Expand Down Expand Up @@ -126,10 +135,14 @@ void QtFirebaseRemoteConfig::init()

if(!_ready && !_initializing) {
_initializing = true;
remote_config::Initialize(*qFirebase->firebaseApp());
qDebug() << self << "::init" << "native initialized";
_initializing = false;
setReady(true);

::firebase::ModuleInitializer initializer;
auto future = initializer.Initialize(qFirebase->firebaseApp(), nullptr, [](::firebase::App* app, void*) {
qDebug() << self << "::init" << "try to initialize Remote Config";
return ::firebase::remote_config::Initialize(*app);
});

qFirebase->addFuture(__QTFIREBASE_ID + QStringLiteral(".config.init"), future);
}
}

Expand All @@ -139,9 +152,27 @@ void QtFirebaseRemoteConfig::onFutureEvent(QString eventId, firebase::FutureBase
return;

qDebug() << self << "::onFutureEvent" << eventId;
if(eventId != __QTFIREBASE_ID + QStringLiteral(".config.fetch"))
if(eventId == __QTFIREBASE_ID + QStringLiteral(".config.fetch"))
onFutureEventFetch(future);
else if( eventId == __QTFIREBASE_ID + QStringLiteral(".config.init") )
onFutureEventInit(future);
}

void QtFirebaseRemoteConfig::onFutureEventInit(firebase::FutureBase &future)
{
if (future.error() != firebase::kFutureStatusComplete) {
qDebug() << this << "::onFutureEvent" << "initializing failed." << "ERROR: Action failed with error code and message: " << future.error() << future.error_message();
_initializing = false;
return;
}

qDebug() << this << "::onFutureEvent initialized ok";
_initializing = false;
setReady(true);
}

void QtFirebaseRemoteConfig::onFutureEventFetch(firebase::FutureBase &future)
{
if(future.status() != firebase::kFutureStatusComplete)
{
qDebug() << this << "::onFutureEvent initializing failed." << "ERROR: Action failed with error code and message: " << future.error() << future.error_message();
Expand Down
2 changes: 2 additions & 0 deletions src/qtfirebaseremoteconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ private slots:
void beforeInit();
void init();
void onFutureEvent(QString eventId, firebase::FutureBase future);
void onFutureEventInit(firebase::FutureBase& future);
void onFutureEventFetch(firebase::FutureBase& future);

private:
void setReady(bool ready);
Expand Down