Files
i2p 773d05f8f1
Pulsar .NET 9.0 Windows Release / build (push) Waiting to run
Mirror to Codeberg and Gitea / mirror (push) Waiting to run
initial commit
2026-08-27 10:57:58 -06:00

47 lines
1.3 KiB
C#

using Pulsar.Server.Models;
using System.Windows.Forms;
namespace Pulsar.Server.DiscordRPC
{
internal class DiscordRPCManager
{
private static DiscordRPC _rpcInstance;
public static void Initialize(Form form)
{
if (_rpcInstance == null)
{
_rpcInstance = new DiscordRPC(form);
}
ApplyDiscordRPC(form);
}
public static void ApplyDiscordRPC(Form form)
{
bool isDiscordRPCChecked = Settings.DiscordRPC;
if (_rpcInstance == null || _rpcInstance.Enabled != isDiscordRPCChecked)
{
if (_rpcInstance != null)
{
_rpcInstance.Enabled = false; // Explicitly disable the old instance
_rpcInstance = null; // Clear reference for garbage collection
}
_rpcInstance = new DiscordRPC(form);
_rpcInstance.Enabled = isDiscordRPCChecked;
}
else
{
_rpcInstance.Enabled = isDiscordRPCChecked; // Enforce the state
}
}
public static void Shutdown()
{
if (_rpcInstance != null)
{
_rpcInstance.Enabled = false;
_rpcInstance = null;
}
}
}
}