From 5cca8bffea339f1043d692f337ab002dbee3a03b Mon Sep 17 00:00:00 2001 From: spookbits <71300703+spooksbit@users.noreply.github.com> Date: Wed, 16 Sep 2020 13:17:14 -0400 Subject: [PATCH 1/4] Removed browser auto-load functionality from the server. Added profiles in launchSettings to start either the web client or the swagger API page. Removed --noautorunwebapp as this is the default functionality. --- CONTRIBUTORS.md | 1 + .../Browser/BrowserLauncher.cs | 51 ------------ .../EntryPoints/StartupWizard.cs | 83 ------------------- .../IStartupOptions.cs | 5 -- Jellyfin.Server/Jellyfin.Server.csproj | 2 +- .../Properties/launchSettings.json | 8 +- Jellyfin.Server/StartupOptions.cs | 4 - .../Configuration/ServerConfiguration.cs | 3 - .../JellyfinApplicationFactory.cs | 3 +- 9 files changed, 10 insertions(+), 150 deletions(-) delete mode 100644 Emby.Server.Implementations/Browser/BrowserLauncher.cs delete mode 100644 Emby.Server.Implementations/EntryPoints/StartupWizard.cs diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f1fe65064b..2ec147ba2f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -103,6 +103,7 @@ - [sl1288](https://github.com/sl1288) - [sorinyo2004](https://github.com/sorinyo2004) - [sparky8251](https://github.com/sparky8251) + - [spookbits](https://github.com/spookbits) - [stanionascu](https://github.com/stanionascu) - [stevehayles](https://github.com/stevehayles) - [SuperSandro2000](https://github.com/SuperSandro2000) diff --git a/Emby.Server.Implementations/Browser/BrowserLauncher.cs b/Emby.Server.Implementations/Browser/BrowserLauncher.cs deleted file mode 100644 index f8108d1c2d..0000000000 --- a/Emby.Server.Implementations/Browser/BrowserLauncher.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; - -namespace Emby.Server.Implementations.Browser -{ - /// - /// Assists in opening application URLs in an external browser. - /// - public static class BrowserLauncher - { - /// - /// Opens the home page of the web client. - /// - /// The app host. - public static void OpenWebApp(IServerApplicationHost appHost) - { - TryOpenUrl(appHost, "/web/index.html"); - } - - /// - /// Opens the swagger API page. - /// - /// The app host. - public static void OpenSwaggerPage(IServerApplicationHost appHost) - { - TryOpenUrl(appHost, "/api-docs/swagger"); - } - - /// - /// Opens the specified URL in an external browser window. Any exceptions will be logged, but ignored. - /// - /// The application host. - /// The URL to open, relative to the server base URL. - private static void TryOpenUrl(IServerApplicationHost appHost, string relativeUrl) - { - try - { - string baseUrl = appHost.GetLocalApiUrl("localhost"); - appHost.LaunchUrl(baseUrl + relativeUrl); - } - catch (Exception ex) - { - var logger = appHost.Resolve>(); - logger?.LogError(ex, "Failed to open browser window with URL {URL}", relativeUrl); - } - } - } -} diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs deleted file mode 100644 index 2e738deeb5..0000000000 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Threading.Tasks; -using Emby.Server.Implementations.Browser; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Extensions; -using MediaBrowser.Controller.Plugins; -using Microsoft.Extensions.Configuration; - -namespace Emby.Server.Implementations.EntryPoints -{ - /// - /// Class StartupWizard. - /// - public sealed class StartupWizard : IServerEntryPoint - { - private readonly IServerApplicationHost _appHost; - private readonly IConfiguration _appConfig; - private readonly IServerConfigurationManager _config; - private readonly IStartupOptions _startupOptions; - - /// - /// Initializes a new instance of the class. - /// - /// The application host. - /// The application configuration. - /// The configuration manager. - /// The application startup options. - public StartupWizard( - IServerApplicationHost appHost, - IConfiguration appConfig, - IServerConfigurationManager config, - IStartupOptions startupOptions) - { - _appHost = appHost; - _appConfig = appConfig; - _config = config; - _startupOptions = startupOptions; - } - - /// - public Task RunAsync() - { - Run(); - return Task.CompletedTask; - } - - private void Run() - { - if (!_appHost.CanLaunchWebBrowser) - { - return; - } - - // Always launch the startup wizard if possible when it has not been completed - if (!_config.Configuration.IsStartupWizardCompleted && _appConfig.HostWebClient()) - { - BrowserLauncher.OpenWebApp(_appHost); - return; - } - - // Do nothing if the web app is configured to not run automatically - if (!_config.Configuration.AutoRunWebApp || _startupOptions.NoAutoRunWebApp) - { - return; - } - - // Launch the swagger page if the web client is not hosted, otherwise open the web client - if (_appConfig.HostWebClient()) - { - BrowserLauncher.OpenWebApp(_appHost); - } - else - { - BrowserLauncher.OpenSwaggerPage(_appHost); - } - } - - /// - public void Dispose() - { - } - } -} diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs index e7e72c686b..4bef59543f 100644 --- a/Emby.Server.Implementations/IStartupOptions.cs +++ b/Emby.Server.Implementations/IStartupOptions.cs @@ -16,11 +16,6 @@ namespace Emby.Server.Implementations /// bool IsService { get; } - /// - /// Gets the value of the --noautorunwebapp command line option. - /// - bool NoAutoRunWebApp { get; } - /// /// Gets the value of the --package-name command line option. /// diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index 0ac309a0b0..b66314a8ea 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -1,4 +1,4 @@ - + diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index b6e2bcf976..ebdd0dedaa 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -2,14 +2,20 @@ "profiles": { "Jellyfin.Server": { "commandName": "Project", + "launchBrowser": true, + "launchUrl": "web", + "applicationUrl": "http://localhost:8096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Jellyfin.Server (nowebclient)": { "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api-docs/swagger", + "applicationUrl": "http://localhost:8096", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development" }, "commandLineArgs": "--nowebclient" } diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs index 41a1430d26..b634340927 100644 --- a/Jellyfin.Server/StartupOptions.cs +++ b/Jellyfin.Server/StartupOptions.cs @@ -63,10 +63,6 @@ namespace Jellyfin.Server [Option("service", Required = false, HelpText = "Run as headless service.")] public bool IsService { get; set; } - /// - [Option("noautorunwebapp", Required = false, HelpText = "Run headless if startup wizard is complete.")] - public bool NoAutoRunWebApp { get; set; } - /// [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")] public string? PackageName { get; set; } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 48d1a7346a..8b78ad842e 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -83,8 +83,6 @@ namespace MediaBrowser.Model.Configuration /// public bool QuickConnectAvailable { get; set; } - public bool AutoRunWebApp { get; set; } - public bool EnableRemoteAccess { get; set; } /// @@ -306,7 +304,6 @@ namespace MediaBrowser.Model.Configuration DisableLiveTvChannelUserDataName = true; EnableNewOmdbSupport = true; - AutoRunWebApp = true; EnableRemoteAccess = true; QuickConnectAvailable = false; diff --git a/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs b/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs index 77f1640fa3..bd3d356870 100644 --- a/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs +++ b/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs @@ -47,8 +47,7 @@ namespace Jellyfin.Api.Tests // Specify the startup command line options var commandLineOpts = new StartupOptions { - NoWebClient = true, - NoAutoRunWebApp = true + NoWebClient = true }; // Use a temporary directory for the application paths From ac32b140122f669e6b8b6b2294b83a96b6842314 Mon Sep 17 00:00:00 2001 From: spooksbit <71300703+spooksbit@users.noreply.github.com> Date: Wed, 16 Sep 2020 15:11:35 -0400 Subject: [PATCH 2/4] Update Jellyfin.Server/Properties/launchSettings.json Co-authored-by: Cody Robibero --- Jellyfin.Server/Properties/launchSettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index ebdd0dedaa..d8be520b7b 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -15,7 +15,7 @@ "launchUrl": "api-docs/swagger", "applicationUrl": "http://localhost:8096", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development" }, "commandLineArgs": "--nowebclient" } From 246ab260f71731c03e8199cbb52e0a7457aaf997 Mon Sep 17 00:00:00 2001 From: spookbits <71300703+spooksbit@users.noreply.github.com> Date: Wed, 16 Sep 2020 17:09:24 -0400 Subject: [PATCH 3/4] Do not implicitly reference ASP.NET Core Analyzers. Also do not explicitly reference AspNetCore.App (fixes compiler warning). --- Jellyfin.Server/Jellyfin.Server.csproj | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index b66314a8ea..ffab18f863 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -13,6 +13,7 @@ true true enable + true @@ -23,10 +24,6 @@ - - - - From c912093579952e3cb7f4b4563975024c9e27a097 Mon Sep 17 00:00:00 2001 From: spookbits <71300703+spooksbit@users.noreply.github.com> Date: Fri, 25 Sep 2020 21:52:37 -0400 Subject: [PATCH 4/4] Created a separate API Docs profile to launch the browser at the API docs, and the nowebclient profile no longer launches the browser at all. Don't point to web in the client because it won't redirect properly. Modified the vscode launch.json to automatically launch the browser when debugging the first configuration. The --- .vscode/launch.json | 6 +++++- Jellyfin.Server/Properties/launchSettings.json | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bf1bd65cbe..05f60cfa69 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,11 @@ "cwd": "${workspaceFolder}/Jellyfin.Server", "console": "internalConsole", "stopAtEntry": false, - "internalConsoleOptions": "openOnSessionStart" + "internalConsoleOptions": "openOnSessionStart", + "serverReadyAction": { + "action": "openExternally", + "pattern": "Overriding address\\(es\\) \\'(https?:\\S+)\\'", + } }, { "name": ".NET Core Launch (nowebclient)", diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index d8be520b7b..20d432afc4 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -3,13 +3,19 @@ "Jellyfin.Server": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "web", "applicationUrl": "http://localhost:8096", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Jellyfin.Server (nowebclient)": { + "commandName": "Project", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "commandLineArgs": "--nowebclient" + }, + "Jellyfin.Server (API Docs)": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api-docs/swagger",