Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/Launch/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ public class Options : IVerb

[Option('p', "preview", Required = false, HelpText = "Show me what will launch, but dont run it. This will also report the token values and show the contents of the generated file, if applicable.")]
public bool Preview { get; set; }

[Option("debug", Required = false, HelpText = "Keep the console window visible for troubleshooting.")]
public bool Debug { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/OneIdentity.Scalus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>OneIdentity.Scalus</RootNamespace>
<AssemblyName>scalus</AssemblyName>
<StartupObject>OneIdentity.Scalus.Program</StartupObject>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>signer.pfx</AssemblyOriginatorKeyFile>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<RuntimeIdentifiers>linux-x64;osx-x64;win10-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<UserSecretsId>dc8f57ba-8a9d-40c4-bf34-a2ffba1ff687</UserSecretsId>
<Company>One Identity LLC</Company>
<Copyright>Copyright 2021 One Identity LLC</Copyright>
Expand All @@ -38,11 +38,11 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
<NoWarn>1701;1702;CA1416</NoWarn>
<NoWarn>1701;1702;CA1416;CA1854;CA1860;CA1865;SYSLIB1045;SYSLIB1054</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;CA1416</NoWarn>
<NoWarn>1701;1702;CA1416;CA1854;CA1860;CA1865;SYSLIB1045;SYSLIB1054</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -116,9 +116,9 @@
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.12" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand All @@ -131,7 +131,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace OneIdentity.Scalus
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -37,8 +38,20 @@ namespace OneIdentity.Scalus

internal class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeConsole();

private static int Main(string[] args)
{
// On Windows, detach from the console for 'launch' and 'ui' verbs so no console
// window is visible. When launched from a browser/Explorer, the console window
// (which was created just for this process) is destroyed. (GitHub issue #131)
// CLI commands (info, register, --help, etc.) keep the console as normal.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && ShouldHideConsole(args))
{
FreeConsole();
}
Comment on lines +52 to +61

bool community = false;
#if COMMUNITY_EDITION
community = true;
Expand Down Expand Up @@ -117,6 +130,24 @@ private static void ReleaseLaunchSemaphore()
}
}

private static bool ShouldHideConsole(string[] args)
{
if (args.Length == 0)
{
// No verb defaults to 'ui'
return true;
}

// --debug flag keeps the console visible for troubleshooting
if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
{
return false;
}

return string.Equals(args[0], "launch", StringComparison.OrdinalIgnoreCase) ||
string.Equals(args[0], "ui", StringComparison.OrdinalIgnoreCase);
Comment thread
Copilot marked this conversation as resolved.
Outdated
}

private static void HandleUnexpectedError(Exception ex)
{
Serilog.Log.Error($"Unexpected error: {ex.Message}", ex);
Expand Down
2 changes: 2 additions & 0 deletions src/Ui/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ namespace OneIdentity.Scalus.Ui
[Verb("ui", isDefault: true, HelpText = "Run the configuration UI")]
public class Options : IVerb
{
[Option("debug", Required = false, HelpText = "Keep the console window visible for troubleshooting.")]
public bool Debug { get; set; }
}
}
6 changes: 3 additions & 3 deletions test/OneIdentity.Scalus.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>signer.pfx</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<OutputType>WinExe</OutputType>
<RootNamespace>OneIdentity.Scalus.Test</RootNamespace>
<RuntimeIdentifiers>linux-x64;osx-x64;win10-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

Expand All @@ -29,7 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading