mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2026-05-09 01:59:32 +00:00
This PR addresses [Ryubing/Issues#345](https://github.com/Ryubing/Issues/issues/345) by fixing the Windows console hide/show path so it only acts on Ryujinx’s own console window instead of whatever window happens to be focused during startup. Previously, when Show Console was disabled, the helper could race with focus changes and end up affecting another app or shell window while leaving the console visible; this change removes that foreground-window dependency and keeps the startup behavior scoped to the Ryujinx console. Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/32
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using Ryujinx.Common.Logging;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace Ryujinx.Common.Helper
|
|
{
|
|
public static partial class ConsoleHelper
|
|
{
|
|
[SupportedOSPlatform("windows")]
|
|
[LibraryImport("kernel32")]
|
|
private static partial nint GetConsoleWindow();
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
[LibraryImport("kernel32", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
private static partial bool FreeConsole();
|
|
|
|
public static bool SetConsoleWindowStateSupported => OperatingSystem.IsWindows();
|
|
public static bool HasConsoleWindow => OperatingSystem.IsWindows() && GetConsoleWindow() != nint.Zero;
|
|
|
|
public static void SetConsoleWindowState(bool show)
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
SetConsoleWindowStateWindows(show);
|
|
}
|
|
else if (show == false)
|
|
{
|
|
Logger.Warning?.Print(LogClass.Application, "OS doesn't support hiding console window");
|
|
}
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static void SetConsoleWindowStateWindows(bool show)
|
|
{
|
|
if (show)
|
|
{
|
|
if (GetConsoleWindow() != nint.Zero)
|
|
{
|
|
Logger.SetConsoleTargetEnabled(true);
|
|
}
|
|
return;
|
|
}
|
|
|
|
Logger.SetConsoleTargetEnabled(false);
|
|
DetachConsole();
|
|
}
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
private static void DetachConsole()
|
|
{
|
|
if (GetConsoleWindow() == nint.Zero)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!FreeConsole())
|
|
{
|
|
Logger.Warning?.Print(LogClass.Application, "Attempted to detach console window but the operation failed");
|
|
}
|
|
}
|
|
}
|
|
}
|