Skip to content

Commit

Permalink
feat(labfusion.menu & labfusion.utilities): add process checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Naymmmm committed Jan 5, 2025
1 parent 43ad710 commit 670dec9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
20 changes: 19 additions & 1 deletion LabFusion/src/Menu/Pages/MenuLogIn.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using LabFusion.Marrow.Proxies;
using LabFusion.Network;
using LabFusion.Network.Proxy;
using LabFusion.Preferences.Client;
using LabFusion.Utilities;

using UnityEngine;

Expand Down Expand Up @@ -47,13 +49,29 @@ public static void PopulateLogIn(GameObject logInGameObject)
};

var logInElement = layoutOptions.Find("button_LogIn").GetComponent<FunctionElement>()
.WithTitle("Log In (illegally)")
.WithTitle("Log In (very legal)")
.Do(() =>
{
var layer = NetworkLayerManager.GetTargetLayer();

if (layer != null)
{
if (layer == NetworkLayer.GetLayer<ProxySteamVRNetworkLayer>())
{
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);
}
});
Expand Down
28 changes: 28 additions & 0 deletions LabFusion/src/Utilities/ProcessUtils.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 670dec9

Please sign in to comment.