From dccf087d652ecf98d24927a397c38cc0c9db3ab4 Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Sun, 27 Jul 2025 14:26:47 +0800 Subject: Move Discord-related code to llappviewer.cpp The doFrame is the one called over and over again, so running the Discord callbacks from there shouldn't have one extra function overhead, while running the Discord initialisation is only once so it's much more okay to have the extra function overhead there. --- indra/newview/llstartup.cpp | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) (limited to 'indra/newview/llstartup.cpp') diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 834b99555e..8d010553a0 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -217,12 +217,6 @@ #include "fsfloatersearch.h" -#ifdef LL_DISCORD -#define DISCORDPP_IMPLEMENTATION -#include -static std::shared_ptr gDiscordClient; -#endif - // // exported globals // @@ -758,14 +752,7 @@ bool idle_startup() } #ifdef LL_DISCORD - gDiscordClient = std::make_shared(); - gDiscordClient->SetStatusChangedCallback([](discordpp::Client::Status status, discordpp::Client::Error, int32_t) { - if (status == discordpp::Client::Status::Ready) { - discordpp::Activity activity; - activity.SetType(discordpp::ActivityTypes::Playing); - gDiscordClient->UpdateRichPresence(activity, [](discordpp::ClientResult) {}); - } - }); + LLAppViewer::initDiscordSocial(); #endif // @@ -3447,35 +3434,6 @@ bool LLStartUp::startLLProxy() return proxy_ok; } -#ifdef LL_DISCORD - -void LLStartUp::runDiscordCallbacks() -{ - discordpp::RunCallbacks(); -} - -void LLStartUp::handleDiscordSocial() -{ - static const uint64_t DISCORD_APPLICATION_ID = 1393451183741599796; - discordpp::AuthorizationArgs discordAuthArgs{}; - discordAuthArgs.SetClientId(DISCORD_APPLICATION_ID); - discordAuthArgs.SetScopes(discordpp::Client::GetDefaultPresenceScopes()); - auto discordCodeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier(); - discordAuthArgs.SetCodeChallenge(discordCodeVerifier.Challenge()); - gDiscordClient->Authorize(discordAuthArgs, [discordCodeVerifier](auto result, auto code, auto redirectUri) { - if (result.Successful()) { - gDiscordClient->GetToken(DISCORD_APPLICATION_ID, code, discordCodeVerifier.Verifier(), redirectUri, [](discordpp::ClientResult result, std::string accessToken, std::string, discordpp::AuthorizationTokenType, int32_t, std::string) { - gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [](discordpp::ClientResult result) { - if (result.Successful()) - gDiscordClient->Connect(); - }); - }); - } - }); -} - -#endif - bool login_alert_done(const LLSD& notification, const LLSD& response) { LLPanelLogin::giveFocus(); -- cgit v1.2.3 From 306eb28d78c9aa83669307dc49daacb94f8c8742 Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Mon, 28 Jul 2025 15:13:36 +0800 Subject: Location for Discord Rich Presence Activity State I was going to use LLAgentUI::buildLocationString but there's no location format that shows only region and coords without having to have the parcel name empty, so I copied buildLocationString implementation in the case of LOCATION_FORMAT_NO_MATURITY but when the parcel name is empty. I had to make updateDiscordActivity check agent's ID and the existence of agent avatar pointer first before trying to set Activity Details or State, cause I like the "Show location" button be checkable not only after online when both the ID & pointer will have existed. I think this way is simpler than programmatically enabling the "Show location" button after the user is logged in. I put a trigger to Activity update somewhere after the user is logged in for now, not yet after a TP. The elapsed time gets reset whenever Activity is updated for now, but I'll try to make elapsed time extended instead. No Party for now, because I couldn't find a way to make a Party shown without showing its CurrentSize (I could still get away not showing its MaxSize by setting it to 0), so the State (location) is shown above the elapsed time, not on the right of it. I'll try to figure out to get some representative numbers for its CurrentSize & MaxSize next. Also no privacy on hiding the username for now, until the UI is ready. --- indra/newview/llstartup.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/newview/llstartup.cpp') diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 8d010553a0..2f40beb9c4 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -2082,6 +2082,9 @@ bool idle_startup() // We have a region, and just did a big inventory download. // We can estimate the user's connection speed, and set their // max bandwidth accordingly. JC +#ifdef LL_DISCORD + LLAppViewer::updateDiscordActivity(); +#endif if (gSavedSettings.getBOOL("FirstLoginThisInstall")) { // This is actually a pessimistic computation, because TCP may not have enough -- cgit v1.2.3 From 94f51d5a4b16d76e46e53802cc188da8c9eb795b Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Mon, 28 Jul 2025 16:33:28 +0800 Subject: Show display name too on Discord Rich Presence Avatar name cache can be used right away upon login now after I moved the update call to the end of PRECACHE section in llstartup. --- indra/newview/llstartup.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/llstartup.cpp') diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 2f40beb9c4..dfad169813 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -2082,9 +2082,6 @@ bool idle_startup() // We have a region, and just did a big inventory download. // We can estimate the user's connection speed, and set their // max bandwidth accordingly. JC -#ifdef LL_DISCORD - LLAppViewer::updateDiscordActivity(); -#endif if (gSavedSettings.getBOOL("FirstLoginThisInstall")) { // This is actually a pessimistic computation, because TCP may not have enough @@ -2330,6 +2327,10 @@ bool idle_startup() do_startup_frame(); } +#ifdef LL_DISCORD + LLAppViewer::updateDiscordActivity(); +#endif + return true; } -- cgit v1.2.3