The Free Software Media System - Server Backend & API
Clean up and document BrowserLauncher correctly
Mark Monteiroa67e32f8ecd4
diff --git a/Emby.Server.Implementations/Browser/BrowserLauncher.cs b/Emby.Server.Implementations/Browser/BrowserLauncher.csindex 752650ae18..96096e142a 100644--- a/Emby.Server.Implementations/Browser/BrowserLauncher.cs+++ b/Emby.Server.Implementations/Browser/BrowserLauncher.cs@@ -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);}}}diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.csindex 25f0905eb8..608ffc61c2 100644--- a/MediaBrowser.Controller/IServerApplicationHost.cs+++ b/MediaBrowser.Controller/IServerApplicationHost.cs@@ -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);