(Android) Added a check for application updates on startup

This commit is contained in:
Leon Styhre 2024-02-25 12:26:32 +01:00
parent 2a5bc0cced
commit 68c906635f
5 changed files with 58 additions and 8 deletions

View file

@ -362,7 +362,7 @@ if(VIDEO_HW_DECODING)
message("-- Building with FFmpeg HW decoding")
endif()
if(AUR_BUILD OR FLATPAK_BUILD OR RETRODECK OR RPI OR ANDROID)
if(AUR_BUILD OR FLATPAK_BUILD OR RETRODECK OR RPI)
set(APPLICATION_UPDATER OFF)
endif()

View file

@ -229,7 +229,11 @@ void ApplicationUpdater::parseFile()
if (doc.HasParseError())
throw std::runtime_error(rapidjson::GetParseError_En(doc.GetParseError()));
#if defined(__ANDROID__)
const std::vector<std::string> releaseTypes {"stable"};
#else
const std::vector<std::string> releaseTypes {"stable", "prerelease"};
#endif
for (auto& releaseType : releaseTypes) {
Release release;
@ -237,11 +241,19 @@ void ApplicationUpdater::parseFile()
release.releaseType = releaseType.c_str();
const rapidjson::Value& releaseTypeEntry {doc[releaseType.c_str()]};
#if defined(__ANDROID__)
if (releaseTypeEntry.HasMember("androidVersionName") &&
releaseTypeEntry["androidVersionName"].IsString())
release.version = releaseTypeEntry["androidVersionName"].GetString();
else
throw std::runtime_error(
"Invalid file structure, \"androidVersionName\" key missing");
#else
if (releaseTypeEntry.HasMember("version") && releaseTypeEntry["version"].IsString())
release.version = releaseTypeEntry["version"].GetString();
else
throw std::runtime_error("Invalid file structure, \"version\" key missing");
#endif
// There may not be a prerelease available.
if (releaseType == "prerelease" && release.version == "")
continue;
@ -251,11 +263,25 @@ void ApplicationUpdater::parseFile()
else
throw std::runtime_error("Invalid file structure, \"release\" key missing");
#if defined(__ANDROID__)
if (releaseTypeEntry.HasMember("androidVersionCode") &&
releaseTypeEntry["androidVersionCode"].IsString())
release.androidVersionCode = releaseTypeEntry["androidVersionCode"].GetString();
else
throw std::runtime_error(
"Invalid file structure, \"androidVersionCode\" key missing");
if (releaseTypeEntry.HasMember("androidDate") &&
releaseTypeEntry["androidDate"].IsString())
release.date = releaseTypeEntry["androidDate"].GetString();
else
throw std::runtime_error("Invalid file structure, \"androidDate\" key missing");
#else
if (releaseTypeEntry.HasMember("date") && releaseTypeEntry["date"].IsString())
release.date = releaseTypeEntry["date"].GetString();
else
throw std::runtime_error("Invalid file structure, \"date\" key missing");
#endif
if (releaseTypeEntry.HasMember("packages") && releaseTypeEntry["packages"].IsArray()) {
const rapidjson::Value& packages {releaseTypeEntry["packages"]};
for (int i {0}; i < static_cast<int>(packages.Size()); ++i) {
@ -341,6 +367,7 @@ void ApplicationUpdater::compareVersions()
{
std::deque<Release*> releaseTypes {&mStableRelease};
#if !defined(__ANDROID__)
if (mPrerelease.releaseNum != "") {
#if defined(IS_PRERELEASE)
releaseTypes.emplace_front(&mPrerelease);
@ -349,6 +376,7 @@ void ApplicationUpdater::compareVersions()
releaseTypes.emplace_front(&mPrerelease);
#endif
}
#endif
mNewVersion = false;
@ -358,7 +386,15 @@ void ApplicationUpdater::compareVersions()
if (releaseType->version == "" || releaseType->releaseNum == "" || releaseType->date == "")
continue;
#if defined(__ANDROID__)
// This should hopefully never happen.
if (releaseType->androidVersionCode == "")
continue;
mNewVersion = (std::stoi(releaseType->androidVersionCode) > ANDROID_VERSION_CODE);
#else
mNewVersion = (std::stoi(releaseType->releaseNum) > PROGRAM_RELEASE_NUMBER);
#endif
if (mNewVersion) {
for (auto& package : releaseType->packages) {
@ -386,8 +422,13 @@ void ApplicationUpdater::compareVersions()
mPackage.message = mPackage.message.substr(0, 280);
mLogInfo = "A new ";
mLogInfo.append(releaseType == &mStableRelease ? "stable release" : "prerelease")
mLogInfo
#if defined(__ANDROID__)
.append("release is available from the app store: ")
#else
.append(releaseType == &mStableRelease ? "stable release" : "prerelease")
.append(" is available for download at https://es-de.org: ")
#endif
.append(releaseType->version)
.append(" (r")
.append(releaseType->releaseNum)
@ -407,11 +448,15 @@ void ApplicationUpdater::compareVersions()
mResults.append("release available: ").append(releaseType->version);
}
#if defined(__ANDROID__)
mResults.append("\nApply update via the app store");
#else
if (mPackageType == PackageType::UNKNOWN)
mResults.append("\nFor more information visit\n").append("https://es-de.org");
if (mPackage.message != "")
mResults.append("\n").append(mPackage.message);
#endif
mResults = Utils::String::toUpper(mResults);
break;
@ -450,10 +495,12 @@ bool ApplicationUpdater::getResults()
LOG(LogInfo) << mLogInfo;
}
#if !defined(__ANDROID__)
if (mNewVersion && mPackage.name == "") {
LOG(LogDebug) << "ApplicationUpdater::getResults(): Couldn't find a package type matching "
"current build";
}
#endif
return mNewVersion;
}

View file

@ -51,6 +51,7 @@ private:
std::string releaseType;
std::string version;
std::string releaseNum;
std::string androidVersionCode;
std::string date;
std::vector<Package> packages;
};

View file

@ -1612,7 +1612,7 @@ void GuiMenu::openOtherOptions()
});
#endif
#if defined(APPLICATION_UPDATER)
#if defined(APPLICATION_UPDATER) && !defined(__ANDROID__)
#if defined(IS_PRERELEASE)
// Add a dummy entry to indicate that this setting is always enabled when running a prerelease.
auto applicationUpdaterPrereleases = std::make_shared<SwitchComponent>();
@ -1864,7 +1864,7 @@ void GuiMenu::openOtherOptions()
});
#endif
#if defined(APPLICATION_UPDATER) && !defined(IS_PRERELEASE)
#if defined(APPLICATION_UPDATER) && !defined(__ANDROID__) && !defined(IS_PRERELEASE)
auto applicationUpdaterFrequencyFunc =
[applicationUpdaterPrereleases](const std::string& frequency) {
if (frequency == "never") {
@ -2100,10 +2100,10 @@ void GuiMenu::addVersionInfo()
#endif
#if defined(IS_PRERELEASE)
mVersion.setText(applicationName + " V" + Utils::String::toUpper(PROGRAM_VERSION_STRING) +
mVersion.setText(applicationName + " " + Utils::String::toUpper(PROGRAM_VERSION_STRING) +
" (Built " + __DATE__ + ")");
#else
mVersion.setText(applicationName + " V" + Utils::String::toUpper(PROGRAM_VERSION_STRING));
mVersion.setText(applicationName + " " + Utils::String::toUpper(PROGRAM_VERSION_STRING));
#endif
mVersion.setHorizontalAlignment(ALIGN_CENTER);

View file

@ -278,7 +278,9 @@ void Settings::setDefaults()
mStringMap["SaveGamelistsMode"] = {"always", "always"};
mStringMap["ApplicationUpdaterFrequency"] = {"always", "always"};
mStringMap["ApplicationUpdaterDownloadDirectory"] = {"", ""};
#if !defined(__ANDROID__)
mBoolMap["ApplicationUpdaterPrereleases"] = {false, false};
#endif
#if defined(_WIN64)
mBoolMap["HideTaskbar"] = {false, false};
#endif