1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Common/SysTray/SysTrayApp.cs
Mark McDowall 08e7490ac5 Re-fix for hidden console CPU + added tray icon
New: Tray Icon visible when running without console window
2013-01-29 18:23:17 -08:00

79 lines
2.3 KiB
C#

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);
}
}
}