jellyfin-server/Emby.Server.Implementations/Browser/BrowserLauncher.cs

50 lines
1.7 KiB
C#
Raw Normal View History

using System;
using MediaBrowser.Controller;
using Microsoft.Extensions.Logging;
2013-09-25 00:54:51 +00:00
namespace Emby.Server.Implementations.Browser
2013-09-25 00:54:51 +00:00
{
2013-09-27 17:04:35 +00:00
/// <summary>
/// Assists in opening application URLs in an external browser.
2013-09-27 17:04:35 +00:00
/// </summary>
2013-09-25 00:54:51 +00:00
public static class BrowserLauncher
{
2013-09-27 17:04:35 +00:00
/// <summary>
/// Opens the home page of the web client.
2013-09-27 17:04:35 +00:00
/// </summary>
/// <param name="appHost">The app host.</param>
2018-09-12 17:26:21 +00:00
public static void OpenWebApp(IServerApplicationHost appHost)
2013-09-27 17:04:35 +00:00
{
TryOpenUrl(appHost, "/web/index.html");
2013-09-27 17:04:35 +00:00
}
/// <summary>
/// Opens the swagger API page.
/// </summary>
/// <param name="appHost">The app host.</param>
public static void OpenSwaggerPage(IServerApplicationHost appHost)
{
TryOpenUrl(appHost, "/swagger/index.html");
}
2013-09-25 00:54:51 +00:00
/// <summary>
/// Opens the specified URL in an external browser window. Any exceptions will be logged, but ignored.
2013-09-25 00:54:51 +00:00
/// </summary>
/// <param name="appHost">The application host.</param>
/// <param name="relativeUrl">The URL to open, relative to the server base URL.</param>
private static void TryOpenUrl(IServerApplicationHost appHost, string relativeUrl)
2013-09-25 00:54:51 +00:00
{
try
{
string baseUrl = appHost.GetLocalApiUrl("localhost");
appHost.LaunchUrl(baseUrl + relativeUrl);
2016-04-24 03:03:49 +00:00
}
catch (Exception ex)
2013-09-25 00:54:51 +00:00
{
2020-06-06 00:15:56 +00:00
var logger = appHost.Resolve<ILogger<IServerApplicationHost>>();
logger?.LogError(ex, "Failed to open browser window with URL {URL}", relativeUrl);
2013-09-25 00:54:51 +00:00
}
}
}
}