Clean up and document BrowserLauncher correctly

pull/2601/head
Mark Monteiro 4 years ago
parent 420e3619fb
commit a67e32f8ec

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

@ -82,6 +82,11 @@ namespace MediaBrowser.Controller
/// <returns>The local API URL.</returns>
string GetLocalApiUrl(IPAddress address);
/// <summary>
/// Open a URL in an external browser window.
/// </summary>
/// <param name="url">The URL to open.</param>
/// <exception cref="NotSupportedException"><see cref="CanLaunchWebBrowser"/> is false.</exception>
void LaunchUrl(string url);
void EnableLoopback(string appName);

Loading…
Cancel
Save