diff --git a/include/CustomPresense.hpp b/include/CustomPresense.hpp index 78ac418..958f6f5 100644 --- a/include/CustomPresense.hpp +++ b/include/CustomPresense.hpp @@ -29,7 +29,8 @@ namespace gdrpc { std::string smallImageText = "", bool useTime = false, bool shouldResetTime = false, - std::string largeImage = "" + std::string largeImage = "", + int timeOffset = 0 ); void registerMod(std::string modID) { mods.insert(modID); diff --git a/mod.json b/mod.json index 4831135..a6d14e8 100644 --- a/mod.json +++ b/mod.json @@ -39,6 +39,12 @@ "description": "Displays the amount of time you've spent working on the level in total across all sessions", "default": true, "type": "bool" + }, + "idling": { + "name": "Show idle status", + "description": "Will change your status to idle when GD is unfocused", + "type": "bool", + "default": true } }, "repository": "https://github.com/TechStudent10/DiscordRPC", diff --git a/src/CustomPresense.cpp b/src/CustomPresense.cpp index ebc30b1..0538cfb 100644 --- a/src/CustomPresense.cpp +++ b/src/CustomPresense.cpp @@ -1,5 +1,5 @@ #include "../include/CustomPresense.hpp" -#include "Geode/loader/Log.hpp" +#include "Geode/modify/AppDelegate.hpp" #include // #include @@ -8,6 +8,23 @@ using namespace geode::prelude; static const char* APPLICATION_ID = "1178492879627366472"; time_t currentTime = time(0); +bool isIdling = false; + +class $modify(AppDelegate) { + void applicationDidEnterBackground() { + AppDelegate::applicationDidEnterBackground(); + isIdling = true; + log::info("idle time"); + gdrpc::GDRPC::getSharedInstance()->updateDiscordRP("techstudent10.discord_rich_presence", "idling"); + } + + void applicationWillEnterForeground() { + AppDelegate::applicationWillEnterForeground(); + isIdling = false; + } +}; + + static void handleDiscordReady(const DiscordUser* user) { log::info("Connected to Discord RPC"); log::info("Username: {}", user->username); @@ -44,7 +61,8 @@ void gdrpc::GDRPC::updateDiscordRP( std::string smallImageText, bool useTime, bool shouldResetTime, - std::string largeImage + std::string largeImage, + int timeOffset ) { if (!(mods.contains(modID))) { log::error("Mod with ID \"{}\" is not registered. Please register your mod with DiscordRPC before utilizing it (gdrpc::GDRPC::getSharedInstance()->registerMod(\"{}\")).", modID, modID); @@ -54,25 +72,29 @@ void gdrpc::GDRPC::updateDiscordRP( auto shouldShowSensitive = Mod::get()->getSettingValue("private-info"); auto shouldShowTime = Mod::get()->getSettingValue("show-time"); DiscordRichPresence discordPresence{}; - discordPresence.details = details.c_str(); - discordPresence.state = state.c_str(); if (largeImage == "") { discordPresence.largeImageKey = "gd_large"; } else { discordPresence.largeImageKey = largeImage.c_str(); } - if (useTime && shouldShowTime) { - if (shouldResetTime) currentTime = time(0); - discordPresence.startTimestamp = currentTime; - } - if (shouldShowSensitive) { - discordPresence.largeImageText = fmt::format("{} (playing on {})", gm->m_playerName, GEODE_PLATFORM_NAME).c_str(); + if (isIdling) { + discordPresence.details = "Idling"; + if (shouldShowSensitive) { + discordPresence.largeImageText = fmt::format("{} (playing on {})", gm->m_playerName, GEODE_PLATFORM_NAME).c_str(); + } else { + discordPresence.largeImageText = fmt::format("Playing Geometry Dash on {}", GEODE_PLATFORM_NAME).c_str(); + } } else { - discordPresence.largeImageText = fmt::format("Playing Geometry Dash on {}", GEODE_PLATFORM_NAME).c_str(); - } - if (smallImageKey != "") { - discordPresence.smallImageKey = smallImageKey.c_str(); - discordPresence.smallImageText = smallImageText.c_str(); + discordPresence.details = details.c_str(); + discordPresence.state = state.c_str(); + if (useTime && shouldShowTime) { + if (shouldResetTime) currentTime = time(0); + discordPresence.startTimestamp = currentTime - timeOffset; + } + if (smallImageKey != "") { + discordPresence.smallImageKey = smallImageKey.c_str(); + discordPresence.smallImageText = smallImageText.c_str(); + } } discordPresence.instance = 0; Discord_UpdatePresence(&discordPresence); diff --git a/src/main.cpp b/src/main.cpp index 476704e..c590960 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -220,6 +220,7 @@ class $modify(MenuLayer) { void onAchievements(CCObject* sender) { auto shouldBeFunny = Mod::get()->getSettingValue("funny-mode"); rpc->updateDiscordRP(MODID, "Browsing Menus", shouldBeFunny ? "Wishing for the Creator Points UFO" : "Achievements"); + MenuLayer::onAchievements(sender); // NetheriteMiner didn't test this one :() } }; @@ -425,7 +426,17 @@ class $modify(MyLevelEditorLayer, LevelEditorLayer) { if (showTotalTime) { totalTime = " (worked on for " + workingTime(m_level->m_workingTime) + ")"; } - rpc->updateDiscordRP(MODID, details, std::to_string(objectCount) + fmt::format(" objects{}", totalTime), "editor", "Editing a level", true); + rpc->updateDiscordRP( + MODID, + details, + std::to_string(objectCount) + " objects{}", + "editor", + "Editing a level", + true, + false, + "", + m_level->m_workingTime + ); } };