Skip to content

Conversation

@Koi-3088
Copy link
Member

Allows setting rich presence for the user running ComputerControl. Displays program name, status, elapsed time.

Enabled by default, can be toggled off. Requires a Discord client to be running on user's computer.

Includes debug and release .lib and binary files for Windows, Linux, MacOS. Linux and MacOS building currently not implemented.

…nabled by default, includes option to disable.
@Koi-3088 Koi-3088 requested a review from Mysticial August 30, 2025 00:10
@Koi-3088
Copy link
Member Author

I guess it would also close this

private:
std::shared_ptr<discordpp::Client> m_client = nullptr;
std::atomic<bool> m_running;
const uint64_t m_app_id = 1406867596585865326;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally hard-coded? Where does it come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_app_id is intentionally hardcoded. It's the private Discord application the SDK gets art assets from.

- Use global strings for program name, make the latest GitHub release URL a private member.
- Add a new, permanent Discord invite URL for SocialSDK.
- Fix erroneous spaces before angle brackets in a couple of places.
log(message, "Internal", severity);
}, m_log_level);

std::thread(&DiscordSocial::thread_loop, this).detach();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never use detach since it's impossible to clean up due to having an unbounded lifetime. If you destruct this class, and the thread is still running, you dangle all the fields that it references.

Store the thread into the class. Then in the destructor after you signaled the thread to exit, join the thread.

m_thread = std::thread(&DiscordSocial::thread_loop, this);

In destructor:

m_running.store(false, std::memory_order_release);
m_thread.join();

//  Now it's safe to destroy the client.
if (m_client) m_client.reset();

m_client = std::make_shared<Client>();
if (!m_client){
log("Failed to initialize DiscordSocialSDK.", "run()", LoggingSeverity::Error);
m_client.reset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't exception safe. If an exception is thrown further down, m_client remains initialized which is probably not what you intended.

Make the client first and store into a local variable:

std::shared_ptrClient> client = std::make_shared<Client>();

Then at the the end of the function (before you start the thread), move it into m_client.

It's possible for the thread creation itself to throw. So to be truly correct, you'll need something like this:

m_client = std::move(client);
try{
    std::thread(&DiscordSocial::thread_loop, this).detach();
}catch (...){
    m_client.reset();
    throw;
}

But see my other comment about not using detach().


RunCallbacks();
update_rich_presence();
std::this_thread::sleep_for(std::chrono::seconds(1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this every second? Is it possible to diff to see if anything changed. And only update if something changed?

Ideally CC itself should push these changes out, but now is not the time to re-architect that part so this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiscordSDK requires some sort of a main loop that calls RunCallbacks() regularly for internal logging and other set callbacks. 1 second with logging only set to errors won't spam, but a loop running on status change (which is possible) would be more invasive (likely require OAuth2 or additional scopes: currently there are none).

If we want CC to dictate rich presence update, that would require a direct program state reference (or something thereof). Not sure how feasible when initialized from Main.cpp.

@Koi-3088 Koi-3088 merged commit 338935b into PokemonAutomation:main Aug 30, 2025
5 checks passed
@Koi-3088 Koi-3088 deleted the social_sdk branch August 30, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants