Added basic RPC wrapper into project
This commit is contained in:
parent
fc27243c1e
commit
8aa1296887
59
Discord Media Loader.Application/Classes/RPC/DiscordRpc.cs
Normal file
59
Discord Media Loader.Application/Classes/RPC/DiscordRpc.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DML.Application.Classes.RPC
|
||||
{
|
||||
// https://github.com/discordapp/discord-rpc/blob/master/examples/button-clicker/Assets/DiscordRpc.cs
|
||||
// Give that man a cookie ^.^
|
||||
|
||||
public class DiscordRpc
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ReadyCallback();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void DisconnectedCallback(int errorCode, string message);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ErrorCallback(int errorCode, string message);
|
||||
|
||||
public struct EventHandlers
|
||||
{
|
||||
public ReadyCallback readyCallback;
|
||||
public DisconnectedCallback disconnectedCallback;
|
||||
public ErrorCallback errorCallback;
|
||||
}
|
||||
|
||||
// Values explanation and example: https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
||||
[System.Serializable]
|
||||
public struct RichPresence
|
||||
{
|
||||
public string state; /* max 128 bytes */
|
||||
public string details; /* max 128 bytes */
|
||||
public long startTimestamp;
|
||||
public long endTimestamp;
|
||||
public string largeImageKey; /* max 32 bytes */
|
||||
public string largeImageText; /* max 128 bytes */
|
||||
public string smallImageKey; /* max 32 bytes */
|
||||
public string smallImageText; /* max 128 bytes */
|
||||
public string partyId; /* max 128 bytes */
|
||||
public int partySize;
|
||||
public int partyMax;
|
||||
public string matchSecret; /* max 128 bytes */
|
||||
public string joinSecret; /* max 128 bytes */
|
||||
public string spectateSecret; /* max 128 bytes */
|
||||
public bool instance;
|
||||
}
|
||||
|
||||
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
|
||||
|
||||
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_UpdatePresence", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void UpdatePresence(ref RichPresence presence);
|
||||
|
||||
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_RunCallbacks", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void RunCallbacks();
|
||||
|
||||
[DllImport(RpcWrapper.Dll, EntryPoint = "Discord_Shutdown", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Shutdown();
|
||||
}
|
||||
}
|
29
Discord Media Loader.Application/Classes/RPC/RpcWrapper.cs
Normal file
29
Discord Media Loader.Application/Classes/RPC/RpcWrapper.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DML.Application.Classes.RPC
|
||||
{
|
||||
public class RpcWrapper
|
||||
{
|
||||
public const string Dll = "discord-rpc-win32";
|
||||
|
||||
public RpcWrapper()
|
||||
{
|
||||
if (!File.Exists(Dll + ".dll"))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Missing " + Dll + ".dll\n\n" +
|
||||
"Grab it from the release on GitHub or from the DiscordRpcDemo/lib/ folder in the repo then put it alongside DiscordRpcDemo.exe.\n\n" +
|
||||
"https://github.com/nostrenz/cshap-discord-rpc-demo"
|
||||
);
|
||||
|
||||
System.Windows.Forms.Application.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -161,6 +161,8 @@
|
|||
<Compile Include="Classes\Core.cs" />
|
||||
<Compile Include="Classes\Job.cs" />
|
||||
<Compile Include="Classes\JobScheduler.cs" />
|
||||
<Compile Include="Classes\RPC\DiscordRpc.cs" />
|
||||
<Compile Include="Classes\RPC\RpcWrapper.cs" />
|
||||
<Compile Include="Dialogs\LoginDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Reference in a new issue