Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] [spike] Minimize HTTP API console windows #297

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Runtime.InteropServices;

namespace Divergent.Customers.API
{
static class ConsoleEx
{
public static void TryMinimize()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that check really necessary when targeting the .NET Framework?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timbussmann it's an edge case, but you could run it on Mono on *nix. But in any case, we want to move to .NET Core ASAP anyway, so I'd rather include this check now.

{
WindowsNativeMethods.ShowWindow(WindowsNativeMethods.GetConsoleWindow(), WindowsNativeMethods.SW_SHOWMINIMIZED);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Program
public static async Task Main(string[] args)
{
Console.Title = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
ConsoleEx.TryMinimize();

var tcs = new TaskCompletionSource<object>();
Console.CancelKeyPress += (sender, e) => { tcs.SetResult(null); };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Runtime.InteropServices;

namespace Divergent.Customers.API
{
static class WindowsNativeMethods
{
public const int SW_SHOWMINIMIZED = 2;

[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
}