StartupWizard.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Threading.Tasks;
  2. using Emby.Server.Implementations.Browser;
  3. using MediaBrowser.Controller;
  4. using MediaBrowser.Controller.Configuration;
  5. using MediaBrowser.Controller.Extensions;
  6. using MediaBrowser.Controller.Plugins;
  7. using Microsoft.Extensions.Configuration;
  8. namespace Emby.Server.Implementations.EntryPoints
  9. {
  10. /// <summary>
  11. /// Class StartupWizard.
  12. /// </summary>
  13. public sealed class StartupWizard : IServerEntryPoint
  14. {
  15. private readonly IServerApplicationHost _appHost;
  16. private readonly IConfiguration _appConfig;
  17. private readonly IServerConfigurationManager _config;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="StartupWizard"/> class.
  20. /// </summary>
  21. /// <param name="appHost">The application host.</param>
  22. /// <param name="config">The configuration manager.</param>
  23. public StartupWizard(IServerApplicationHost appHost, IConfiguration appConfig, IServerConfigurationManager config)
  24. {
  25. _appHost = appHost;
  26. _appConfig = appConfig;
  27. _config = config;
  28. }
  29. /// <inheritdoc />
  30. public Task RunAsync()
  31. {
  32. Run();
  33. return Task.CompletedTask;
  34. }
  35. private void Run()
  36. {
  37. if (!_appHost.CanLaunchWebBrowser)
  38. {
  39. return;
  40. }
  41. // Always launch the startup wizard if possible when it has not been completed
  42. if (!_config.Configuration.IsStartupWizardCompleted && _appConfig.HostWebClient())
  43. {
  44. BrowserLauncher.OpenWebApp(_appHost);
  45. return;
  46. }
  47. // Do nothing if the web app is configured to not run automatically
  48. var options = ((ApplicationHost)_appHost).StartupOptions;
  49. if (!_config.Configuration.AutoRunWebApp || options.NoAutoRunWebApp)
  50. {
  51. return;
  52. }
  53. // Launch the swagger page if the web client is not hosted, otherwise open the web client
  54. if (_appConfig.HostWebClient())
  55. {
  56. BrowserLauncher.OpenWebApp(_appHost);
  57. }
  58. else
  59. {
  60. BrowserLauncher.OpenSwaggerPage(_appHost);
  61. }
  62. }
  63. /// <inheritdoc />
  64. public void Dispose()
  65. {
  66. }
  67. }
  68. }