Skip to content

Commit

Permalink
Added support for pebble-time appstore fixes smokku#79
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfy committed Oct 10, 2015
1 parent dff2ba6 commit 8bee022
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
38 changes: 33 additions & 5 deletions app/pebblestoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ PebbleStoreView::PebbleStoreView()

this->m_networkManager = new QNetworkAccessManager(this);
connect(this->m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onNetworkReplyFinished(QNetworkReply*)));
}

void PebbleStoreView::fetchConfig()
{
qDebug()<<this->m_hardwarePlatform;

if (this->m_hardwarePlatform == "aplite") {
this->m_configUrl = QUrl("https://boot.getpebble.com/api/config/android/v1/3");
} else {
this->m_configUrl = QUrl("https://boot.getpebble.com/api/config/android/v3/1?app_version=3.4.0");

This comment has been minimized.

Copy link
@smokku

smokku Oct 10, 2015

why hardcoded 3.4.0?

This comment has been minimized.

Copy link
@smurfy

smurfy Oct 10, 2015

Author Owner

The app_version param is required to get the config.
Also why not hardcode it, this way we know that the config for this pebble times android version works with our app.

If we do some fetch latest android app version and adding the latest app_version and they change something it could break something at our end. Sure even with hardcoding the version it still can break something (see smokku#88) but hey.

This comment has been minimized.

Copy link
@smokku

smokku Oct 10, 2015

makes sense.
maybe some comment that "we are pretending to be android app 3.4.0"?

}

this->m_configUrl = QUrl("https://boot.getpebble.com/api/config/android/v1/3");
this->m_downloadInProgress = false;
emit downloadInProgressChanged();

Expand All @@ -31,10 +41,25 @@ void PebbleStoreView::setAccessToken(const QString &accessToken)
emit accessTokenChanged(accessToken);
}

QString PebbleStoreView::hardwarePlatform() const
{
return this->m_hardwarePlatform;
}

void PebbleStoreView::setHardwarePlatform(const QString &hardwarePlatform)
{
this->m_hardwarePlatform = hardwarePlatform;
emit hardwarePlatformChanged(hardwarePlatform);

//We need to refetch the config after a platform change
this->fetchConfig();
}


void PebbleStoreView::logout()
{
setAccessToken("");
setUrl(prepareUrl(this->storeConfigObject.value("webviews").toObject().value("authentication").toString()));
setUrl(prepareUrl(this->storeConfigObject.value("webviews").toObject().value("authentication/sign_in").toString()));
}

bool PebbleStoreView::loggedin()
Expand Down Expand Up @@ -128,7 +153,7 @@ void PebbleStoreView::onNetworkReplyFinished(QNetworkReply* reply)
this->storeConfigObject = jsonObject.value("config").toObject();

if (this->m_accessToken.isEmpty()) {
setUrl(prepareUrl(this->storeConfigObject.value("webviews").toObject().value("authentication").toString()));
setUrl(prepareUrl(this->storeConfigObject.value("webviews").toObject().value("authentication/sign_in").toString()));
} else {
setUrl(prepareUrl(this->storeConfigObject.value("webviews").toObject().value("onboarding/get_some_apps").toString()));
}
Expand Down Expand Up @@ -164,9 +189,12 @@ void PebbleStoreView::onNetworkReplyFinished(QNetworkReply* reply)
QUrl PebbleStoreView::prepareUrl(QString baseUrl)
{
baseUrl = baseUrl.replace("$$user_id$$", "ZZZ");
baseUrl = baseUrl.replace("$$phone_id$$", "XXX");
baseUrl = baseUrl.replace("$$pebble_id$$", "YYY");
baseUrl = baseUrl.replace("$$phone_id$$", "XXX"); //Unique phone id
baseUrl = baseUrl.replace("$$pebble_id$$", "YYY"); //official APP puts serial here
baseUrl = baseUrl.replace("$$pebble_color$$", "64");

This comment has been minimized.

Copy link
@smokku

smokku Oct 10, 2015

What about Pebble Classic? Does it have 64 colors too?

This comment has been minimized.

Copy link
@smurfy

smurfy Oct 10, 2015

Author Owner

no, but the $$pebble_color$$ variable is not present in the pebble classic url.
Also as a side note, i'm not sure that 64 is the correct value, due to the decompiled pebble time android app is not as clean as the old app. (lot of not decompileable method names, so there a lot of dummy methods called a or other characters of the alphabet. I'm not sure if the query param is used in the store anyway. my guess is the important param is the hardware one.

This comment has been minimized.

Copy link
@smurfy

smurfy Oct 10, 2015

Author Owner

if you like i could wrap the new variables replacement in a if platform = ... statement but why.

This comment has been minimized.

Copy link
@smokku

smokku Oct 10, 2015

"$$pebble_color$$ variable is not present in the pebble classic url" - aaaah... as simple as that.
yes. then it is ok. :)

baseUrl = baseUrl.replace("$$hardware$$", this->m_hardwarePlatform);
baseUrl = baseUrl.replace("$$access_token$$", this->m_accessToken);
baseUrl = baseUrl.replace("$$extras$$", "");

qDebug()<<baseUrl;

Expand Down
6 changes: 6 additions & 0 deletions app/pebblestoreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ class PebbleStoreView : public QQuickWebView
Q_PROPERTY(bool loggedin READ loggedin NOTIFY accessTokenChanged)
Q_PROPERTY(bool downloadInProgress READ downloadInProgress NOTIFY downloadInProgressChanged)
Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken NOTIFY accessTokenChanged)
Q_PROPERTY(QString hardwarePlatform READ hardwarePlatform WRITE setHardwarePlatform NOTIFY hardwarePlatformChanged)

