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