Skip to content

Commit

Permalink
Fix issues according to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttyartist committed Aug 24, 2023
1 parent ecc6353 commit 1b60a5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
52 changes: 22 additions & 30 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MainWindow::MainWindow(QWidget *parent)
m_subscriptionWindowQuickView(nullptr),
m_subscriptionWindowWidget(new QWidget(this)),
m_purchaseDataAlt1(QStringLiteral("https://raw.githubusercontent.com/nuttyartist/notes/"
"master/notes_purchase_data.json")),
"master/notes_purchase_data.jsonhkk")),
m_purchaseDataAlt2(
QStringLiteral("https://www.rubymamistvalove.com/notes/notes_purchase_data.json")),
m_dataBuffer(new QByteArray()),
Expand Down Expand Up @@ -1377,17 +1377,19 @@ void MainWindow::getPaymentDetailsSignalsSlots()
connect(m_netPurchaseDataReplyFirstAttempt, &QNetworkReply::readyRead, this,
[this]() { m_dataBuffer->append(m_netPurchaseDataReplyFirstAttempt->readAll()); });
connect(m_netPurchaseDataReplyFirstAttempt, &QNetworkReply::finished, this, [this]() {
// Handle error
if (m_netPurchaseDataReplyFirstAttempt->error() != QNetworkReply::NoError) {
qDebug() << "Error : " << m_netPurchaseDataReplyFirstAttempt->errorString();
qDebug() << "Failed first attempt at getting data. Trying second...";
qDebug() << "Failed first attempt at getting payment data. Trying second...";
emit tryPurchaseDataSecondAlternative();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
} else {
qDebug() << "success 1";
m_paymentDetails = QJsonDocument::fromJson(*m_dataBuffer).object();
emit fetchingPaymentDetailsRemotelyFinished();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
return;
}

// Handle success
m_paymentDetails = QJsonDocument::fromJson(*m_dataBuffer).object();
emit fetchingPaymentDetailsRemotelyFinished();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
});
}

