Re-fix for hidden console CPU + added tray icon
New: Tray Icon visible when running without console window
This commit is contained in:
parent
506899730a
commit
08e7490ac5
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,9 @@
|
|||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
|
@ -100,6 +102,10 @@
|
|||
<Compile Include="RestProvider.cs" />
|
||||
<Compile Include="SecurityProvider.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
<Compile Include="SysTray\SysTrayApp.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SysTray\SysTrayProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -110,7 +110,7 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="NzbDrone.ico" />
|
||||
<EmbeddedResource Include="NzbDrone.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="NzbDrone.ico" />
|
||||
<EmbeddedResource Include="NzbDrone.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
|
|
|
@ -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<string> 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:
|
||||
|
|
Loading…
Reference in New Issue