Update-to-same version dialog immediately after updating.

This commit is contained in:
Robin Davies
2024-10-14 16:12:32 -04:00
parent 6711860b05
commit 632b96eeff
2 changed files with 53 additions and 11 deletions
+43 -8
View File
@@ -68,7 +68,7 @@ public:
virtual void SetUpdatePolicy(UpdatePolicyT updatePolicy) override; virtual void SetUpdatePolicy(UpdatePolicyT updatePolicy) override;
virtual void ForceUpdateCheck() override; virtual void ForceUpdateCheck() override;
virtual void DownloadUpdate(const std::string &url, std::filesystem::path *file, std::filesystem::path *signatureFile) override; virtual void DownloadUpdate(const std::string &url, std::filesystem::path *file, std::filesystem::path *signatureFile) override;
virtual UpdateStatus GetCurrentStatus() const override { return this->currentResult; } virtual UpdateStatus GetCurrentStatus() const override;
virtual UpdateStatus GetReleaseGeneratorStatus() override; virtual UpdateStatus GetReleaseGeneratorStatus() override;
private: private:
@@ -156,7 +156,7 @@ UpdateStatus UpdaterImpl::GetCachedUpdateStatus()
reader.read(&status); reader.read(&status);
// cached curruent version might come from a different version. // cached curruent version might come from a different version.
status.ResetCurrentVersion(); status.UpdateForCurrentVersion();
return status; return status;
} }
} }
@@ -416,6 +416,36 @@ static int compareVersions(const std::string &l, const std::string &r)
} }
return 0; return 0;
} }
void UpdateRelease::UpdateForCurrentVersion(const std::string&currentVersion)
{
if (compareVersions(currentVersion,this->UpgradeVersion()) >= 0)
{
this->updateAvailable_ = false;
}
}
bool UpdateStatus::UpdateAvailable() const
{
if (!isValid_) return false;
switch (this->UpdatePolicy())
{
case UpdatePolicyT::Development:
return this->devRelease_.UpdateAvailable();
break;
case UpdatePolicyT::ReleaseOnly:
return this->releaseOnlyRelease_.UpdateAvailable();
case UpdatePolicyT::ReleaseOrBeta:
this->releaseOrBetaRelease_.UpdateAvailable();
default:
case UpdatePolicyT::Disabled:
return false;
}
}
static std::string normalizeReleaseName(const std::string &releaseName) static std::string normalizeReleaseName(const std::string &releaseName)
{ {
// e.g. "PiPedal 1.2.34 Release" -> "PiPedal v1.2.34-Release" // e.g. "PiPedal 1.2.34 Release" -> "PiPedal v1.2.34-Release"
@@ -897,16 +927,20 @@ UpdateStatus::UpdateStatus()
#endif #endif
} }
void UpdateStatus::ResetCurrentVersion() void UpdateStatus::UpdateForCurrentVersion()
{ {
currentVersion_ = PROJECT_VER; currentVersion_ = PROJECT_VER;
currentVersionDisplayName_ = PROJECT_DISPLAY_VERSION; currentVersionDisplayName_ = PROJECT_DISPLAY_VERSION;
#ifdef TEST_UPDATE #if defined(TEST_UPDATE) && defined(DEBUG)
// uncomment this line to test upgrading. // uncomment this line to test upgrading.
currentVersion_ = "1.2.39"; currentVersion_ = "1.2.39";
currentVersionDisplayName_ = "PiPedal 1.2.39-Debug"; currentVersionDisplayName_ = "PiPedal 1.2.39-Fictional";
#endif #endif
this->devRelease_.UpdateForCurrentVersion(currentVersion_);;
this->releaseOnlyRelease_.UpdateForCurrentVersion(currentVersion_);
this->releaseOrBetaRelease_.UpdateForCurrentVersion(currentVersion_);
} }
std::chrono::system_clock::time_point UpdateStatus::LastUpdateTime() const std::chrono::system_clock::time_point UpdateStatus::LastUpdateTime() const
@@ -953,9 +987,6 @@ const GithubAsset *GithubRelease::GetDownloadForCurrentArchitecture() const
return nullptr; return nullptr;
} }
UpdateRelease::UpdateRelease()
{
}
std::string UpdaterImpl::GetSignatureUrl(const std::string &url) std::string UpdaterImpl::GetSignatureUrl(const std::string &url)
{ {
@@ -1327,6 +1358,10 @@ void UpdaterImpl::DownloadUpdate(const std::string &url, std::filesystem::path *
} }
} }
UpdateStatus UpdaterImpl::GetCurrentStatus() const {
return this->currentResult;
}
void UpdateStatus::AddRelease(const std::string&packageName) void UpdateStatus::AddRelease(const std::string&packageName)
{ {
+10 -3
View File
@@ -22,7 +22,9 @@
#include "json.hpp" #include "json.hpp"
namespace pipedal { namespace pipedal {
enum class UpdatePolicyT class UpdateStatus;
enum class UpdatePolicyT
{ {
// ordinal values must not change, as files depend on them. // ordinal values must not change, as files depend on them.
// must match declaration in Updater.tsx // must match declaration in Updater.tsx
@@ -37,14 +39,15 @@ namespace pipedal {
{ {
private: private:
friend class UpdaterImpl; friend class UpdaterImpl;
friend class UpdateStatus;
bool updateAvailable_ = false; bool updateAvailable_ = false;
std::string upgradeVersion_; // just the version. std::string upgradeVersion_; // just the version.
std::string upgradeVersionDisplayName_; // display name for the version. std::string upgradeVersionDisplayName_; // display name for the version.
std::string assetName_; // filename only std::string assetName_; // filename only
std::string updateUrl_; // url from which to download the .deb file. std::string updateUrl_; // url from which to download the .deb file.
std::string gpgSignatureUrl_; // url from which to download the .deb.asc file. std::string gpgSignatureUrl_; // url from which to download the .deb.asc file.
void UpdateForCurrentVersion(const std::string&currentVersion);
public: public:
UpdateRelease();
bool UpdateAvailable() const { return updateAvailable_; } bool UpdateAvailable() const { return updateAvailable_; }
const std::string &UpgradeVersion() const { return upgradeVersion_; } const std::string &UpgradeVersion() const { return upgradeVersion_; }
@@ -78,8 +81,12 @@ namespace pipedal {
std::chrono::system_clock::time_point LastUpdateTime() const; std::chrono::system_clock::time_point LastUpdateTime() const;
void LastUpdateTime(const std::chrono::system_clock::time_point &timePoint); void LastUpdateTime(const std::chrono::system_clock::time_point &timePoint);
void ResetCurrentVersion();
void UpdateForCurrentVersion();
bool IsValid() const { return isValid_; } bool IsValid() const { return isValid_; }
bool UpdateAvailable() const;
const std::string &ErrorMessage() const { return errorMessage_; } const std::string &ErrorMessage() const { return errorMessage_; }
bool IsOnline() const { return isOnline_; } bool IsOnline() const { return isOnline_; }
const std::string &CurrentVersion() const { return currentVersion_; } const std::string &CurrentVersion() const { return currentVersion_; }