Expand All @@ -1403,12 +1405,13 @@ void MainWindow::verifyLicenseSignalsSlots()
connect(m_netPurchaseDataReplySecondAttempt, &QNetworkReply::readyRead, this,
[this]() { m_dataBuffer->append(m_netPurchaseDataReplySecondAttempt->readAll()); });
connect(m_netPurchaseDataReplySecondAttempt, &QNetworkReply::finished, this, [this]() {
if (m_netPurchaseDataReplySecondAttempt->error() != QNetworkReply::NoError) {
qDebug() << "Error : " << m_netPurchaseDataReplySecondAttempt->errorString();
qDebug() << "Failed second attempt at getting data. Using embedded data...";
} else {
qDebug() << "success 2";
// Handle success
if (m_netPurchaseDataReplySecondAttempt->error() == QNetworkReply::NoError) {
m_paymentDetails = QJsonDocument::fromJson(*m_dataBuffer).object();
} else {
// Handle error - ignore and use defaulte hard-coded/embedded payment data
qDebug() << "Failed second attempt at getting payment data. Using default embedded "
"payment data...";
}
emit fetchingPaymentDetailsRemotelyFinished();
m_netPurchaseDataReplySecondAttempt->deleteLater();
Expand All @@ -1417,8 +1420,7 @@ void MainWindow::verifyLicenseSignalsSlots()

connect(this, &MainWindow::fetchingPaymentDetailsRemotelyFinished, this, [this]() {
if (m_paymentDetails.isEmpty()) {
qDebug() << "Using default";

qDebug() << "Using default embedded payment data";
QJsonObject paymentDetailsDefault;
paymentDetailsDefault["purchase_pro_url"] = "https://www.get-notes.com/pricing";
paymentDetailsDefault["purchaseApiBase"] = "https://api.lemonsqueezy.com";
Expand All @@ -1427,10 +1429,6 @@ void MainWindow::verifyLicenseSignalsSlots()
paymentDetailsDefault["deactivateLicenseEndpoint"] = "/v1/licenses/deactivate";
m_paymentDetails = paymentDetailsDefault;
}
// else {
// qDebug() << "Using fetched data:";
// qDebug() << m_paymentDetails;
// }
emit gettingPaymentDetailsFinished();
});

Expand All @@ -1450,24 +1448,19 @@ void MainWindow::verifyLicenseSignalsSlots()
bool showSubscriptionWindowWhenNotPro = true;

if (reply->error() != QNetworkReply::NoError) {
qDebug() << "Error : " << reply->errorString();
QByteArray responseData = reply->readAll();
QJsonObject response = QJsonDocument::fromJson(responseData).object();
// qDebug() << "response object: " << response;

if (response.isEmpty()) {
// No Internet
if (!m_localLicenseData->contains(QStringLiteral("gracePeriodStartedDate"))) {
// qDebug() << "gracePeriodStartedDate not found";
// Show enterting grace period window
// gracePeriodStartedDate not found, so entering new one now
m_localLicenseData->setValue(QStringLiteral("gracePeriodStartedDate"),
QDateTime::currentDateTime());
skipSettingNotProOnError = true;
setActivationSuccessful(m_userLicenseKey, false);
m_subscriptionStatus = SubscriptionStatus::EnteredGracePeriod;
} else {
// qDebug() << "Date: " <<
// m_localLicenseData->value(QStringLiteral("gracePeriodStartedDate")).toDateTime().toString();
QDateTime gracePeriodStartedDate =
m_localLicenseData
->value(QStringLiteral("gracePeriodStartedDate"),
Expand Down Expand Up @@ -1509,10 +1502,8 @@ void MainWindow::verifyLicenseSignalsSlots()
m_aboutWindow.setProVersion(false);
}
} else {
// qDebug() << "Verification response:";
QByteArray responseData = reply->readAll();
QJsonObject response = QJsonDocument::fromJson(responseData).object();
// qDebug() << "response object: " << response;

if (response.contains("license_key") && response.contains("valid")
&& response["valid"] == true) {
Expand Down Expand Up @@ -1606,11 +1597,12 @@ void MainWindow::checkProVersion()
qDebug() << "Failed first attempt at getting data. Trying second...";
emit tryPurchaseDataSecondAlternative();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
} else {
m_paymentDetails = QJsonDocument::fromJson(*m_dataBuffer).object();
emit fetchingPaymentDetailsRemotelyFinished();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
return;
}

m_paymentDetails = QJsonDocument::fromJson(*m_dataBuffer).object();
emit fetchingPaymentDetailsRemotelyFinished();
m_netPurchaseDataReplyFirstAttempt->deleteLater();
});
} else {
m_isProVersionActivated = false;
Expand Down
2 changes: 1 addition & 1 deletion src/qml/TextButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Item {
id: root
width: root.backgroundSizeFitText ? buttonText.implicitWidth : root.backgroundWidth
height: root.backgroundSizeFitText ? buttonText.implicitHeight : root.backgroundHeight
required property string text
property string text
signal clicked
property var themeData: {{theme: "Light"}}
property real backgroundOpacity: 1.0
Expand Down
4 changes: 0 additions & 4 deletions src/qml/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ function request(verb, BASE, endpoint, obj, cb) {
// console.log('request: ' + verb + ' ' + BASE + (endpoint ? '/' + endpoint : ''));
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
// console.log('xhr: on ready state change: ' + xhr.readyState)
if(xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if(cb) {
var res = JSON.parse(xhr.responseText.toString())
// console.log(xhr.responseText.toString());
res.error = null;
cb(res)
}
Expand All @@ -24,11 +22,9 @@ function request(verb, BASE, endpoint, obj, cb) {
var errorResponse;
try {
errorResponse = JSON.parse(xhr.responseText.toString());
// console.log(xhr.responseText.toString());
} catch (err) {
errorResponse = {error: "error"};
}
// console.log(xhr.responseText.toString());
cb(errorResponse);
}
}
Expand Down

0 comments on commit 1b60a5b

Please sign in to comment.