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