blob: 15540a1c82d92776373b82bd313b7341537b2cd5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
using DiscordRPC;
using Ryujinx.Common;
using System;
using System.IO;
using System.Linq;
namespace Ryujinx.Configuration
{
static class DiscordIntegrationModule
{
private static DiscordRpcClient DiscordClient;
private static string LargeDescription = "Ryujinx is a Nintendo Switch emulator.";
public static RichPresence DiscordPresence { get; private set; }
public static void Initialize()
{
DiscordPresence = new RichPresence
{
Assets = new Assets
{
LargeImageKey = "ryujinx",
LargeImageText = LargeDescription
},
Details = "Main Menu",
State = "Idling",
Timestamps = new Timestamps(DateTime.UtcNow)
};
ConfigurationState.Instance.EnableDiscordIntegration.Event += Update;
}
private static void Update(object sender, ReactiveEventArgs<bool> e)
{
if (e.OldValue != e.NewValue)
{
// If the integration was active, disable it and unload everything
if (e.OldValue)
{
DiscordClient?.Dispose();
DiscordClient = null;
}
// If we need to activate it and the client isn't active, initialize it
if (e.NewValue && DiscordClient == null)
{
DiscordClient = new DiscordRpcClient("568815339807309834");
DiscordClient.Initialize();
DiscordClient.SetPresence(DiscordPresence);
}
}
}
public static void SwitchToPlayingState(string titleId, string titleName)
{
if (File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RPsupported.dat")).Contains(titleId))
{
DiscordPresence.Assets.LargeImageKey = titleId;
}
string state = titleId;
if (state == null)
{
state = "Ryujinx";
}
else
{
state = state.ToUpper();
}
string details = "Idling";
if (titleName != null)
{
details = $"Playing {titleName}";
}
DiscordPresence.Details = details;
DiscordPresence.State = state;
DiscordPresence.Assets.LargeImageText = titleName;
DiscordPresence.Assets.SmallImageKey = "ryujinx";
DiscordPresence.Assets.SmallImageText = LargeDescription;
DiscordPresence.Timestamps = new Timestamps(DateTime.UtcNow);
DiscordClient?.SetPresence(DiscordPresence);
}
}
}
|