1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-10 04:52:42 +01:00
Radarr/NzbDrone/SysTray/SysTrayApp.cs

81 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Owin;
namespace NzbDrone.SysTray
{
2013-05-11 01:53:50 +02:00
public interface ISystemTrayApp
{
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;
private readonly NotifyIcon _trayIcon = new NotifyIcon();
private readonly ContextMenu _trayMenu = new ContextMenu();
public SystemTrayApp(IProcessProvider processProvider, IHostController hostController)
{
_processProvider = processProvider;
2013-02-19 02:13:42 +01:00
_hostController = hostController;
}
2013-05-11 01:53:50 +02:00
public void Start()
{
_trayMenu.MenuItems.Add("Launch Browser", LaunchBrowser);
_trayMenu.MenuItems.Add("-");
_trayMenu.MenuItems.Add("Exit", OnExit);
2013-03-05 20:58:53 +01:00
_trayIcon.Text = String.Format("NzbDrone - {0}", BuildInfo.Version);
_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);
}
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);
}
}
}