Redo update checker responder to be more like unstable branch

This commit is contained in:
Liru Færs
2020-02-07 08:02:44 -05:00
parent 49f0f8e28f
commit 42139835d5

View File

@@ -10,116 +10,95 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
void onNotifyButtonPress(const LLSD& notification, const LLSD& response, std::string name, std::string url)
{
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
if (option == 0) // URL
{
if (gViewerWindow)
{
gViewerWindow->getWindow()->spawnWebBrowser(LLWeb::escapeURL(url), true);
}
}
}
void onCompleted(const LLSD& data, bool release)
{
S32 build(LLVersionInfo::getBuild());
std::string viewer_version = llformat("%s (%i)", LLVersionInfo::getShortVersion().c_str(), build);
#if LL_WINDOWS
constexpr auto platform = "windows";
#elif LL_LINUX
constexpr auto platform = "linux";
#elif LL_DARWIN
constexpr auto platform = "apple";
#endif
std::string recommended_version = data["recommended"][platform];
std::string minimum_version = data["minimum"][platform];
S32 minimum_build, recommended_build;
sscanf(recommended_version.c_str(), "%*i.%*i.%*i (%i)", &recommended_build);
sscanf(minimum_version.c_str(), "%*i.%*i.%*i (%i)", &minimum_build);
LL_INFOS("GetUpdateInfoResponder") << build << LL_ENDL;
LLSD args;
args["CURRENT_VER"] = viewer_version;
args["RECOMMENDED_VER"] = recommended_version;
args["MINIMUM_VER"] = minimum_version;
args["URL"] = data["url"].asString();
args["TYPE"] = release ? "Viewer" : "Alpha";
static LLCachedControl<S32> lastver(release ? "SinguLastKnownReleaseBuild" : "SinguLastKnownAlphaBuild", 0);
if (build < minimum_build || build < recommended_build)
{
if (lastver.get() < recommended_build)
{
lastver = recommended_build;
LLUI::sIgnoresGroup->setWarning("UrgentUpdateModal", true);
LLUI::sIgnoresGroup->setWarning("UrgentUpdate", true);
LLUI::sIgnoresGroup->setWarning("RecommendedUpdate", true);
}
const std::string&& notification = build < minimum_build ?
LLUI::sIgnoresGroup->getWarning("UrgentUpdateModal") ? "UrgentUpdateModal" : "UrgentUpdate" :
"RecommendedUpdate"; //build < recommended_build
LLNotificationsUtil::add(notification, args, LLSD(), boost::bind(onNotifyButtonPress, _1, _2, notification, data["url"].asString()));
}
}
extern AIHTTPTimeoutPolicy getUpdateInfoResponder_timeout; extern AIHTTPTimeoutPolicy getUpdateInfoResponder_timeout;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// GetUpdateInfoResponder // GetUpdateInfoResponder
class GetUpdateInfoResponder : public LLHTTPClient::ResponderWithCompleted class GetUpdateInfoResponder final : public LLHTTPClient::ResponderWithCompleted
{ {
LOG_CLASS(GetUpdateInfoResponder); LOG_CLASS(GetUpdateInfoResponder);
public: public:
GetUpdateInfoResponder(std::string type) GetUpdateInfoResponder(std::string type) : mType(type) {}
: mType(type) void completedRaw(LLChannelDescriptors const& channels, buffer_ptr_t const& buffer) override
{}
void onNotifyButtonPress(const LLSD& notification, const LLSD& response, std::string name, std::string url)
{ {
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
if (option == 0) // URL
{
std::string escaped_url = LLWeb::escapeURL(url);
if (gViewerWindow)
{
gViewerWindow->getWindow()->spawnWebBrowser(escaped_url, true);
}
}
if (option == 1) // Later
{}
}
/*virtual*/ void completedRaw(LLChannelDescriptors const& channels, buffer_ptr_t const& buffer)
{
LLBufferStream istr(channels, buffer.get());
std::stringstream strstrm;
strstrm << istr.rdbuf();
const std::string body = strstrm.str();
if (mStatus != HTTP_OK) if (mStatus != HTTP_OK)
{ {
LL_WARNS() << "Failed to get update info (" << mStatus << ")" << LL_ENDL; LL_WARNS() << "Failed to get update info (" << mStatus << ")" << LL_ENDL;
return; return;
} }
auto root = nlohmann::json::parse(body, nullptr, false); LLBufferStream istr(channels, buffer.get());
if (root.is_discarded()) std::stringstream strstrm;
strstrm << istr.rdbuf();
LLSD data = LlsdFromJsonString(strstrm.str());
if (data.isUndefined())
{ {
LL_WARNS() << "Failed to parse json string from body:\n" << body << LL_ENDL; LL_WARNS() << "Failed to parse json string from body." << LL_ENDL;
return; // TODO: Should we say something here for the user? // TODO: Should we say something here for the user?
} }
else onCompleted(data[mType], mType == "release")
std::string viewer_version = llformat("%s (%i)", LLVersionInfo::getShortVersion().c_str(), LLVersionInfo::getBuild());
const auto data = root[mType];
#if LL_WINDOWS
constexpr auto platform = "windows";
#elif LL_LINUX
constexpr auto platform = "linux";
#elif LL_DARWIN
constexpr auto platform = "apple";
#endif
std::string recommended_version = data["recommended"][platform];
std::string minimum_version = data["minimum"][platform];
S32 minimum_build, recommended_build;
sscanf(recommended_version.c_str(), "%*i.%*i.%*i (%i)", &recommended_build);
sscanf(minimum_version.c_str(), "%*i.%*i.%*i (%i)", &minimum_build);
LL_INFOS() << LLVersionInfo::getBuild() << LL_ENDL;
LLSD args;
args["CURRENT_VER"] = viewer_version;
args["RECOMMENDED_VER"] = recommended_version;
args["MINIMUM_VER"] = minimum_version;
args["URL"] = data["url"].get<std::string>();
args["TYPE"] = mType == "release" ? "Viewer" : "Alpha";
static LLCachedControl<S32> sLastKnownReleaseBuild("SinguLastKnownReleaseBuild", 0);
static LLCachedControl<S32> sLastKnownAlphaBuild("SinguLastKnownAlphaBuild", 0);
LLCachedControl<S32>& lastver = mType == "release" ? sLastKnownReleaseBuild : sLastKnownAlphaBuild;
if (LLVersionInfo::getBuild() < minimum_build || LLVersionInfo::getBuild() < recommended_build)
{
if (lastver.get() < recommended_build)
{
lastver = recommended_build;
LLUI::sIgnoresGroup->setWarning("UrgentUpdateModal", true);
LLUI::sIgnoresGroup->setWarning("UrgentUpdate", true);
LLUI::sIgnoresGroup->setWarning("RecommendedUpdate", true);
}
std::string notificaiton;
if (LLVersionInfo::getBuild() < minimum_build)
{
if (LLUI::sIgnoresGroup->getWarning("UrgentUpdateModal"))
{
notificaiton = "UrgentUpdateModal";
}
else
{
notificaiton = "UrgentUpdate";
}
}
else if (LLVersionInfo::getBuild() < recommended_build)
{
notificaiton = "RecommendedUpdate";
}
if (!notificaiton.empty())
{
LLNotificationsUtil::add(notificaiton, args, LLSD(), boost::bind(&GetUpdateInfoResponder::onNotifyButtonPress, this, _1, _2, notificaiton, data["url"]));
}
}
} }
protected: protected:
/*virtual*/ AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy(void) const { return getUpdateInfoResponder_timeout; } AIHTTPTimeoutPolicy const& getHTTPTimeoutPolicy() const override { return getUpdateInfoResponder_timeout; }
/*virtual*/ char const* getName(void) const { return "GetUpdateInfoResponder"; } char const* getName() const override { return "GetUpdateInfoResponder"; }
private: private:
std::string mType; std::string mType;
@@ -133,18 +112,15 @@ void check_for_updates()
{ {
std::string type; std::string type;
auto& channel = LLVersionInfo::getChannel(); auto& channel = LLVersionInfo::getChannel();
if (channel == std::string("Singularity")) if (channel == "Singularity")
{ {
type = "release"; type = "release";
} }
else if (channel == std::string("Singularity Test") || channel == std::string("Singularity Alpha") || channel == "Singularity Beta") else if (channel == "Singularity Test" || channel == "Singularity Alpha" || channel == "Singularity Beta")
{ {
type = "alpha"; type = "alpha";
} }
else else return;
{
return;
}
LLHTTPClient::get(url, new GetUpdateInfoResponder(type)); LLHTTPClient::get(url, new GetUpdateInfoResponder(type));
} }
} }