2013-01-30 02:21:45 +00:00
|
|
|
|
using System;
|
2013-08-06 07:13:26 +00:00
|
|
|
|
using System.ComponentModel;
|
2013-01-30 02:21:45 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Reflection;
|
2013-08-06 07:13:26 +00:00
|
|
|
|
using System.Threading;
|
2013-01-30 02:21:45 +00:00
|
|
|
|
using System.Windows.Forms;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-06-28 00:04:52 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-04 21:09:25 +00:00
|
|
|
|
using NzbDrone.Owin;
|
2013-01-30 02:21:45 +00:00
|
|
|
|
|
2013-05-04 21:09:25 +00:00
|
|
|
|
namespace NzbDrone.SysTray
|
2013-01-30 02:21:45 +00:00
|
|
|
|
{
|
2013-05-10 23:53:50 +00:00
|
|
|
|
public interface ISystemTrayApp
|
2013-01-30 02:21:45 +00:00
|
|
|
|
{
|
2013-05-10 23:53:50 +00:00
|
|
|
|
void Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SystemTrayApp : Form, ISystemTrayApp
|
|
|
|
|
{
|
|
|
|
|
private readonly IProcessProvider _processProvider;
|
2013-02-19 01:57:08 +00:00
|
|
|
|
private readonly IHostController _hostController;
|
2013-01-30 02:21:45 +00:00
|
|
|
|
|
|
|
|
|
private readonly NotifyIcon _trayIcon = new NotifyIcon();
|
|
|
|
|
private readonly ContextMenu _trayMenu = new ContextMenu();
|
|
|
|
|
|
2013-06-28 00:04:52 +00:00
|
|
|
|
public SystemTrayApp(IProcessProvider processProvider, IHostController hostController)
|
2013-01-30 02:21:45 +00:00
|
|
|
|
{
|
|
|
|
|
_processProvider = processProvider;
|
2013-02-19 01:13:42 +00:00
|
|
|
|
_hostController = hostController;
|
2013-01-30 02:21:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-10 23:53:50 +00:00
|
|
|
|
public void Start()
|
2013-01-30 02:21:45 +00:00
|
|
|
|
{
|
2013-08-06 07:13:26 +00:00
|
|
|
|
Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
|
|
|
|
|
Application.ApplicationExit += new EventHandler(OnApplicationExit);
|
|
|
|
|
|
2013-01-30 02:21:45 +00:00
|
|
|
|
_trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser);
|
|
|
|
|
_trayMenu.MenuItems.Add("-");
|
|
|
|
|
_trayMenu.MenuItems.Add("Exit", OnExit);
|
2013-03-05 19:58:53 +00:00
|
|
|
|
|
2013-06-28 00:04:52 +00:00
|
|
|
|
_trayIcon.Text = String.Format("NzbDrone - {0}", BuildInfo.Version);
|
2013-01-30 02:21:45 +00:00
|
|
|
|
_trayIcon.Icon = new Icon(Assembly.GetEntryAssembly().GetManifestResourceStream("NzbDrone.NzbDrone.ico"));
|
|
|
|
|
|
|
|
|
|
_trayIcon.ContextMenu = _trayMenu;
|
|
|
|
|
_trayIcon.Visible = true;
|
2013-05-10 23:53:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application.Run(this);
|
2013-01-30 02:21:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 07:13:26 +00:00
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DisposeTrayIcon();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-30 02:21:45 +00:00
|
|
|
|
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 01:13:42 +00:00
|
|
|
|
_processProvider.Start(_hostController.AppUrl);
|
2013-01-30 02:21:45 +00:00
|
|
|
|
}
|
2013-08-06 07:13:26 +00:00
|
|
|
|
|
|
|
|
|
private void OnApplicationExit(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DisposeTrayIcon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnThreadException(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DisposeTrayIcon();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeTrayIcon()
|
|
|
|
|
{
|
|
|
|
|
_trayIcon.Visible = false;
|
|
|
|
|
_trayIcon.Icon = null;
|
|
|
|
|
_trayIcon.Visible = false;
|
|
|
|
|
_trayIcon.Dispose();
|
|
|
|
|
}
|
2013-01-30 02:21:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|