mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-25 10:28:28 +01:00
Added frequency display to presence
This commit is contained in:
parent
6420553ae9
commit
70c7060eaf
@ -4,7 +4,7 @@
|
||||
#include <gui/gui.h>
|
||||
#include <gui/style.h>
|
||||
#include <core.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <discord_rpc.h>
|
||||
|
||||
SDRPP_MOD_INFO {
|
||||
@ -15,7 +15,10 @@ SDRPP_MOD_INFO {
|
||||
/* Max instances */ -1
|
||||
};
|
||||
|
||||
void ready(const DiscordUser *request);
|
||||
static DiscordRichPresence presence;
|
||||
static time_t lastUpdate = time(0);
|
||||
static char* freq = new char[24];
|
||||
|
||||
class PresenceModule : public ModuleManager::Instance {
|
||||
public:
|
||||
@ -23,20 +26,7 @@ public:
|
||||
this->name = name;
|
||||
gui::menu.registerEntry(name, menuHandler, this, this);
|
||||
|
||||
// Discord initialization
|
||||
DiscordEventHandlers handlers;
|
||||
memset(&handlers, 0, sizeof(handlers));
|
||||
memset(&presence, 0, sizeof(presence));
|
||||
Discord_Initialize("833485588954742864", &handlers, 1, "");
|
||||
|
||||
// Set the first presence
|
||||
presence.state = "Loading...";
|
||||
presence.details = "Initializing rich presence...";
|
||||
presence.partySize = 1;
|
||||
presence.partyMax = 1;
|
||||
presence.startTimestamp = time(0);
|
||||
presence.largeImageKey = "image_large";
|
||||
Discord_UpdatePresence(&presence);
|
||||
startPresence();
|
||||
}
|
||||
|
||||
~PresenceModule() {
|
||||
@ -44,10 +34,12 @@ public:
|
||||
}
|
||||
|
||||
void enable() {
|
||||
startPresence();
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
Discord_ClearPresence();
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
@ -64,12 +56,39 @@ private:
|
||||
|
||||
// GUI
|
||||
ImGui::BeginGroup();
|
||||
ImGui::Text("Connecting to Discord...");
|
||||
ImGui::Text("SDR++ Rich Presence by Starman0620");
|
||||
ImGui::EndGroup();
|
||||
|
||||
// Very basic method of implenting a 10s timer
|
||||
if (time(0) - lastUpdate > 10) {
|
||||
updatePresence();
|
||||
lastUpdate = time(0);
|
||||
}
|
||||
|
||||
if (!_this->enabled) { style::endDisabled(); }
|
||||
}
|
||||
|
||||
static void updatePresence() {
|
||||
presence.details = "Listening";
|
||||
sprintf(freq, "%.2fMHz", gui::waterfall.getCenterFrequency()/1000000, 3);
|
||||
presence.state = freq;
|
||||
Discord_UpdatePresence(&presence);
|
||||
}
|
||||
|
||||
static void startPresence() {
|
||||
// Discord initialization
|
||||
DiscordEventHandlers handlers;
|
||||
memset(&handlers, 0, sizeof(handlers));
|
||||
memset(&presence, 0, sizeof(presence));
|
||||
Discord_Initialize("833485588954742864", &handlers, 1, "");
|
||||
|
||||
// Set the first presence
|
||||
presence.details = "Initializing rich presence...";
|
||||
presence.startTimestamp = time(0);
|
||||
presence.largeImageKey = "image_large";
|
||||
Discord_UpdatePresence(&presence);
|
||||
}
|
||||
|
||||
std::string name;
|
||||
bool enabled = true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user