using System;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Browser
{
///
/// Assists in opening application URLs in an external browser.
///
public static class BrowserLauncher
{
///
/// Opens the home page of the web client.
///
/// The app host.
public static void OpenWebApp(IServerApplicationHost appHost)
{
TryOpenUrl(appHost, "/web/index.html");
}
///
/// Opens the swagger API page.
///
/// The app host.
public static void OpenSwaggerPage(IServerApplicationHost appHost)
{
TryOpenUrl(appHost, "/api-docs/swagger");
}
///
/// Opens the specified URL in an external browser window. Any exceptions will be logged, but ignored.
///
/// The application host.
/// The URL.
private static void TryOpenUrl(IServerApplicationHost appHost, string url)
{
try
{
string baseUrl = appHost.GetLocalApiUrl("localhost");
appHost.LaunchUrl(baseUrl + url);
}
catch (Exception ex)
{
var logger = appHost.Resolve();
logger?.LogError(ex, "Failed to open browser window with URL {URL}", url);
}
}
}
}