2013-09-25 00:54:51 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-09-27 17:04:35 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-09-25 00:54:51 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2013-09-27 17:04:35 +00:00
|
|
|
|
using System.Linq;
|
2013-09-25 00:54:51 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.ServerApplication.Native
|
|
|
|
|
{
|
2013-09-27 17:04:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class BrowserLauncher
|
|
|
|
|
/// </summary>
|
2013-09-25 00:54:51 +00:00
|
|
|
|
public static class BrowserLauncher
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the dashboard page.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="page">The page.</param>
|
|
|
|
|
/// <param name="loggedInUser">The logged in user.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="appHost">The app host.</param>
|
2013-09-27 17:04:35 +00:00
|
|
|
|
/// <param name="logger">The logger.</param>
|
2013-09-25 00:54:51 +00:00
|
|
|
|
public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
2014-07-02 04:57:18 +00:00
|
|
|
|
appHost.WebApplicationName + "/web/" + page;
|
2013-09-25 00:54:51 +00:00
|
|
|
|
|
|
|
|
|
OpenUrl(url, logger);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-27 17:04:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the github.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public static void OpenGithub(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
OpenUrl("https://github.com/MediaBrowser/MediaBrowser", logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the community.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public static void OpenCommunity(ILogger logger)
|
|
|
|
|
{
|
2014-05-08 21:23:24 +00:00
|
|
|
|
OpenUrl("http://mediabrowser.tv/community", logger);
|
2013-09-27 17:04:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the web client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="appHost">The app host.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public static void OpenWebClient(IUserManager userManager, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
var user = userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
|
|
|
|
OpenDashboardPage("index.html", user, configurationManager, appHost, logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the dashboard.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="appHost">The app host.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public static void OpenDashboard(IUserManager userManager, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
var user = userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator);
|
|
|
|
|
OpenDashboardPage("dashboard.html", user, configurationManager, appHost, logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the swagger.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
|
|
|
/// <param name="appHost">The app host.</param>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public static void OpenSwagger(IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
OpenUrl("http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
|
|
|
|
appHost.WebApplicationName + "/swagger-ui/index.html", logger);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 00:54:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens the URL.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The URL.</param>
|
2013-09-27 17:04:35 +00:00
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
private static void OpenUrl(string url, ILogger logger)
|
2013-09-25 00:54:51 +00:00
|
|
|
|
{
|
|
|
|
|
var process = new Process
|
2013-12-05 16:50:21 +00:00
|
|
|
|
{
|
|
|
|
|
StartInfo = new ProcessStartInfo
|
2013-09-25 00:54:51 +00:00
|
|
|
|
{
|
2013-12-05 16:50:21 +00:00
|
|
|
|
FileName = url
|
|
|
|
|
},
|
2013-09-25 00:54:51 +00:00
|
|
|
|
|
2013-12-05 16:50:21 +00:00
|
|
|
|
EnableRaisingEvents = true,
|
|
|
|
|
};
|
2013-09-25 00:54:51 +00:00
|
|
|
|
|
|
|
|
|
process.Exited += ProcessExited;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
process.Start();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.ErrorException("Error launching url: {0}", ex, url);
|
|
|
|
|
|
2013-12-05 16:50:21 +00:00
|
|
|
|
Console.WriteLine("Error launching browser");
|
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
|
2014-10-06 23:58:46 +00:00
|
|
|
|
//#if !__MonoCS__
|
|
|
|
|
// System.Windows.Forms.MessageBox.Show("There was an error launching your web browser. Please check your default browser settings.");
|
|
|
|
|
//#endif
|
2013-09-25 00:54:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Processes the exited.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">The sender.</param>
|
|
|
|
|
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
|
|
|
|
|
private static void ProcessExited(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
((Process)sender).Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|