diff --git a/Studio/CelesteStudio/Studio.cs b/Studio/CelesteStudio/Studio.cs index 4f19d1ea..d443ccc6 100644 --- a/Studio/CelesteStudio/Studio.cs +++ b/Studio/CelesteStudio/Studio.cs @@ -102,7 +102,7 @@ public Studio(string[] args, Action windowCreationCallback) { // Close other Studio instances to avoid conflicts foreach (var process in Process.GetProcesses().Where(process => process.ProcessName is "CelesteStudio" or "CelesteStudio.WPF" or "CelesteStudio.GTK" or "CelesteStudio.Mac" or "Celeste Studio")) { - if (process.Id == Process.GetCurrentProcess().Id) { + if (process.Id == Environment.ProcessId) { continue; } diff --git a/StudioCommunication/Util/ProcessHelper.cs b/StudioCommunication/Util/ProcessHelper.cs index 11995a9b..e4a84a19 100644 --- a/StudioCommunication/Util/ProcessHelper.cs +++ b/StudioCommunication/Util/ProcessHelper.cs @@ -27,15 +27,13 @@ public static void Terminate(this Process process) { } // Windows - FreeConsole(); - AttachConsole((uint)process.Id); - GenerateConsoleCtrlEvent(0, 0); + if (process.MainWindowHandle != IntPtr.Zero) { + PostMessage(process.MainWindowHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); + } } - [DllImport("kernel32.dll")] - private static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId); - [DllImport("kernel32.dll", SetLastError = true)] - private static extern bool AttachConsole(uint dwProcessId); - [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern bool FreeConsole(); + [DllImport("user32.dll")] + private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); + + private const uint WM_CLOSE = 0x0010; }