1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 01:37:07 +00:00
Sonarr/NzbDrone/SysTray/SysTrayApp.cs

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