2013-01-30 03:21:45 +01:00
|
|
|
|
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 ProcessProvider _processProvider;
|
2013-02-19 02:57:08 +01:00
|
|
|
|
private readonly IHostController _hostController;
|
2013-01-30 03:21:45 +01:00
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
|
|
|
|
|
|
|
|
|
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
|
|
|
|
private readonly ContextMenu _trayMenu = new ContextMenu();
|
|
|
|
|
|
2013-03-05 20:58:53 +01:00
|
|
|
|
public SysTrayApp(ProcessProvider processProvider, IHostController hostController, EnvironmentProvider environmentProvider)
|
2013-01-30 03:21:45 +01:00
|
|
|
|
{
|
|
|
|
|
_processProvider = processProvider;
|
2013-02-19 02:13:42 +01:00
|
|
|
|
_hostController = hostController;
|
2013-01-30 03:21:45 +01:00
|
|
|
|
_environmentProvider = environmentProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SysTrayApp()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Create()
|
|
|
|
|
{
|
|
|
|
|
_trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser);
|
|
|
|
|
_trayMenu.MenuItems.Add("-");
|
|
|
|
|
_trayMenu.MenuItems.Add("Exit", OnExit);
|
2013-03-05 20:58:53 +01:00
|
|
|
|
|
2013-01-30 03:21:45 +01:00
|
|
|
|
_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)
|
|
|
|
|
{
|
2013-02-19 02:13:42 +01:00
|
|
|
|
_processProvider.Start(_hostController.AppUrl);
|
2013-01-30 03:21:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|