Fix crash after entering manage content
This commit is contained in:
@@ -32,16 +32,21 @@ namespace OpenRA.Mods.Common
|
|||||||
public sealed class DiscordService : IGlobalModData, IDisposable
|
public sealed class DiscordService : IGlobalModData, IDisposable
|
||||||
{
|
{
|
||||||
public readonly string ApplicationId = null;
|
public readonly string ApplicationId = null;
|
||||||
readonly DiscordRpcClient client;
|
DiscordRpcClient client;
|
||||||
DiscordState currentState;
|
DiscordState currentState;
|
||||||
|
|
||||||
static readonly Lazy<DiscordService> Service = Exts.Lazy(() =>
|
static DiscordService instance;
|
||||||
|
static DiscordService GetService()
|
||||||
{
|
{
|
||||||
|
if (instance != null)
|
||||||
|
return instance;
|
||||||
|
|
||||||
if (!Game.ModData.Manifest.Contains<DiscordService>())
|
if (!Game.ModData.Manifest.Contains<DiscordService>())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return Game.ModData.Manifest.Get<DiscordService>();
|
instance = Game.ModData.Manifest.Get<DiscordService>();
|
||||||
});
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
public DiscordService(MiniYaml yaml)
|
public DiscordService(MiniYaml yaml)
|
||||||
{
|
{
|
||||||
@@ -90,7 +95,7 @@ namespace OpenRA.Mods.Common
|
|||||||
if (currentState == state)
|
if (currentState == state)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Service.Value == null)
|
if (instance == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string stateText;
|
string stateText;
|
||||||
@@ -164,20 +169,26 @@ namespace OpenRA.Mods.Common
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (client != null)
|
if (client != null)
|
||||||
|
{
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
|
client = null;
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int? players = null, int? slots = null)
|
public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int? players = null, int? slots = null)
|
||||||
{
|
{
|
||||||
if (Service.Value != null)
|
var service = GetService();
|
||||||
Service.Value.SetStatus(state, details, secret, players, slots);
|
if (service != null)
|
||||||
|
service.SetStatus(state, details, secret, players, slots);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetPlayers(int players, int slots)
|
public static void SetPlayers(int players, int slots)
|
||||||
{
|
{
|
||||||
if (Service.Value != null)
|
var service = GetService();
|
||||||
|
if (service != null)
|
||||||
{
|
{
|
||||||
Service.Value.client.UpdateParty(new Party
|
service.client.UpdateParty(new Party
|
||||||
{
|
{
|
||||||
ID = Secrets.CreateFriendlySecret(new Random()),
|
ID = Secrets.CreateFriendlySecret(new Random()),
|
||||||
Size = players,
|
Size = players,
|
||||||
@@ -188,14 +199,16 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public static void UpdatePlayers(int players, int slots)
|
public static void UpdatePlayers(int players, int slots)
|
||||||
{
|
{
|
||||||
if (Service.Value != null)
|
var service = GetService();
|
||||||
Service.Value.client.UpdatePartySize(players, slots);
|
if (service != null)
|
||||||
|
service.client.UpdatePartySize(players, slots);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateDetails(string details)
|
public static void UpdateDetails(string details)
|
||||||
{
|
{
|
||||||
if (Service.Value != null)
|
var service = GetService();
|
||||||
Service.Value.client.UpdateDetails(details);
|
if (service != null)
|
||||||
|
service.client.UpdateDetails(details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user