bool loggedin();
bool downloadInProgress();
QString accessToken() const;
void setAccessToken(const QString &accessToken);
QString hardwarePlatform() const;
void setHardwarePlatform(const QString &hardwarePlatform);

public slots:
void gotoWatchFaces();
Expand All @@ -34,6 +37,7 @@ private slots:

signals:
void accessTokenChanged(const QString & accessToken);
void hardwarePlatformChanged(const QString & hardwarePlatform);
void downloadPebbleApp(const QString & downloadTitle, const QString & downloadUrl);
void downloadInProgressChanged();
void titleChanged(const QString & title);
Expand All @@ -42,11 +46,13 @@ private slots:
QNetworkAccessManager* m_networkManager;
QUrl m_configUrl;
QString m_accessToken;
QString m_hardwarePlatform;
QJsonObject downloadObject;
QJsonObject storeConfigObject;
bool m_downloadInProgress;

QUrl prepareUrl(QString baseUrl);
void fetchConfig();
void fetchData(QUrl url);
void addToLocker(QJsonObject data);
void removeFromLocker(QJsonObject data);
Expand Down
1 change: 1 addition & 0 deletions app/qml/pages/AppStorePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Page {
}

accessToken: settings.storeAccessToken
hardwarePlatform: pebbled.info.platform

onAccessTokenChanged: {
settings.storeAccessToken = accessToken;
Expand Down
13 changes: 13 additions & 0 deletions daemon/watchconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ QVariantMap WatchConnector::WatchVersions::toMap() const
map.insert("bootloader", this->bootLoaderBuild.toTime_t());
map.insert("serial", this->serialNumber);
map.insert("address", this->address.toHex());
map.insert("platform", this->hardwarePlatform);
map.insertMulti("firmware", this->main.toMap());
map.insertMulti("firmware", this->safe.toMap());
}
Expand Down Expand Up @@ -126,6 +127,18 @@ WatchConnector::WatchConnector(QObject *parent) :

platform = hardwareMapping.value(_versions.safe.hw_revision).first;

switch (this->platform) {
case APLITE:
_versions.hardwarePlatform = "aplite";
break;
case BASALT:
_versions.hardwarePlatform = "basalt";
break;
case CHALK:
_versions.hardwarePlatform = "chalk";
break;
}

if (u.bad()) {
qCWarning(l) << "short read while reading firmware version";
} else {
Expand Down
1 change: 1 addition & 0 deletions daemon/watchconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class WatchConnector : public QObject
SoftwareVersion safe;
QDateTime bootLoaderBuild;
QString hardwareRevision;
QString hardwarePlatform;
QString serialNumber;
QByteArray address;

Expand Down

0 comments on commit 8bee022

Please sign in to comment.