From 4f09c1e06dab7cc8b260129648f5a54c77b8a4f9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 23 Nov 2017 10:46:16 -0500 Subject: reduce dlna chatter --- MediaBrowser.Controller/IServerApplicationHost.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Controller/IServerApplicationHost.cs') diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs index e9f7d59321..380be068e5 100644 --- a/MediaBrowser.Controller/IServerApplicationHost.cs +++ b/MediaBrowser.Controller/IServerApplicationHost.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using MediaBrowser.Model.Net; +using System.Threading; namespace MediaBrowser.Controller { @@ -19,7 +20,7 @@ namespace MediaBrowser.Controller /// Gets the system info. /// /// SystemInfo. - Task GetSystemInfo(); + Task GetSystemInfo(CancellationToken cancellationToken); /// /// Gets a value indicating whether [supports automatic run at startup]. @@ -61,13 +62,13 @@ namespace MediaBrowser.Controller /// Gets the local ip address. /// /// The local ip address. - Task> GetLocalIpAddresses(); + Task> GetLocalIpAddresses(CancellationToken cancellationToken); /// /// Gets the local API URL. /// /// The local API URL. - Task GetLocalApiUrl(); + Task GetLocalApiUrl(CancellationToken cancellationToken); /// /// Gets the local API URL. -- cgit v1.2.3 From d7a1a87009eed638d28d070e6a47c8a5bee38c2e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 1 Dec 2017 12:03:40 -0500 Subject: reduce work done by system info endpoints --- Emby.Server.Implementations/ApplicationHost.cs | 17 ++++++++++++++++- .../EntryPoints/StartupWizard.cs | 7 ++++++- .../Networking/NetworkManager.cs | 19 ++++++------------- .../Session/HttpSessionController.cs | 2 +- Emby.Server.Implementations/Session/SessionManager.cs | 4 +--- .../Session/WebSocketController.cs | 6 +++--- MediaBrowser.Api/System/SystemService.cs | 14 ++------------ MediaBrowser.Controller/IServerApplicationHost.cs | 2 ++ MediaBrowser.Controller/Session/ISessionController.cs | 5 +---- 9 files changed, 38 insertions(+), 38 deletions(-) (limited to 'MediaBrowser.Controller/IServerApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9a159194ee..abc6c35666 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -361,7 +361,7 @@ namespace Emby.Server.Implementations protected IAuthService AuthService { get; private set; } - protected readonly StartupOptions StartupOptions; + public StartupOptions StartupOptions { get; private set; } protected readonly string ReleaseAssetFilename; internal IPowerManagement PowerManagement { get; private set; } @@ -1950,6 +1950,21 @@ namespace Emby.Server.Implementations }; } + public async Task GetPublicSystemInfo(CancellationToken cancellationToken) + { + var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + + return new PublicSystemInfo + { + Version = ApplicationVersion.ToString(), + Id = SystemId, + OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(), + WanAddress = ConnectManager.WanApiAddress, + ServerName = FriendlyName, + LocalAddress = localAddress + }; + } + public bool EnableHttps { get diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 8d13557952..746edf9e7b 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -41,7 +41,12 @@ namespace Emby.Server.Implementations.EntryPoints } else if (_config.Configuration.IsStartupWizardCompleted) { - BrowserLauncher.OpenDashboardPage("index.html", _appHost); + var options = ((ApplicationHost)_appHost).StartupOptions; + + if (!options.ContainsOption("-service") && !options.ContainsOption("-nobrowser")) + { + BrowserLauncher.OpenDashboardPage("index.html", _appHost); + } } } diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 30a3ff9e86..60da8a0124 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -11,15 +11,12 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; -using System.Threading; namespace Emby.Server.Implementations.Networking { public class NetworkManager : INetworkManager { protected ILogger Logger { get; private set; } - private DateTime _lastRefresh; - private int NetworkCacheMinutes = 720; public event EventHandler NetworkChanged; @@ -33,7 +30,6 @@ namespace Emby.Server.Implementations.Networking } catch (Exception ex) { - NetworkCacheMinutes = 15; Logger.ErrorException("Error binding to NetworkAddressChanged event", ex); } @@ -43,7 +39,6 @@ namespace Emby.Server.Implementations.Networking } catch (Exception ex) { - NetworkCacheMinutes = 15; Logger.ErrorException("Error binding to NetworkChange_NetworkAvailabilityChanged event", ex); } } @@ -51,19 +46,21 @@ namespace Emby.Server.Implementations.Networking private void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e) { Logger.Debug("NetworkAvailabilityChanged"); - _lastRefresh = DateTime.MinValue; OnNetworkChanged(); } private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e) { Logger.Debug("NetworkAddressChanged"); - _lastRefresh = DateTime.MinValue; OnNetworkChanged(); } private void OnNetworkChanged() { + lock (_localIpAddressSyncLock) + { + _localIpAddresses = null; + } if (NetworkChanged != null) { NetworkChanged(this, EventArgs.Empty); @@ -77,20 +74,16 @@ namespace Emby.Server.Implementations.Networking { lock (_localIpAddressSyncLock) { - var forceRefresh = (DateTime.UtcNow - _lastRefresh).TotalMinutes >= NetworkCacheMinutes; - - if (_localIpAddresses == null || forceRefresh) + if (_localIpAddresses == null) { var addresses = GetLocalIpAddressesInternal().Result.Select(ToIpAddressInfo).ToList(); _localIpAddresses = addresses; - _lastRefresh = DateTime.UtcNow; return addresses; } + return _localIpAddresses; } - - return _localIpAddresses; } private async Task> GetLocalIpAddressesInternal() diff --git a/Emby.Server.Implementations/Session/HttpSessionController.cs b/Emby.Server.Implementations/Session/HttpSessionController.cs index e852544204..6725cd7af6 100644 --- a/Emby.Server.Implementations/Session/HttpSessionController.cs +++ b/Emby.Server.Implementations/Session/HttpSessionController.cs @@ -151,7 +151,7 @@ namespace Emby.Server.Implementations.Session return SendMessage("LibraryChanged", info, cancellationToken); } - public Task SendRestartRequiredNotification(SystemInfo info, CancellationToken cancellationToken) + public Task SendRestartRequiredNotification(CancellationToken cancellationToken) { return SendMessage("RestartRequired", cancellationToken); } diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index f49251da53..6b70f2cda3 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1182,13 +1182,11 @@ namespace Emby.Server.Implementations.Session { var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList(); - var info = await _appHost.GetSystemInfo(cancellationToken).ConfigureAwait(false); - var tasks = sessions.Select(session => Task.Run(async () => { try { - await session.SessionController.SendRestartRequiredNotification(info, cancellationToken).ConfigureAwait(false); + await session.SessionController.SendRestartRequiredNotification(cancellationToken).ConfigureAwait(false); } catch (Exception ex) { diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.cs index ee9ee8969e..b13eb6116d 100644 --- a/Emby.Server.Implementations/Session/WebSocketController.cs +++ b/Emby.Server.Implementations/Session/WebSocketController.cs @@ -145,12 +145,12 @@ namespace Emby.Server.Implementations.Session /// The information. /// The cancellation token. /// Task. - public Task SendRestartRequiredNotification(SystemInfo info, CancellationToken cancellationToken) + public Task SendRestartRequiredNotification(CancellationToken cancellationToken) { - return SendMessagesInternal(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "RestartRequired", - Data = info + Data = string.Empty }, cancellationToken); } diff --git a/MediaBrowser.Api/System/SystemService.cs b/MediaBrowser.Api/System/SystemService.cs index 6de7dd98ba..c0bbf70ead 100644 --- a/MediaBrowser.Api/System/SystemService.cs +++ b/MediaBrowser.Api/System/SystemService.cs @@ -172,19 +172,9 @@ namespace MediaBrowser.Api.System public async Task Get(GetPublicSystemInfo request) { - var result = await _appHost.GetSystemInfo(CancellationToken.None).ConfigureAwait(false); + var result = await _appHost.GetPublicSystemInfo(CancellationToken.None).ConfigureAwait(false); - var publicInfo = new PublicSystemInfo - { - Id = result.Id, - ServerName = result.ServerName, - Version = result.Version, - LocalAddress = result.LocalAddress, - WanAddress = result.WanAddress, - OperatingSystem = result.OperatingSystem - }; - - return ToOptimizedResult(publicInfo); + return ToOptimizedResult(result); } /// diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs index 380be068e5..89ae85b508 100644 --- a/MediaBrowser.Controller/IServerApplicationHost.cs +++ b/MediaBrowser.Controller/IServerApplicationHost.cs @@ -22,6 +22,8 @@ namespace MediaBrowser.Controller /// SystemInfo. Task GetSystemInfo(CancellationToken cancellationToken); + Task GetPublicSystemInfo(CancellationToken cancellationToken); + /// /// Gets a value indicating whether [supports automatic run at startup]. /// diff --git a/MediaBrowser.Controller/Session/ISessionController.cs b/MediaBrowser.Controller/Session/ISessionController.cs index f8a6ed1fc1..0d8c207b61 100644 --- a/MediaBrowser.Controller/Session/ISessionController.cs +++ b/MediaBrowser.Controller/Session/ISessionController.cs @@ -55,10 +55,7 @@ namespace MediaBrowser.Controller.Session /// /// Sends the restart required message. /// - /// The information. - /// The cancellation token. - /// Task. - Task SendRestartRequiredNotification(SystemInfo info, CancellationToken cancellationToken); + Task SendRestartRequiredNotification(CancellationToken cancellationToken); /// /// Sends the user data change info. -- cgit v1.2.3 From 8717f81bf406fb4f78adf117fd380f37bd6a98fc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 3 Dec 2017 17:14:35 -0500 Subject: Add setting to auto-run web app when server starts --- Emby.Server.Implementations/ApplicationHost.cs | 37 ++++++++++++++++++---- .../EntryPoints/StartupWizard.cs | 9 ++++-- MediaBrowser.Api/StartupWizardService.cs | 1 + MediaBrowser.Controller/IServerApplicationHost.cs | 4 ++- .../Configuration/ServerConfiguration.cs | 2 ++ MediaBrowser.Model/System/SystemInfo.cs | 2 ++ 6 files changed, 45 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.Controller/IServerApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index abc6c35666..26450c06ca 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -148,6 +148,34 @@ namespace Emby.Server.Implementations } } + public virtual bool CanLaunchWebBrowser + { + get + { + if (!Environment.UserInteractive) + { + return false; + } + + if (StartupOptions.ContainsOption("-service")) + { + return false; + } + + if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows) + { + return true; + } + + if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX) + { + return true; + } + + return false; + } + } + /// /// Occurs when [has pending restart changed]. /// @@ -1936,6 +1964,7 @@ namespace Emby.Server.Implementations OperatingSystemDisplayName = OperatingSystemDisplayName, CanSelfRestart = CanSelfRestart, CanSelfUpdate = CanSelfUpdate, + CanLaunchWebBrowser = CanLaunchWebBrowser, WanAddress = ConnectManager.WanApiAddress, HasUpdateAvailable = HasUpdateAvailable, SupportsAutoRunAtStartup = SupportsAutoRunAtStartup, @@ -2358,13 +2387,7 @@ namespace Emby.Server.Implementations public virtual void LaunchUrl(string url) { - if (EnvironmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows && - EnvironmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.OSX) - { - throw new NotSupportedException(); - } - - if (!Environment.UserInteractive) + if (!CanLaunchWebBrowser) { throw new NotSupportedException(); } diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 746edf9e7b..103b4b321e 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -35,15 +35,20 @@ namespace Emby.Server.Implementations.EntryPoints /// public void Run() { + if (!_appHost.CanLaunchWebBrowser) + { + return; + } + if (_appHost.IsFirstRun) { BrowserLauncher.OpenDashboardPage("wizardstart.html", _appHost); } - else if (_config.Configuration.IsStartupWizardCompleted) + else if (_config.Configuration.IsStartupWizardCompleted && _config.Configuration.AutoRunWebApp) { var options = ((ApplicationHost)_appHost).StartupOptions; - if (!options.ContainsOption("-service") && !options.ContainsOption("-nobrowser")) + if (!options.ContainsOption("-noautorunwebapp")) { BrowserLauncher.OpenDashboardPage("index.html", _appHost); } diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 54e4657c11..c6345c17f4 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -67,6 +67,7 @@ namespace MediaBrowser.Api public void Post(ReportStartupWizardComplete request) { _config.Configuration.IsStartupWizardCompleted = true; + _config.Configuration.AutoRunWebApp = true; _config.SetOptimalValues(); _config.SaveConfiguration(); diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs index 89ae85b508..3f7f8248b5 100644 --- a/MediaBrowser.Controller/IServerApplicationHost.cs +++ b/MediaBrowser.Controller/IServerApplicationHost.cs @@ -29,7 +29,9 @@ namespace MediaBrowser.Controller /// /// true if [supports automatic run at startup]; otherwise, false. bool SupportsAutoRunAtStartup { get; } - + + bool CanLaunchWebBrowser { get; } + /// /// Gets the HTTP server port. /// diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index f2c3b7cc8a..41ed0648a6 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -61,6 +61,8 @@ namespace MediaBrowser.Model.Configuration /// true if this instance is port authorized; otherwise, false. public bool IsPortAuthorized { get; set; } + public bool AutoRunWebApp { get; set; } + /// /// Gets or sets a value indicating whether [enable case sensitive item ids]. /// diff --git a/MediaBrowser.Model/System/SystemInfo.cs b/MediaBrowser.Model/System/SystemInfo.cs index b61d637293..9ed0f904f0 100644 --- a/MediaBrowser.Model/System/SystemInfo.cs +++ b/MediaBrowser.Model/System/SystemInfo.cs @@ -68,6 +68,8 @@ namespace MediaBrowser.Model.System /// true if this instance can self update; otherwise, false. public bool CanSelfUpdate { get; set; } + public bool CanLaunchWebBrowser { get; set; } + /// /// Gets or sets plugin assemblies that failed to load. /// -- cgit v1.2.3