/// <summary> /// Initialize discord RPC controller. /// </summary> public static void Init(bool forced) { if (Application.isBatchMode) { Debug.Log($"Discord RPC can't be initialized in BathMode."); return; // ignore discord in batchmode! } //Debug.Log($"JEMDiscordController.Initialize isInitialized:{IsInitialized}"); if (IsInitialized) { return; } IsInitialized = true; // Load configuration. JEMDiscordConfiguration.LoadConfiguration(); // Hook the update EditorApplication.update += Update; // Load last initialization time. if (EditorPrefs.HasKey("jem.discordRPC.lastInitialization")) { _lastInitializationTime = DateTime.Parse(EditorPrefs.GetString("jem.discordRPC.lastInitialization"), CultureInfo.InvariantCulture); } // To prevent spamming with discord RPC init calls we will only initialize discord controller again if there is at least // one minute difference with previous init call. if (CanInitialize()) { InternalDiscordInitialize(); } }
public static void LoadConfiguration() { if (File.Exists(ConfigFile)) { Loaded = JsonUtility.FromJson <JEMDiscordConfiguration>(File.ReadAllText(ConfigFile)); } else { Debug.Log($"{ConfigFile} was missing. Creating new."); Loaded = new JEMDiscordConfiguration(); } }
private static bool CanInitialize() { var config = JEMDiscordConfiguration.Resolve(); if (!config.Enable) { return(false); } var diff = DateTime.Now - _lastInitializationTime; return(diff.Seconds >= config.RecompileTimeout); }
private static void Update() { if (!IsInitialized) { return; } if (!IsConnected) { // While discord is not yet connected, we will try again after one min. if (CanInitialize()) { InternalDiscordInitialize(); } return; } // Hide unity presence if not focused. // TODO: Adjust timestamp after receiving focus again if (_wasWindowFocused == InternalEditorUtility.isApplicationActive) { return; } _wasWindowFocused = InternalEditorUtility.isApplicationActive; if (!JEMDiscordConfiguration.Resolve().ShowPresenceOnlyWhenActive) { return; } if (_wasWindowFocused) { JEMDiscordUnityPresence.RefreshPresence(); } else { JEMDiscordUnityPresence.RefreshPresence(true); } }