mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-26 19:08:30 +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/gui.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
|
#include <cmath>
|
||||||
#include <discord_rpc.h>
|
#include <discord_rpc.h>
|
||||||
|
|
||||||
SDRPP_MOD_INFO {
|
SDRPP_MOD_INFO {
|
||||||
@ -15,7 +15,10 @@ SDRPP_MOD_INFO {
|
|||||||
/* Max instances */ -1
|
/* Max instances */ -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ready(const DiscordUser *request);
|
||||||
static DiscordRichPresence presence;
|
static DiscordRichPresence presence;
|
||||||
|
static time_t lastUpdate = time(0);
|
||||||
|
static char* freq = new char[24];
|
||||||
|
|
||||||
class PresenceModule : public ModuleManager::Instance {
|
class PresenceModule : public ModuleManager::Instance {
|
||||||
public:
|
public:
|
||||||
@ -23,20 +26,7 @@ public:
|
|||||||
this->name = name;
|
this->name = name;
|
||||||
gui::menu.registerEntry(name, menuHandler, this, this);
|
gui::menu.registerEntry(name, menuHandler, this, this);
|
||||||
|
|
||||||
// Discord initialization
|
startPresence();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PresenceModule() {
|
~PresenceModule() {
|
||||||
@ -44,10 +34,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void enable() {
|
void enable() {
|
||||||
|
startPresence();
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void disable() {
|
void disable() {
|
||||||
|
Discord_ClearPresence();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +56,39 @@ private:
|
|||||||
|
|
||||||
// GUI
|
// GUI
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::Text("Connecting to Discord...");
|
ImGui::Text("SDR++ Rich Presence by Starman0620");
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
|
||||||
|
// Very basic method of implenting a 10s timer
|
||||||
|
if (time(0) - lastUpdate > 10) {
|
||||||
|
updatePresence();
|
||||||
|
lastUpdate = time(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!_this->enabled) { style::endDisabled(); }
|
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;
|
std::string name;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user