mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-19 18:33:00 +08:00
[feat] add mobile update badges and iOS simulator support
This commit is contained in:
@@ -21,7 +21,7 @@ struct VersionInfo {
|
||||
int patch = -1;
|
||||
};
|
||||
|
||||
// Shared desktop release parsing and comparison for desktop and iOS controllers.
|
||||
// Shared release parsing and comparison for desktop and mobile controllers.
|
||||
std::optional<VersionInfo> ParseVersionInfoJSON(std::string_view json);
|
||||
bool IsValidAppVersion(const std::string& version);
|
||||
|
||||
@@ -38,6 +38,13 @@ bool IsNewerVersionWithMetadata(const std::string& current,
|
||||
std::optional<std::string> AvailableAppUpdate(const std::string& current,
|
||||
const VersionInfo& latest);
|
||||
|
||||
// Local mobile updates use downloads[platform], never the desktop release at
|
||||
// the root. nullopt means invalid/unavailable metadata; an empty string means
|
||||
// up to date, otherwise the result is the newer release's display version.
|
||||
std::optional<std::string> CheckPlatformAppUpdate(const std::string& current,
|
||||
std::string_view json,
|
||||
const std::string& platform);
|
||||
|
||||
} // namespace crossdesk
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -348,6 +348,20 @@ bool IsValidAppVersion(const std::string& version) {
|
||||
return ParseVersionInfo(nlohmann::json{{"version", version}}).has_value();
|
||||
}
|
||||
|
||||
std::optional<std::string> CheckPlatformAppUpdate(const std::string& current,
|
||||
std::string_view json,
|
||||
const std::string& platform) {
|
||||
if (!IsValidAppVersion(current)) return std::nullopt;
|
||||
try {
|
||||
const auto manifest = nlohmann::json::parse(json);
|
||||
const auto latest = ParseVersionInfo(manifest.at("downloads").at(platform));
|
||||
if (!latest) return std::nullopt;
|
||||
return AvailableAppUpdate(current, *latest).value_or("");
|
||||
} catch (const nlohmann::json::exception&) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> AvailableAppUpdate(const std::string& current,
|
||||
const VersionInfo& latest) {
|
||||
if (!IsValidAppVersion(latest.version) ||
|
||||
|
||||
Reference in New Issue
Block a user