mirror of
https://github.com/Goldenkrew3000/OSSP_OpenSource.git
synced 2025-12-18 15:54:44 +10:00
Added error handling to discord RPC and made user agent consistent
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* Note: This provides server auth creds (encoded) directly to Discord, could use Spotify's API instead??
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -57,7 +58,7 @@ static void handleDiscordError(int errcode, const char* message)
|
||||
printf("\nDiscord: error (%d: %s)\n", errcode, message);
|
||||
}
|
||||
|
||||
void discordrpc_init() {
|
||||
int discordrpc_init() {
|
||||
printf("[DiscordRPC] Initializing...\n");
|
||||
DiscordEventHandlers handlers;
|
||||
memset(&handlers, 0, sizeof(handlers));
|
||||
@@ -67,8 +68,12 @@ void discordrpc_init() {
|
||||
Discord_Initialize(discordrpc_appid, &handlers, 1, NULL);
|
||||
|
||||
// Fetch OS String for RPC (Heap-allocated)
|
||||
// TODO: Check if failed
|
||||
discordrpc_osString = discordrpc_getOS();
|
||||
if (discordrpc_osString == NULL) {
|
||||
logger_log_error(__func__, "asprintf() or strdup() failed.");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void discordrpc_update(discordrpc_data** discordrpc_struct) {
|
||||
@@ -104,8 +109,6 @@ void discordrpc_update(discordrpc_data** discordrpc_struct) {
|
||||
char* discordrpc_getOS() {
|
||||
#if defined(__linux__)
|
||||
// NOTE: Could have made a sysctl function, but this is literally only done here, not worth it
|
||||
// TODO: This is ONLY linux compatible at this point
|
||||
|
||||
FILE* fp_ostype = fopen("/proc/sys/kernel/ostype", "r");
|
||||
char buf_ostype[16];
|
||||
if (!fp_ostype) {
|
||||
@@ -211,6 +214,8 @@ char* discordrpc_getOS() {
|
||||
}
|
||||
return osString;
|
||||
#else
|
||||
// NOTE: This is not a critical error, just let the user know
|
||||
logger_log_error(__func__, "Could not fetch OS details.");
|
||||
return strdup("on Unknown");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ typedef struct {
|
||||
|
||||
void discordrpc_struct_init(discordrpc_data** discordrpc_struct);
|
||||
void discordrpc_struct_deinit(discordrpc_data** discordrpc_struct);
|
||||
void discordrpc_init();
|
||||
int discordrpc_init();
|
||||
void discordrpc_update(discordrpc_data** discordrpc_struct);
|
||||
char* discordrpc_getOS();
|
||||
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
#include "player/player.h"
|
||||
#include "discordrpc.h"
|
||||
|
||||
static int rc = 0;
|
||||
configHandler_config_t* configObj = NULL;
|
||||
int checkConfigFile();
|
||||
int validateConnection();
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int rc = 0;
|
||||
|
||||
// Read config file
|
||||
rc = configHandler_Read(&configObj);
|
||||
if (rc != 0) {
|
||||
@@ -61,7 +60,10 @@ int main(int argc, char** argv) {
|
||||
discordrpc_data* discordrpc = NULL;
|
||||
discordrpc_struct_init(&discordrpc);
|
||||
discordrpc->state = DISCORDRPC_STATE_IDLE;
|
||||
discordrpc_init();
|
||||
rc = discordrpc_init();
|
||||
if (rc != 0) {
|
||||
return 1;
|
||||
}
|
||||
discordrpc_update(&discordrpc);
|
||||
discordrpc_struct_deinit(&discordrpc);
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ guint bus_watch_id;
|
||||
GMainLoop* loop;
|
||||
bool isPlaying = false;
|
||||
|
||||
static void gst_playbin3_sourcesetup_callback(GstElement* playbin, GstElement* source, gpointer udata) {
|
||||
g_object_set(G_OBJECT(source), "user-agent", "OSSP/1.0 (avery@hojuix.org)", NULL);
|
||||
}
|
||||
|
||||
static gboolean gst_bus_call(GstBus* bus, GstMessage* message, gpointer data) {
|
||||
GMainLoop* loop = (GMainLoop*)data;
|
||||
|
||||
@@ -148,7 +152,6 @@ void* OSSPlayer_ThrdInit(void*) {
|
||||
discordrpc_update(&discordrpc);
|
||||
discordrpc_struct_deinit(&discordrpc);
|
||||
|
||||
printf("%s\n", coverart_url->formedUrl);
|
||||
opensubsonic_httpClient_URL_cleanup(&coverart_url);
|
||||
|
||||
opensubsonic_getSong_struct_free(&songStruct);
|
||||
@@ -235,13 +238,14 @@ int OSSPlayer_GstInit() {
|
||||
gst_object_unref(sink_pad);
|
||||
gst_object_unref(src_pad);
|
||||
|
||||
// TEST - Setup playbin
|
||||
// Setup playbin3 (Configure audio plugins and set user agent)
|
||||
g_object_set(playbin, "audio-filter", filter_bin, NULL);
|
||||
g_signal_connect (playbin, "source-setup", G_CALLBACK(gst_playbin3_sourcesetup_callback), NULL);
|
||||
|
||||
// 000
|
||||
// Add playbin3 to the pipeline
|
||||
gst_bin_add(GST_BIN(pipeline), playbin);
|
||||
|
||||
// Initialize in-volume
|
||||
// Initialize in-volume (Volume before the audio reaches the plugins)
|
||||
g_object_set(in_volume, "volume", 0.175, NULL);
|
||||
|
||||
// Initialize equalizer
|
||||
@@ -309,6 +313,13 @@ int OSSPlayer_GstInit() {
|
||||
|
||||
g_object_set(equalizer, "enabled", true, NULL);
|
||||
}
|
||||
|
||||
// Initialize pitch
|
||||
|
||||
|
||||
|
||||
|
||||
// Initialize reverb
|
||||
}
|
||||
|
||||
int OSSPlayer_GstDeInit() {
|
||||
|
||||
Reference in New Issue
Block a user