2019-12-21 12:52:31 -07:00
|
|
|
|
using DiscordRPC;
|
|
|
|
|
using Ryujinx.Common;
|
2022-05-15 05:30:15 -06:00
|
|
|
|
using Ryujinx.Ui.Common.Configuration;
|
2019-12-21 12:52:31 -07:00
|
|
|
|
|
2022-05-15 05:30:15 -06:00
|
|
|
|
namespace Ryujinx.Ui.Common
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2022-05-15 05:30:15 -06:00
|
|
|
|
public static class DiscordIntegrationModule
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
private const string Description = "A simple, experimental Nintendo Switch emulator.";
|
|
|
|
|
private const string CliendId = "568815339807309834";
|
2019-12-21 12:52:31 -07:00
|
|
|
|
|
2021-05-02 14:17:34 -06:00
|
|
|
|
private static DiscordRpcClient _discordClient;
|
|
|
|
|
private static RichPresence _discordPresenceMain;
|
2019-12-21 12:52:31 -07:00
|
|
|
|
|
|
|
|
|
public static void Initialize()
|
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
_discordPresenceMain = new RichPresence
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2021-01-08 01:14:13 -07:00
|
|
|
|
Assets = new Assets
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
|
|
|
|
LargeImageKey = "ryujinx",
|
2021-05-02 14:17:34 -06:00
|
|
|
|
LargeImageText = Description
|
2019-12-21 12:52:31 -07:00
|
|
|
|
},
|
|
|
|
|
Details = "Main Menu",
|
|
|
|
|
State = "Idling",
|
2021-05-02 14:17:34 -06:00
|
|
|
|
Timestamps = Timestamps.Now,
|
|
|
|
|
Buttons = new Button[]
|
|
|
|
|
{
|
|
|
|
|
new Button()
|
|
|
|
|
{
|
|
|
|
|
Label = "Website",
|
|
|
|
|
Url = "https://ryujinx.org/"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-21 12:52:31 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ConfigurationState.Instance.EnableDiscordIntegration.Event += Update;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:17:34 -06:00
|
|
|
|
private static void Update(object sender, ReactiveEventArgs<bool> evnt)
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
if (evnt.OldValue != evnt.NewValue)
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
|
|
|
|
// If the integration was active, disable it and unload everything
|
2021-05-02 14:17:34 -06:00
|
|
|
|
if (evnt.OldValue)
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2020-03-28 21:25:54 -06:00
|
|
|
|
_discordClient?.Dispose();
|
2019-12-21 12:52:31 -07:00
|
|
|
|
|
2020-03-28 21:25:54 -06:00
|
|
|
|
_discordClient = null;
|
2019-12-21 12:52:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we need to activate it and the client isn't active, initialize it
|
2021-05-02 14:17:34 -06:00
|
|
|
|
if (evnt.NewValue && _discordClient == null)
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
_discordClient = new DiscordRpcClient(CliendId);
|
2019-12-21 12:52:31 -07:00
|
|
|
|
|
2020-03-28 21:25:54 -06:00
|
|
|
|
_discordClient.Initialize();
|
2021-05-02 14:17:34 -06:00
|
|
|
|
_discordClient.SetPresence(_discordPresenceMain);
|
2019-12-21 12:52:31 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void SwitchToPlayingState(string titleId, string titleName)
|
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
_discordClient?.SetPresence(new RichPresence
|
2019-12-21 12:52:31 -07:00
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
Assets = new Assets
|
|
|
|
|
{
|
|
|
|
|
LargeImageKey = "game",
|
|
|
|
|
LargeImageText = titleName,
|
|
|
|
|
SmallImageKey = "ryujinx",
|
|
|
|
|
SmallImageText = Description,
|
|
|
|
|
},
|
|
|
|
|
Details = $"Playing {titleName}",
|
|
|
|
|
State = (titleId == "0000000000000000") ? "Homebrew" : titleId.ToUpper(),
|
|
|
|
|
Timestamps = Timestamps.Now,
|
|
|
|
|
Buttons = new Button[]
|
|
|
|
|
{
|
|
|
|
|
new Button()
|
|
|
|
|
{
|
|
|
|
|
Label = "Website",
|
|
|
|
|
Url = "https://ryujinx.org/"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-12-21 12:52:31 -07:00
|
|
|
|
}
|
2020-01-21 15:23:11 -07:00
|
|
|
|
|
|
|
|
|
public static void SwitchToMainMenu()
|
|
|
|
|
{
|
2021-05-02 14:17:34 -06:00
|
|
|
|
_discordClient?.SetPresence(_discordPresenceMain);
|
2020-01-21 15:23:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Exit()
|
|
|
|
|
{
|
2020-03-28 21:25:54 -06:00
|
|
|
|
_discordClient?.Dispose();
|
2020-01-21 15:23:11 -07:00
|
|
|
|
}
|
2019-12-21 12:52:31 -07:00
|
|
|
|
}
|
2021-01-08 01:14:13 -07:00
|
|
|
|
}
|