using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; using System.Diagnostics; using System.Linq; namespace MediaBrowser.ServerApplication.Native { /// /// Class BrowserLauncher /// public static class BrowserLauncher { /// /// Opens the dashboard page. /// /// The page. /// The logged in user. /// The configuration manager. /// The app host. /// The logger. public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger) { var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" + appHost.WebApplicationName + "/dashboard/" + page; OpenUrl(url, logger); } /// /// Opens the github. /// /// The logger. public static void OpenGithub(ILogger logger) { OpenUrl("https://github.com/MediaBrowser/MediaBrowser", logger); } /// /// Opens the community. /// /// The logger. public static void OpenCommunity(ILogger logger) { OpenUrl("http://mediabrowser3.com/community", logger); } /// /// Opens the web client. /// /// The user manager. /// The configuration manager. /// The app host. /// The logger. 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); } /// /// Opens the dashboard. /// /// The user manager. /// The configuration manager. /// The app host. /// The logger. 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); } /// /// Opens the swagger. /// /// The configuration manager. /// The app host. /// The logger. public static void OpenSwagger(IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger) { OpenUrl("http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" + appHost.WebApplicationName + "/swagger-ui/index.html", logger); } /// /// Opens the standard API documentation. /// /// The configuration manager. /// The app host. /// The logger. public static void OpenStandardApiDocumentation(IServerConfigurationManager configurationManager, IServerApplicationHost appHost, ILogger logger) { OpenUrl("http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" + appHost.WebApplicationName + "/metadata", logger); } /// /// Opens the URL. /// /// The URL. /// The logger. private static void OpenUrl(string url, ILogger logger) { var process = new Process { StartInfo = new ProcessStartInfo { FileName = url }, EnableRaisingEvents = true, }; process.Exited += ProcessExited; try { process.Start(); } catch (Exception ex) { logger.ErrorException("Error launching url: {0}", ex, url); Console.WriteLine("Error launching browser"); Console.WriteLine(ex.Message); #if !__MonoCS__ System.Windows.Forms.MessageBox.Show("There was an error launching your web browser. Please check your default browser settings."); #endif } } /// /// Processes the exited. /// /// The sender. /// The instance containing the event data. private static void ProcessExited(object sender, EventArgs e) { ((Process)sender).Dispose(); } } }