Skip to content

Commit

Permalink
Added a function to get the application version from the latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nighty3098 committed Jun 3, 2024
1 parent 3ae3877 commit 244396b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/CodeKeeper/settingsFunc/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,36 @@ void SettingsWindow::fopenFolder()
}
}

void SettingsWindow::getAppVersion() {
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QUrl url("https://api.github.com/repos/Nighty3098/CodeKeeper/releases/latest");

QUrlQuery query;
query.addQueryItem("login", git_user);
url.setQuery(query);

QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
request.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
request.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
request.setRawHeader("Accept", "application/vnd.github.v3+json");

QNetworkReply *reply = manager->get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

loop.exec();

QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
QJsonObject obj = doc.object();

QString version = obj["name"].toString();

reply->deleteLater();

versionInfo->setText(version);
}

void SettingsWindow::setFontPr2(QFont *selectedFont, int *font_size_int)
{
qDebug() << "🟢 Applying preferences";
Expand Down
10 changes: 9 additions & 1 deletion src/CodeKeeper/settingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QMainWindow{ parent }
urlToRepo->setAlignment(Qt::AlignHCenter | Qt::AlignTop);

versionInfo = new QLabel();
versionInfo->setText("Version: 0.1.5");
versionInfo->setText("");
versionInfo->setAlignment(Qt::AlignCenter);

checkUpdatesBtn =
Expand Down Expand Up @@ -373,6 +373,14 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QMainWindow{ parent }
qDebug() << "🟢 styleThread started";
});
styleThread->start();

QThread *versionThread = new QThread;
QObject::connect(versionThread, &QThread::started, this, [this]() {
getAppVersion();

qDebug() << "🟢 versionThread started";
});
versionThread->start();
}

SettingsWindow::~SettingsWindow() { }
1 change: 1 addition & 0 deletions src/CodeKeeper/settingswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private slots:

void setFontPr2(QFont *selectedFont, int *font_size_int);
void checkRepo();
void getAppVersion();

private:
QWidget *centralWidget;
Expand Down

0 comments on commit 244396b

Please sign in to comment.