Пример #1
0
        static DRP_Main()
        {
            last_updated_file_name = FileHelper.ReadFileIntoString(DRP_LAST_UPDATED_FILE_PATH);
            clientID = Environment.GetEnvironmentVariable("DISCORD_CLIENT_ID");
            if (clientID == null)
            {
                clientID = "619838876994764800";
            }

            if (InitDiscord())
            {
                EditorApplication.update += Update;
            }
            else
            {
                EditorApplication.update += TryInitDiscord;
            }

            ModuleHandler.RegisterPreModuleRemoveFunction(delegate()
            {
                if (isRunning)
                {
                    EditorApplication.update -= Update;
                }
                else
                {
                    EditorApplication.update -= TryInitDiscord;
                }
                discord.Dispose();
            });
        }
Пример #2
0
 public void UpdaterThread()
 {
     try
     {
         while (true)
         {
             if (!disposed)
             {
                 discord.RunCallbacks();
                 Thread.Sleep(1000 / 60);
             }
             if (stopThread)
             {
                 break;
             }
         }
     }
     finally
     {
         if (!disposed)
         {
             discord.Dispose();
             disposed = true;
         }
     }
 }
Пример #3
0
 public static void Shutdown()
 {
     if (DiscordInstance != null)
     {
         DiscordInstance.Dispose();
     }
 }
Пример #4
0
 void DestroyDiscord()
 {
     if (discord == null)
     {
         return;
     }
     try {
         discord.GetActivityManager()?.ClearActivity(_ => { });
         discord.RunCallbacks();
     } finally {
         discord.Dispose();
         discord = null;
     }
 }
 public static void Clear()
 {
     MainLogic.Log("Disconnecting from discord...");
     if (discord != null)
     {
         try
         {
             discord.Dispose();
         }
         catch
         {
         }
     }
     discord = null;
 }
Пример #6
0
        public static void Dispose()
        {
            if (_Discord == null)
            {
                return;
            }

            try
            {
                _Discord.GetActivityManager().ClearActivity((result) =>
                {
                    _Discord.Dispose();
                    _Discord = null;
                });
            }
            catch { }
        }
Пример #7
0
 private async Task StartInstance()
 {
     try
     {
         Console.WriteLine("Start Discord bridge");
         IsRunning = true;
         while (IsRunning)
         {
             discord.RunCallbacks();
             await Task.Delay(1000 / 60);
         }
     }
     finally
     {
         Console.WriteLine("Stop and dispose Discord bridge");
         discord.Dispose();
     }
 }
Пример #8
0
        private void _BackgroundLoop()
        {
            App.Logger.Info(nameof(DiscordManager), "Background loop started");
            try
            {
                while (true)
                {
                    _DisposedTokenSource.Token.ThrowIfCancellationRequested();

                    var workingVisible = StatusVisible;
                    if (workingVisible != LastStatusVisible)
                    {
                        if (workingVisible)
                        {
                            _Discord?.Dispose();
                            _Discord = _CreateDiscordClient();

                            var activity = new Discord.Activity
                            {
                                State   = "Optimised PSO2 Patcher",
                                Details = "https://astra.yen.gg",
                                Assets  = new Discord.ActivityAssets
                                {
                                    LargeImage = "icon-borderless",
                                    LargeText  = "PSRT Astra"
                                }
                            };

                            Discord.Result?result = null;
                            _Discord.GetActivityManager().UpdateActivity(activity, res => result = res);
                            while (result == null)
                            {
                                _PollDiscord(_Discord);
                            }

                            if (result == Discord.Result.Ok)
                            {
                                App.Logger.Info(nameof(DiscordManager), "Activity updated");
                            }
                            else
                            {
                                App.Logger.Info(nameof(DiscordManager), $"Activity update failed: {result}");
                            }
                        }
                        else if (_Discord != null)
                        {
                            Discord.Result?result = null;
                            _Discord.GetActivityManager().ClearActivity(res => result = res);
                            while (result == null)
                            {
                                _PollDiscord(_Discord);
                            }

                            _Discord.Dispose();
                            _Discord = null;

                            if (result == Discord.Result.Ok)
                            {
                                App.Logger.Info(nameof(DiscordManager), "Activity cleared");
                            }
                            else
                            {
                                App.Logger.Info(nameof(DiscordManager), $"Activity clearing failed: {result}");
                            }
                        }
                        LastStatusVisible = workingVisible;
                    }

                    Thread.Sleep(250);
                }
            }
            catch (OperationCanceledException)
            {
                App.Logger.Info(nameof(DiscordManager), "Background loop canceled");
            }
            catch (Exception ex)
            {
                App.Logger.Error(nameof(DiscordManager), "Fatal error in background loop", ex);
            }
            finally
            {
                _Discord?.Dispose();
            }
        }
Пример #9
0
 public static void Close()
 {
     discord.GetActivityManager().ClearActivity((p) => { });
     discord.Dispose();
 }