From 670dec9817e0b96776dc395f9f2ef558f6a88a3f Mon Sep 17 00:00:00 2001 From: naymmm Date: Sun, 5 Jan 2025 14:05:12 +1100 Subject: [PATCH] feat(labfusion.menu & labfusion.utilities): add process checking --- LabFusion/src/Menu/Pages/MenuLogIn.cs | 20 +++++++++++++++++- LabFusion/src/Utilities/ProcessUtils.cs | 28 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 LabFusion/src/Utilities/ProcessUtils.cs diff --git a/LabFusion/src/Menu/Pages/MenuLogIn.cs b/LabFusion/src/Menu/Pages/MenuLogIn.cs index 5865ab31..bb563cea 100644 --- a/LabFusion/src/Menu/Pages/MenuLogIn.cs +++ b/LabFusion/src/Menu/Pages/MenuLogIn.cs @@ -1,6 +1,8 @@ using LabFusion.Marrow.Proxies; using LabFusion.Network; +using LabFusion.Network.Proxy; using LabFusion.Preferences.Client; +using LabFusion.Utilities; using UnityEngine; @@ -47,13 +49,29 @@ public static void PopulateLogIn(GameObject logInGameObject) }; var logInElement = layoutOptions.Find("button_LogIn").GetComponent() - .WithTitle("Log In (illegally)") + .WithTitle("Log In (very legal)") .Do(() => { var layer = NetworkLayerManager.GetTargetLayer(); if (layer != null) { + if (layer == NetworkLayer.GetLayer()) + { + if (ProcessUtils.ProcessRunning("Fusion Helper") == false) + { + FusionLogger.Warn("FusionHelper is not running!"); + FusionNotifier.Send(new FusionNotification() + { + Title = "FusionHelper is not running!", + Message = "FusionHelper is not running, therefore you will not be able to connect to the Proxy layer.", + Type = NotificationType.WARNING, + SaveToMenu = false, + ShowPopup = true, + PopupLength = 3f, + }); + } + } NetworkLayerManager.LogIn(layer); } }); diff --git a/LabFusion/src/Utilities/ProcessUtils.cs b/LabFusion/src/Utilities/ProcessUtils.cs new file mode 100644 index 00000000..7158f4d8 --- /dev/null +++ b/LabFusion/src/Utilities/ProcessUtils.cs @@ -0,0 +1,28 @@ +using System; +using System.Diagnostics; + +namespace LabFusion.Utilities; + +public static class ProcessUtils +{ + private static bool ProcessRunningInternal(string processName) + { + // Check if the process name is valid + if (string.IsNullOrEmpty(processName)) + { + throw new ArgumentException("Process name cannot be null or empty.", nameof(processName)); + } + + // Get all processes with the specified name + Process[] processes = Process.GetProcessesByName(processName); + + // Return true if any processes are found + return processes.Length > 0; + } + + public static bool ProcessRunning(string args) + { + + return ProcessRunningInternal(args); + } +}