Improve how multiple menu instances are handled

This commit is contained in:
pizzaboxer 2023-06-12 12:16:42 +01:00
parent 778a67dcb9
commit 3926f30866
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
2 changed files with 25 additions and 13 deletions

View File

@ -228,25 +228,22 @@ namespace Bloxstrap
if (IsMenuLaunch)
{
Mutex mutex;
Process? menuProcess = Process.GetProcesses().Where(x => x.MainWindowTitle == $"{ProjectName} Menu").FirstOrDefault();
try
if (menuProcess is not null)
{
mutex = Mutex.OpenExisting("Bloxstrap_MenuMutex");
Logger.WriteLine("[App::OnStartup] Bloxstrap_MenuMutex mutex exists, aborting menu launch...");
Terminate();
IntPtr handle = menuProcess.MainWindowHandle;
Logger.WriteLine($"[App::OnStartup] Found an already existing menu window with handle {handle}");
NativeMethods.SetForegroundWindow(handle);
}
catch
else
{
// no mutex exists, continue to opening preferences menu
mutex = new(true, "Bloxstrap_MenuMutex");
}
if (Utilities.GetProcessCount(ProjectName) > 1)
if (Process.GetProcessesByName(ProjectName).Length > 1)
ShowMessageBox($"{ProjectName} is currently running, likely as a background Roblox process. Please note that not all your changes will immediately apply until you close all currently open Roblox instances.", MessageBoxImage.Information);
new MainWindow().ShowDialog();
}
}
else if (LaunchArgs.Length > 0)
{
if (LaunchArgs[0].StartsWith("roblox-player:"))

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap
{
static class NativeMethods
{
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}