Skip to content

Commit

Permalink
Add Discord Enable option to Settings -> Privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed May 29, 2018
1 parent 81ce02c commit ddbc0d5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
54 changes: 42 additions & 12 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1744,8 +1744,8 @@ void command_playlist_update_write(
**/
bool command_event(enum event_command cmd, void *data)
{
settings_t *settings = config_get_ptr();
bool boolean = false;
static bool discord_inited = false;
bool boolean = false;

switch (cmd)
{
Expand Down Expand Up @@ -1942,25 +1942,26 @@ bool command_event(enum event_command cmd, void *data)
case CMD_EVENT_REINIT_FROM_TOGGLE:
retroarch_unset_forced_fullscreen();
case CMD_EVENT_REINIT:
video_driver_reinit();
{
video_driver_reinit();
{
const input_driver_t *input_drv = input_get_ptr();
void *input_data = input_get_data();
/* Poll input to avoid possibly stale data to corrupt things. */
if (input_drv && input_drv->poll)
input_drv->poll(input_data);
}
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, (void*)(intptr_t)-1);
const input_driver_t *input_drv = input_get_ptr();
void *input_data = input_get_data();
/* Poll input to avoid possibly stale data to corrupt things. */
if (input_drv && input_drv->poll)
input_drv->poll(input_data);
}
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, (void*)(intptr_t)-1);
#ifdef HAVE_MENU
{
settings_t *settings = config_get_ptr();
menu_display_set_framebuffer_dirty_flag();
if (settings->bools.video_fullscreen)
video_driver_hide_mouse();

if (menu_driver_is_alive())
command_event(CMD_EVENT_VIDEO_SET_BLOCKING_STATE, NULL);
#endif
}
#endif
break;
case CMD_EVENT_CHEATS_DEINIT:
cheat_manager_state_free();
Expand Down Expand Up @@ -2826,6 +2827,35 @@ TODO: Add a setting for these tweaks */
libui_main();
#endif
break;
case CMD_EVENT_DISCORD_INIT:
{
settings_t *settings = config_get_ptr();

if (!settings->bools.discord_enable)
return false;
if (discord_inited)
return true;

discord_init();
discord_inited = true;
}
break;
case CMD_EVENT_DISCORD_DEINIT:
if (!discord_inited)
return false;

discord_shutdown();
discord_inited = false;
break;
case CMD_EVENT_DISCORD_UPDATE:
if (!data || !discord_inited)
return false;

{
discord_userdata_t *userdata = (discord_userdata_t*)data;
discord_update(userdata->status);
}
break;
case CMD_EVENT_NONE:
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions command.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ enum event_command
CMD_EVENT_DISABLE_OVERRIDES,
CMD_EVENT_RESTORE_REMAPS,
CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET,
CMD_EVENT_DISCORD_INIT,
CMD_EVENT_DISCORD_DEINIT,
CMD_EVENT_DISCORD_UPDATE,
CMD_EVENT_LIBUI_TEST
};

Expand Down
5 changes: 5 additions & 0 deletions discord/discord.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ enum discord_presence
DISCORD_PRESENCE_NETPLAY_CLIENT
};

typedef struct discord_userdata
{
enum discord_presence status;
} discord_userdata_t;

void discord_init(void);

void discord_shutdown(void);
Expand Down
23 changes: 15 additions & 8 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,13 +1382,16 @@ bool retroarch_main_init(int argc, char *argv[])
rarch_is_inited = true;

#ifdef HAVE_DISCORD
{
discord_init();
discord_is_inited = true;
}
if (command_event(CMD_EVENT_DISCORD_INIT, NULL))
discord_is_inited = true;

if (discord_is_inited)
discord_update(DISCORD_PRESENCE_MENU);
{
discord_userdata_t userdata;
userdata.status = DISCORD_PRESENCE_MENU;

command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
}
#endif

if (rarch_first_start)
Expand Down Expand Up @@ -2339,8 +2342,7 @@ bool retroarch_main_quit(void)
rarch_menu_running_finished();

#ifdef HAVE_DISCORD
if (discord_is_inited)
discord_shutdown();
command_event(CMD_EVENT_DISCORD_DEINIT, NULL);
discord_is_inited = false;
#endif

Expand Down Expand Up @@ -3350,7 +3352,12 @@ int runloop_iterate(unsigned *sleep_ms)

#ifdef HAVE_DISCORD
if (discord_is_inited)
discord_update(DISCORD_PRESENCE_GAME);
{
discord_userdata_t userdata;
userdata.status = DISCORD_PRESENCE_GAME;

command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
}
#endif

for (i = 0; i < max_users; i++)
Expand Down

0 comments on commit ddbc0d5

Please sign in to comment.