Renamed rich presence module

This commit is contained in:
Starman0620
2021-04-20 14:34:54 -04:00
parent f23faa72ec
commit 18eb29fabd
3 changed files with 8 additions and 10 deletions

View File

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.13)
project(discord-integration)
if (MSVC)
set(CMAKE_CXX_FLAGS "-O2 /std:c++17 /EHsc")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -Wno-unused-command-line-argument -undefined dynamic_lookup -fPIC")
else ()
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fPIC")
endif ()
file(GLOB SRC "src/*.cpp")
include_directories("src/")
add_library(integration SHARED ${SRC})
target_link_libraries(integration PUBLIC sdrpp_core discord-rpc)
set_target_properties(integration PROPERTIES PREFIX "")
# Install directives
install(TARGETS integration DESTINATION lib/sdrpp/plugins)

View File

@ -0,0 +1,110 @@
#include <imgui.h>
#include <spdlog/spdlog.h>
#include <module.h>
#include <gui/gui.h>
#include <gui/style.h>
#include <core.h>
#include <cmath>
#include <discord_rpc.h>
SDRPP_MOD_INFO {
/* Name: */ "discord",
/* Description: */ "Discord Rich Presence module for SDR++",
/* Author: */ "Starman0620",
/* Version: */ 0, 0, 1,
/* 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:
PresenceModule(std::string name) {
this->name = name;
gui::menu.registerEntry(name, menuHandler, this, this);
startPresence();
}
~PresenceModule() {
}
void enable() {
startPresence();
enabled = true;
}
void disable() {
Discord_ClearPresence();
enabled = false;
}
bool isEnabled() {
return enabled;
}
private:
static void menuHandler(void* ctx) {
PresenceModule* _this = (PresenceModule*)ctx;
if (!_this->enabled) { style::beginDisabled(); }
float menuWidth = ImGui::GetContentRegionAvailWidth();
// GUI
ImGui::BeginGroup();
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;
};
MOD_EXPORT void _INIT_() {
}
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
return new PresenceModule(name);
}
MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
delete (PresenceModule*)instance;
}
MOD_EXPORT void _END_() {
}