Skip to content

Commit

Permalink
[MTGOSDK/Core/RemoteClient] Allow MTGO to start minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
Qonfused committed Jan 2, 2024
1 parent ff9145c commit dba2ca9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions MTGOSDK/src/API/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public Client(ClientOptions options = default) : base(
//
Construct(_ref: s_flsClientSession /* Can be any deferred instance */);

// Minimize the MTGO window after startup.
if (options.StartMinimized)
RemoteClient.MinimizeWindow();

// Verify that any existing user sessions are valid.
if ((SessionId == Guid.Empty) && IsConnected)
throw new VerificationException("Current user session is invalid.");
Expand Down
5 changes: 5 additions & 0 deletions MTGOSDK/src/API/ClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public struct ClientOptions()
/// </summary>
public bool CreateProcess { get; init; } = false;

/// <summary>
/// Whether to start the MTGO process minimized.
/// </summary>
public bool StartMinimized { get; init; } = false;

/// <summary>
/// Whether to kill the MTGO process when the client object is disposed.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions MTGOSDK/src/Core/RemoteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

using RemoteNET;
Expand Down Expand Up @@ -146,6 +147,19 @@ public static async Task<bool> StartProcess()
return await WaitUntil(() => MTGOProcess().MainWindowHandle != IntPtr.Zero);
}

private const int SW_MAXIMIZE = 3;
private const int SW_MINIMIZE = 6;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

public static bool MinimizeWindow()
{
var handle = MTGOProcess().MainWindowHandle;
return ShowWindow(handle, SW_MINIMIZE);
}

//
// Process and RemoteNET state management
//
Expand Down

0 comments on commit dba2ca9

Please sign in to comment.