StartupWizard.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. private readonly IStartupOptions _startupOptions;
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="StartupWizard"/> class.
  21. /// </summary>
  22. /// <param name="appHost">The application host.</param>
  23. /// <param name="appConfig">The application configuration.</param>
  24. /// <param name="config">The configuration manager.</param>
  25. /// <param name="startupOptions">The application startup options.</param>
  26. public StartupWizard(
  27. IServerApplicationHost appHost,
  28. IConfiguration appConfig,
  29. IServerConfigurationManager config,
  30. IStartupOptions startupOptions)
  31. {
  32. _appHost = appHost;
  33. _appConfig = appConfig;
  34. _config = config;
  35. _startupOptions = startupOptions;
  36. }
  37. /// <inheritdoc />
  38. public Task RunAsync()
  39. {
  40. Run();
  41. return Task.CompletedTask;
  42. }
  43. private void Run()
  44. {
  45. if (!_appHost.CanLaunchWebBrowser)
  46. {
  47. return;
  48. }
  49. // Always launch the startup wizard if possible when it has not been completed
  50. if (!_config.Configuration.IsStartupWizardCompleted && _appConfig.HostWebClient())
  51. {
  52. BrowserLauncher.OpenWebApp(_appHost);
  53. return;
  54. }
  55. // Do nothing if the web app is configured to not run automatically
  56. if (!_config.Configuration.AutoRunWebApp || _startupOptions.NoAutoRunWebApp)
  57. {
  58. return;
  59. }
  60. // Launch the swagger page if the web client is not hosted, otherwise open the web client
  61. if (_appConfig.HostWebClient())
  62. {
  63. BrowserLauncher.OpenWebApp(_appHost);
  64. }
  65. else
  66. {
  67. BrowserLauncher.OpenSwaggerPage(_appHost);
  68. }
  69. }
  70. /// <inheritdoc />
  71. public void Dispose()
  72. {
  73. }
  74. }
  75. }