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

Trying to get auto sync from peloton API #1772

61 changes: 61 additions & 0 deletions src/Browser.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.0
import Qt.labs.settings 1.0
import QtWebView 1.1

Item {
id: column1

signal browser_peloton_time_to_complete(string time_to_complete)
signal browser_peloton_time_to_start(string time_to_start)

Settings {
id: settings
}

WebView {
id: webView
property var rr;
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width

url: "https://onepeloton.com"
visible: true
onLoadingChanged: {
if (loadRequest.errorString)
console.error(loadRequest.errorString);
if (loadRequest.status == WebView.LoadSucceededStatus) {
console.error("Procedo");
let loadScr = `
var findAndDisplayElement = function() {
var p = document.querySelector('p[data-test-id="time-to-complete"]');
if (p) {
browser_peloton_time_to_complete(p.innerText);
console.log(p.innerText);
} else {
console.log("Element not found");
}

p = document.querySelector('p[data-test-id="time-to-start"]');
if (p) {
browser_peloton_time_to_start(p.innerText);
console.log(p.innerText);
} else {
console.log("Element not found");
}
};

findAndDisplayElement(); // Run immediately on first load
setInterval(findAndDisplayElement, 1000); // Then run every 1000 milliseconds (1 second)
`;
console.error(loadScr);
webView.runJavaScript(loadScr, function(res) {
});
}
}
}
}
14 changes: 14 additions & 0 deletions src/homeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ homeform::homeform(QQmlApplicationEngine *engine, bluetooth *bl) {
QObject::connect(stack, SIGNAL(keyMediaNext()), this, SLOT(keyMediaNext()));
QObject::connect(stack, SIGNAL(floatingOpen()), this, SLOT(floatingOpen()));
QObject::connect(stack, SIGNAL(openFloatingWindowBrowser()), this, SLOT(openFloatingWindowBrowser()));
QObject::connect(stack, SIGNAL(browser_peloton_time_to_complete(QString)), this, SLOT(browser_peloton_time_to_complete(QString)));
QObject::connect(stack, SIGNAL(browser_peloton_time_to_start(QString)), this, SLOT(browser_peloton_time_to_start(QString)));

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
QObject::connect(engine, &QQmlApplicationEngine::quit, &QGuiApplication::quit);
Expand Down Expand Up @@ -5211,6 +5213,18 @@ bool homeform::getLap() {
return true;
}

void homeform::browser_peloton_time_to_complete(const QString time_to_complete) {
qDebug() << QStringLiteral("browser_peloton_time_to_complete") << time_to_complete << trainProgram;
if(trainProgram)
trainProgram->pelotonOCRcomputeTime(time_to_complete);
}

void homeform::browser_peloton_time_to_start(const QString time_to_start) {
qDebug() << QStringLiteral("browser_peloton_time_to_start") << time_to_start << trainProgram;
if(trainProgram)
trainProgram->pelotonOCRcomputeTime("INTRO");
}

void homeform::copyAndroidContentsURI(QFile* file, QString subfolder) {
#ifdef Q_OS_ANDROID
QString filename = file->fileName();
Expand Down
2 changes: 2 additions & 0 deletions src/homeform.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ class homeform : public QObject {
void deviceFound(const QString &name);
void deviceConnected(QBluetoothDeviceInfo b);
void ftmsAccessoryConnected(smartspin2k *d);
void browser_peloton_time_to_complete(const QString time_to_complete);
void browser_peloton_time_to_start(const QString time_to_start);
void trainprogram_open_clicked(const QUrl &fileName);
void profile_open_clicked(const QUrl &fileName);
void trainprogram_preview(const QUrl &fileName);
Expand Down
5 changes: 2 additions & 3 deletions src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,11 @@ ApplicationWindow {

ItemDelegate {
id: gpx_save
text: qsTr("Save GPX")
text: qsTr("Open Browser")
width: parent.width
onClicked: {
gpx_save_clicked()
drawer.close()
popupSaveFile.open()
stackView.push("Browser.qml")
}
}
ItemDelegate {
Expand Down
1 change: 1 addition & 0 deletions src/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@
<file>ChartFooter.qml</file>
<file>ChartFooterInnerJS.qml</file>
<file>ChartFooterInnerNoJS.qml</file>
<file>Browser.qml</file>
</qresource>
</RCC>
5 changes: 3 additions & 2 deletions src/trainprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class trainprogram : public QObject {
}
return false;
}

void pelotonOCRcomputeTime(QString t);

QList<trainrow> rows;
QList<trainrow> loadedRows; // rows as loaded
Expand Down Expand Up @@ -153,8 +155,7 @@ private slots:
double lastCurrentStepDistance = 0.0;
QTime lastCurrentStepTime = QTime(0, 0, 0);

QUdpSocket* pelotonOCRsocket = nullptr;
void pelotonOCRcomputeTime(QString t);
QUdpSocket* pelotonOCRsocket = nullptr;
};

#endif // TRAINPROGRAM_H
Loading