mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-01 22:55:41 +08:00
#42 Enable reading update info from GitHub Packages REST API
This commit is contained in:
@@ -159,11 +159,15 @@ namespace BlackCore
|
||||
m_setupReader.reset(new CSetupReader(this));
|
||||
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::onSetupHandlingCompleted, Qt::QueuedConnection);
|
||||
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingCompleted, Qt::QueuedConnection); // hand thru
|
||||
connect(m_setupReader.data(), &CSetupReader::updateInfoAvailable, this, &CApplication::updateInfoAvailable, Qt::QueuedConnection);
|
||||
connect(m_setupReader.data(), &CSetupReader::successfullyReadSharedUrl, m_networkWatchDog, &CNetworkWatchdog::setWorkingSharedUrl, Qt::QueuedConnection);
|
||||
|
||||
this->addParserOptions(m_setupReader->getCmdLineOptions()); // add options from reader
|
||||
|
||||
// check for updates
|
||||
m_gitHubPackagesReader.reset(new CGitHubPackagesReader(this));
|
||||
connect(m_gitHubPackagesReader.data(), &CGitHubPackagesReader::updateInfoAvailable, this, &CApplication::updateInfoAvailable, Qt::QueuedConnection);
|
||||
reloadUpdateInfo();
|
||||
|
||||
// startup done
|
||||
connect(this, &CApplication::startUpCompleted, this, &CApplication::onStartUpCompleted, Qt::QueuedConnection);
|
||||
connect(this, &CApplication::coreFacadeStarted, this, &CApplication::onCoreFacadeStarted, Qt::QueuedConnection);
|
||||
@@ -336,9 +340,15 @@ namespace BlackCore
|
||||
CUpdateInfo CApplication::getUpdateInfo() const
|
||||
{
|
||||
if (m_shutdown) { return CUpdateInfo(); }
|
||||
const CSetupReader *r = m_setupReader.data();
|
||||
if (!r) { return CUpdateInfo(); }
|
||||
return r->getUpdateInfo();
|
||||
if (!m_gitHubPackagesReader) { return CUpdateInfo(); }
|
||||
return m_gitHubPackagesReader->getUpdateInfo();
|
||||
}
|
||||
|
||||
void CApplication::reloadUpdateInfo()
|
||||
{
|
||||
if (m_shutdown) { return; }
|
||||
if (!m_gitHubPackagesReader) { return; }
|
||||
m_gitHubPackagesReader->readUpdateInfo();
|
||||
}
|
||||
|
||||
CDistribution CApplication::getOwnDistribution() const
|
||||
@@ -1099,6 +1109,11 @@ namespace BlackCore
|
||||
m_webDataServices.reset();
|
||||
}
|
||||
|
||||
if (m_gitHubPackagesReader)
|
||||
{
|
||||
m_gitHubPackagesReader.reset();
|
||||
}
|
||||
|
||||
if (m_setupReader)
|
||||
{
|
||||
m_setupReader->gracefulShutdown();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackcore/corefacadeconfig.h"
|
||||
#include "blackcore/db/databasereaderconfig.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackcore/githubpackagesreader.h"
|
||||
#include "blackcore/application/applicationsettings.h"
|
||||
#include "blackcore/inputmanager.h"
|
||||
#include "blackcore/webreaderflags.h"
|
||||
@@ -166,9 +167,11 @@ namespace BlackCore
|
||||
Data::CGlobalSetup getGlobalSetup() const;
|
||||
|
||||
//! Update info
|
||||
//! \threadsafe
|
||||
BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
|
||||
|
||||
//! Reload update info
|
||||
void reloadUpdateInfo();
|
||||
|
||||
//! Own distribution
|
||||
//! \threadsafe
|
||||
BlackMisc::Db::CDistribution getOwnDistribution() const;
|
||||
@@ -714,6 +717,7 @@ namespace BlackCore
|
||||
BlackMisc::CApplicationInfo m_applicationInfo; //!< Application if specified
|
||||
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
|
||||
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
|
||||
QScopedPointer<CGitHubPackagesReader> m_gitHubPackagesReader; //!< github packages reader
|
||||
QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services
|
||||
QScopedPointer<BlackMisc::CFileLogger> m_fileLogger; //!< file logger
|
||||
QPointer<CCookieManager> m_cookieManager; //!< single cookie manager for our access manager
|
||||
|
||||
52
src/blackcore/githubpackagesreader.cpp
Normal file
52
src/blackcore/githubpackagesreader.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/* Copyright (C) 2020
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#include "githubpackagesreader.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QStringBuilder>
|
||||
#include <QUrl>
|
||||
|
||||
using namespace BlackMisc::Db;
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CGitHubPackagesReader::CGitHubPackagesReader(QObject *parent) : QObject(parent)
|
||||
{}
|
||||
|
||||
void CGitHubPackagesReader::readUpdateInfo()
|
||||
{
|
||||
// https://docs.github.com/en/rest/reference/repos#releases
|
||||
|
||||
const QNetworkRequest request(QUrl(CBuildConfig::gitHubRepoApiUrl() % u"releases"));
|
||||
auto reply = sApp->getNetworkAccessManager()->get(request);
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply]
|
||||
{
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
const auto updateInfo = CUpdateInfo::fromGitHubReleasesJson(reply->readAll());
|
||||
if (!updateInfo.isEmpty())
|
||||
{
|
||||
m_updateInfo.set(updateInfo);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
CUpdateInfo CGitHubPackagesReader::getUpdateInfo() const
|
||||
{
|
||||
return m_updateInfo.get();
|
||||
}
|
||||
}
|
||||
45
src/blackcore/githubpackagesreader.h
Normal file
45
src/blackcore/githubpackagesreader.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2020
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_GITHUBPACKAGESREADER_H
|
||||
#define BLACKCORE_GITHUBPACKAGESREADER_H
|
||||
|
||||
#include "blackmisc/db/updateinfo.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* Read available updates from GitHub Packages REST API.
|
||||
*/
|
||||
class CGitHubPackagesReader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor.
|
||||
CGitHubPackagesReader(QObject *parent = nullptr);
|
||||
|
||||
//! Read updates from GitHub Packages.
|
||||
void readUpdateInfo();
|
||||
|
||||
//! Get updates cached from previous read.
|
||||
BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
|
||||
|
||||
signals:
|
||||
//! Updates have been received from GitHub Packages.
|
||||
void updateInfoAvailable(bool available);
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Db::TUpdateInfo> m_updateInfo { this };
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user