Update Discord RPC

This commit is contained in:
miku-666
2022-06-26 19:09:29 +02:00
parent cf2d689bf4
commit 2dbe03b60b
3 changed files with 23 additions and 73 deletions

View File

@@ -5,52 +5,37 @@ using DiscordRPC.Exceptions;
namespace RichPresenceClient
{
public static class RPC
// https://github.com/BullyWiiPlaza/Minecraft-Wii-U-Mod-Injector/blob/main/Minecraft%20Wii%20U%20Mod%20Injector/Helpers/DiscordRp.cs
class RPC
{
public static DiscordRpcClient Client;
public static DateTime StartUpTime = DateTime.UtcNow;
public static DiscordRpcClient client = null;
public static void Initialize(string ClientID)
public static void Initialize()
{
client = new DiscordRpcClient(ClientID);
try
{
client.Initialize();
}
catch (UninitializedException ex)
{
Console.WriteLine(ex.Message);
}
catch (ObjectDisposedException ex)
{
Console.WriteLine(ex.Message);
}
Client = new DiscordRpcClient("825875166574673940");
Client.Initialize();
}
public static void SetRPC(string details, string state, string imageLarge, string imageLargeText, string imageSmall)
public static void SetPresence(string details, string state)
{
if (client == null) return;
client.SetPresence(new RichPresence()
Client?.SetPresence(new RichPresence()
{
Details = details,
State = state,
Timestamps = new Timestamps() { Start = StartUpTime },
Assets = new Assets()
{
LargeImageKey = imageLarge,
LargeImageText = imageLargeText,
SmallImageKey = imageSmall
LargeImageKey = "pcklgo",
LargeImageText = "PCK Studio",
}
});
}
public static void CloseRPC()
public static void Deinitialize()
{
if (client != null && client.IsInitialized)
{
client.Deinitialize();
}
client.Dispose();
Client?.Dispose();
Client = null;
}
}
}

View File

@@ -324,7 +324,7 @@ namespace PckStudio.Forms
try
{
RPC.SetRPC("Viewing the PCK Center", "Program by PhoenixARC", "pcklogo", "PCK Studio", "pcklogo");
RPC.SetPresence("Viewing the PCK Center", "Program by PhoenixARC");
}
catch
{

View File

@@ -5,8 +5,6 @@ using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO.Compression;
using System.Net;
using System.Diagnostics;
using PckStudio.Properties;
using Ohana3DS_Rebirth.Ohana;
@@ -38,8 +36,6 @@ namespace PckStudio
imageList.Images.Add(Resources.ZUnknown);
pckOpen.AllowDrop = true;
tabControl.SelectTab(0);
RPC.Initialize("825875166574673940");
labelVersion.Text = Application.ProductVersion;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
@@ -872,17 +868,8 @@ namespace PckStudio
private void Form1_Load(object sender, EventArgs e)
{
try
{
RPC.SetRPC("Sitting alone", "Program by PhoenixARC", "pcklgo", "PCK Studio", "pcklgo");
timer1.Start();
timer1.Enabled = true;
}
catch(Exception ex)
{
Console.WriteLine("ERROR WITH RPC");
Console.WriteLine(ex.Message);
}
RPC.Initialize();
RPC.SetPresence("Sitting alone", "Program by PhoenixARC");
#if DEBUG
DBGLabel.Visible = true;
#else
@@ -2787,48 +2774,26 @@ namespace PckStudio
SaveTemplate();
}
private void timer1_Tick(object sender, EventArgs e)
{
//! TODO
//try
//{
// RPC.SetRPC("Developing " + Path.GetFileName(PCKFilePath), "Program by PhoenixARC", "pcklgo", "PCK Studio", "pcklgo");
//}
//catch (Exception ex)
//{
// Console.WriteLine(ex.Message);
//}
}
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
checkSaveState();
RPC.CloseRPC();
RPC.Deinitialize();
}
private void FormMain_Deactivate(object sender, EventArgs e)
{
RPC.CloseRPC();
RPC.Deinitialize();
}
private void FormMain_Activated(object sender, EventArgs e)
{
try
{
RPC.Initialize("825875166574673940");
RPC.SetRPC("Sitting alone", "Program by PhoenixARC", "pcklgo", "PCK Studio", "pcklgo");
timer1.Start();
timer1.Enabled = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
RPC.Initialize();
RPC.SetPresence("Sitting alone", "Program by PhoenixARC");
}
private void forMattNLContributorToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("https://ko-fi.com/mattnl");
}
}
}
}