// Copyright Epic Games, Inc. All Rights Reserved. using System.Diagnostics; using System.Threading.Tasks; using EpicGames.Core; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace HordeServer.Commands { /// /// Opens a web browser to the server homepage /// [Command("open", "Open web browser to the server homepage")] public class OpenCommand : Command { readonly IOptions _settings; /// /// Constructor /// public OpenCommand(IOptions settings) { _settings = settings; } /// public override Task ExecuteAsync(ILogger logger) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = $"http://localhost:{_settings.Value.HttpPort}"; startInfo.UseShellExecute = true; using Process? process = Process.Start(startInfo); return Task.FromResult((process != null) ? 0 : 1); } } }