diff --git a/ArchiSteamFarm/Core/NativeMethods.cs b/ArchiSteamFarm/Core/NativeMethods.cs index 04bd181d0..b98ce16df 100644 --- a/ArchiSteamFarm/Core/NativeMethods.cs +++ b/ArchiSteamFarm/Core/NativeMethods.cs @@ -32,6 +32,9 @@ internal static partial class NativeMethods { [SupportedOSPlatform("Windows")] internal const uint EnableQuickEditMode = 0x0040; + [SupportedOSPlatform("Windows")] + internal const byte ShowWindowMinimize = 6; + [SupportedOSPlatform("Windows")] internal const sbyte StandardInputHandle = -10; @@ -103,6 +106,17 @@ internal static partial class NativeMethods { internal static partial EExecutionState SetThreadExecutionState(EExecutionState executionState); #endif + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + [SupportedOSPlatform("Windows")] + [return: MarshalAs(UnmanagedType.Bool)] +#if NETFRAMEWORK + [DllImport("user32.dll")] + internal static extern bool ShowWindow(nint hWnd, int nCmdShow); +#else + [LibraryImport("user32.dll")] + internal static partial bool ShowWindow(nint hWnd, int nCmdShow); +#endif + [Flags] [SupportedOSPlatform("Windows")] internal enum EExecutionState : uint { diff --git a/ArchiSteamFarm/Core/OS.cs b/ArchiSteamFarm/Core/OS.cs index 166d9fcb5..47c371b9a 100644 --- a/ArchiSteamFarm/Core/OS.cs +++ b/ArchiSteamFarm/Core/OS.cs @@ -92,8 +92,12 @@ internal static class OS { private static string? BackingVersion; private static Mutex? SingleInstance; - internal static void CoreInit(bool systemRequired) { + internal static void CoreInit(bool minimized, bool systemRequired) { if (OperatingSystem.IsWindows()) { + if (minimized) { + WindowsMinimizeConsoleWindow(); + } + if (systemRequired) { WindowsKeepSystemActive(); } @@ -328,6 +332,17 @@ internal static class OS { } } + [SupportedOSPlatform("Windows")] + private static void WindowsMinimizeConsoleWindow() { + if (!OperatingSystem.IsWindows()) { + throw new PlatformNotSupportedException(); + } + + using Process process = Process.GetCurrentProcess(); + + NativeMethods.ShowWindow(process.MainWindowHandle, NativeMethods.ShowWindowMinimize); + } + [Flags] [SupportedOSPlatform("FreeBSD")] [SupportedOSPlatform("Linux")] diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index c96378805..41db2ccde 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -71,6 +71,7 @@ internal static class Program { private static bool IgnoreUnsupportedEnvironment; private static bool InputCryptkeyManually; + private static bool Minimized; private static bool SystemRequired; internal static async Task Exit(byte exitCode = 0) { @@ -283,7 +284,7 @@ internal static class Program { return false; } - OS.CoreInit(SystemRequired); + OS.CoreInit(Minimized, SystemRequired); Console.Title = SharedInfo.ProgramIdentifier; ASF.ArchiLogger.LogGenericInfo(SharedInfo.ProgramIdentifier); @@ -580,6 +581,10 @@ internal static class Program { case "--INPUT-CRYPTKEY" when noArgumentValueNext(): InputCryptkeyManually = true; + break; + case "--MINIMIZED" when noArgumentValueNext(): + Minimized = true; + break; case "--NETWORK-GROUP" when noArgumentValueNext(): networkGroupNext = true;