mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Improve how multiple menu instances are handled
This commit is contained in:
parent
778a67dcb9
commit
3926f30866
@ -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:"))
|
||||
|
15
Bloxstrap/NativeMethods.cs
Normal file
15
Bloxstrap/NativeMethods.cs
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user