2022-11-20 17:47:28 +00:00
|
|
|
using System;
|
2013-11-26 02:46:12 +00:00
|
|
|
using NLog;
|
2013-11-26 06:53:36 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-11-26 02:46:12 +00:00
|
|
|
using NzbDrone.Common.Processes;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
2022-11-20 17:47:28 +00:00
|
|
|
namespace NzbDrone.Host
|
2013-11-26 02:46:12 +00:00
|
|
|
{
|
|
|
|
public interface IBrowserService
|
|
|
|
{
|
|
|
|
void LaunchWebUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BrowserService : IBrowserService
|
|
|
|
{
|
|
|
|
private readonly IProcessProvider _processProvider;
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2013-11-26 06:53:36 +00:00
|
|
|
private readonly IRuntimeInfo _runtimeInfo;
|
2013-11-26 02:46:12 +00:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-11-26 06:53:36 +00:00
|
|
|
public BrowserService(IProcessProvider processProvider, IConfigFileProvider configFileProvider, IRuntimeInfo runtimeInfo, Logger logger)
|
2013-11-26 02:46:12 +00:00
|
|
|
{
|
|
|
|
_processProvider = processProvider;
|
|
|
|
_configFileProvider = configFileProvider;
|
2013-11-26 06:53:36 +00:00
|
|
|
_runtimeInfo = runtimeInfo;
|
2013-11-26 02:46:12 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void LaunchWebUI()
|
|
|
|
{
|
|
|
|
var url = string.Format("http://localhost:{0}", _configFileProvider.Port);
|
|
|
|
try
|
|
|
|
{
|
2013-11-26 06:53:36 +00:00
|
|
|
if (_runtimeInfo.IsUserInteractive)
|
|
|
|
{
|
|
|
|
_logger.Info("Starting default browser. {0}", url);
|
|
|
|
_processProvider.OpenDefaultBrowser(url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-26 21:03:07 +00:00
|
|
|
_logger.Debug("non-interactive runtime. Won't attempt to open browser.");
|
2013-11-26 06:53:36 +00:00
|
|
|
}
|
2013-11-26 02:46:12 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2016-02-11 21:13:42 +00:00
|
|
|
_logger.Error(e, "Couldn't open default browser to " + url);
|
2013-11-26 02:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-22 21:24:10 +00:00
|
|
|
}
|