From 2dbe03b60b41fdb991e17b9164a65fbb95d7f173 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 26 Jun 2022 19:09:29 +0200 Subject: [PATCH] Update Discord RPC --- .../Classes/Misc/RichPresenceClient.cs | 45 ++++++----------- .../Forms/Utilities/pckCenter.cs | 2 +- MinecraftUSkinEditor/MainForm.cs | 49 +++---------------- 3 files changed, 23 insertions(+), 73 deletions(-) diff --git a/MinecraftUSkinEditor/Classes/Misc/RichPresenceClient.cs b/MinecraftUSkinEditor/Classes/Misc/RichPresenceClient.cs index 12acd26e..4a419fc6 100644 --- a/MinecraftUSkinEditor/Classes/Misc/RichPresenceClient.cs +++ b/MinecraftUSkinEditor/Classes/Misc/RichPresenceClient.cs @@ -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; } - } } \ No newline at end of file diff --git a/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs b/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs index 4f6464b0..142ceccf 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs @@ -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 { diff --git a/MinecraftUSkinEditor/MainForm.cs b/MinecraftUSkinEditor/MainForm.cs index bc83541a..ea4782c7 100644 --- a/MinecraftUSkinEditor/MainForm.cs +++ b/MinecraftUSkinEditor/MainForm.cs @@ -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"); } - } + } } \ No newline at end of file