Skip to content

Commit

Permalink
Hide console on startup (windows only)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jul 14, 2023
1 parent 0eb08af commit 714b723
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/NxEditor.Core/Extensions/ConsoleExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Runtime.InteropServices;

namespace NxEditor.Core.Extensions;

public enum WindowMode : int { Hidden = 0, Visible = 5 }

public static partial class ConsoleExtension
{
private static readonly IntPtr _handle = GetConsoleWindow();
private static WindowMode _current = WindowMode.Visible;

[LibraryImport("kernel32.dll")]
private static partial IntPtr GetConsoleWindow();

[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool ShowWindow(IntPtr window_handle, int cmd_show_mode);

public static void SetWindowMode(WindowMode mode)
{
_current = mode;
ShowWindow(_handle, (int)mode);
}

public static void SwapWindowMode()
{
_current = _current == WindowMode.Hidden
? WindowMode.Visible : WindowMode.Hidden;
ShowWindow(_handle, (int)_current);
}
}
1 change: 1 addition & 0 deletions src/NxEditor.Core/NxEditor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/NxEditor/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public override async void OnFrameworkInitializationCompleted()
MaxItems = 3,
Margin = new(0, 0, 4, 0)
};
#if WIN_X64
Core.Extensions.ConsoleExtension.SetWindowMode(
Core.Extensions.WindowMode.Hidden);
#endif
};

ConfigViewModel.Shared.IsValid = PluginManager.RegisterModules(ConfigViewModel.Shared);
Expand Down

0 comments on commit 714b723

Please sign in to comment.