diff --git a/NzbDrone.Common/ConsoleProvider.cs b/NzbDrone.Common/ConsoleProvider.cs
index 3a36b83e1..094c4b9ba 100644
--- a/NzbDrone.Common/ConsoleProvider.cs
+++ b/NzbDrone.Common/ConsoleProvider.cs
@@ -1,17 +1,22 @@
using System;
using System.Diagnostics;
+using System.IO;
using System.Threading;
namespace NzbDrone.Common
{
public class ConsoleProvider
{
+ public static bool IsConsoleApplication
+ {
+ get { return Console.In != StreamReader.Null; }
+ }
+
public virtual void WaitForClose()
{
while (true)
{
Console.ReadLine();
- Thread.Sleep(250);
}
}
diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj
index c7a29d920..69c667320 100644
--- a/NzbDrone.Common/NzbDrone.Common.csproj
+++ b/NzbDrone.Common/NzbDrone.Common.csproj
@@ -74,7 +74,9 @@
+
+
@@ -100,6 +102,10 @@
+
+ Form
+
+
diff --git a/NzbDrone.Common/SysTray/SysTrayApp.cs b/NzbDrone.Common/SysTray/SysTrayApp.cs
new file mode 100644
index 000000000..d50ca2f71
--- /dev/null
+++ b/NzbDrone.Common/SysTray/SysTrayApp.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Drawing;
+using System.Linq;
+using System.Reflection;
+using System.Windows.Forms;
+
+namespace NzbDrone.Common.SysTray
+{
+ public class SysTrayApp : Form
+ {
+ private readonly ConfigFileProvider _configFileProvider;
+ private readonly ProcessProvider _processProvider;
+ private readonly IISProvider _iisProvider;
+ private readonly EnvironmentProvider _environmentProvider;
+
+ private readonly NotifyIcon _trayIcon = new NotifyIcon();
+ private readonly ContextMenu _trayMenu = new ContextMenu();
+
+ public SysTrayApp(ConfigFileProvider configFileProvider, ProcessProvider processProvider,
+ IISProvider iisProvider, EnvironmentProvider environmentProvider)
+ {
+ _configFileProvider = configFileProvider;
+ _processProvider = processProvider;
+ _iisProvider = iisProvider;
+ _environmentProvider = environmentProvider;
+ }
+
+ public SysTrayApp()
+ {
+ }
+
+ public void Create()
+ {
+ _trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser);
+ _trayMenu.MenuItems.Add("-");
+ _trayMenu.MenuItems.Add("Exit", OnExit);
+
+ _trayIcon.Text = String.Format("NzbDrone - {0}", _environmentProvider.Version);
+ _trayIcon.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("NzbDrone.NzbDrone.ico"));
+
+ _trayIcon.ContextMenu = _trayMenu;
+ _trayIcon.Visible = true;
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ Console.WriteLine("Closing");
+ base.OnClosed(e);
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ Visible = false;
+ ShowInTaskbar = false;
+
+ base.OnLoad(e);
+ }
+
+ protected override void Dispose(bool isDisposing)
+ {
+ if (isDisposing)
+ {
+ _trayIcon.Dispose();
+ }
+
+ base.Dispose(isDisposing);
+ }
+
+ private void OnExit(object sender, EventArgs e)
+ {
+ Application.Exit();
+ }
+
+ private void LaunchBrowser(object sender, EventArgs e)
+ {
+ _processProvider.Start(_iisProvider.AppUrl);
+ }
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone.Common/SysTray/SysTrayProvider.cs b/NzbDrone.Common/SysTray/SysTrayProvider.cs
new file mode 100644
index 000000000..e3b0057e1
--- /dev/null
+++ b/NzbDrone.Common/SysTray/SysTrayProvider.cs
@@ -0,0 +1,26 @@
+using System.Linq;
+using System.Windows.Forms;
+
+namespace NzbDrone.Common.SysTray
+{
+ public class SysTrayProvider
+ {
+ private readonly SysTrayApp _sysTrayApp;
+
+ public SysTrayProvider(SysTrayApp sysTrayApp)
+ {
+ _sysTrayApp = sysTrayApp;
+ }
+
+ public SysTrayProvider()
+ {
+ }
+
+ public virtual void Start()
+ {
+ _sysTrayApp.Create();
+
+ Application.Run(_sysTrayApp);
+ }
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone/NzbDrone.Console.csproj b/NzbDrone/NzbDrone.Console.csproj
index e3766d1bd..48b2d4f78 100644
--- a/NzbDrone/NzbDrone.Console.csproj
+++ b/NzbDrone/NzbDrone.Console.csproj
@@ -110,7 +110,7 @@
-
+
diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj
index 47b9e44b9..913092971 100644
--- a/NzbDrone/NzbDrone.csproj
+++ b/NzbDrone/NzbDrone.csproj
@@ -106,7 +106,7 @@
-
+
diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs
index c4c34ef17..82505330e 100644
--- a/NzbDrone/Router.cs
+++ b/NzbDrone/Router.cs
@@ -2,9 +2,12 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using System.Net.Mime;
using NLog;
using NzbDrone.Common;
+using NzbDrone.Common.SysTray;
using NzbDrone.Model;
+using NzbDrone.Providers;
namespace NzbDrone
{
@@ -17,16 +20,18 @@ namespace NzbDrone
private readonly ConsoleProvider _consoleProvider;
private readonly EnvironmentProvider _environmentProvider;
private readonly ProcessProvider _processProvider;
+ private readonly SysTrayProvider _sysTrayProvider;
public Router(ApplicationServer applicationServer, ServiceProvider serviceProvider,
ConsoleProvider consoleProvider, EnvironmentProvider environmentProvider,
- ProcessProvider processProvider)
+ ProcessProvider processProvider, SysTrayProvider sysTrayProvider)
{
_applicationServer = applicationServer;
_serviceProvider = serviceProvider;
_consoleProvider = consoleProvider;
_environmentProvider = environmentProvider;
_processProvider = processProvider;
+ _sysTrayProvider = sysTrayProvider;
}
public void Route(IEnumerable args)
@@ -56,7 +61,14 @@ namespace NzbDrone
{
logger.Trace("Console selected");
_applicationServer.Start();
- _consoleProvider.WaitForClose();
+ if(ConsoleProvider.IsConsoleApplication)
+ _consoleProvider.WaitForClose();
+
+ else
+ {
+ _sysTrayProvider.Start();
+ }
+
break;
}
case ApplicationMode.InstallService: