SystemTrayMenu/UserInterface/AppNotifyIcon.cs

72 lines
1.9 KiB
C#
Raw Normal View History

// <copyright file="AppNotifyIcon.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
2019-07-05 05:04:14 +12:00
namespace SystemTrayMenu.UserInterface
2019-07-05 05:04:14 +12:00
{
using System;
using System.Windows.Forms;
using SystemTrayMenu.Helper;
using SystemTrayMenu.Utilities;
internal class AppNotifyIcon : IDisposable
2019-07-05 05:04:14 +12:00
{
private readonly NotifyIcon notifyIcon = new();
2019-07-05 05:04:14 +12:00
public AppNotifyIcon()
2019-07-05 05:04:14 +12:00
{
notifyIcon.Text = "SystemTrayMenu";
notifyIcon.Icon = Config.GetAppIcon();
notifyIcon.Visible = true;
AppContextMenu contextMenus = new();
2019-07-05 05:04:14 +12:00
contextMenus.ClickedOpenLog += ClickedOpenLog;
void ClickedOpenLog()
{
OpenLog?.Invoke();
2019-07-05 05:04:14 +12:00
}
notifyIcon.ContextMenuStrip = contextMenus.Create();
notifyIcon.MouseClick += NotifyIcon_MouseClick;
void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{
VerifyClick(e);
2019-07-05 05:04:14 +12:00
}
2019-07-05 05:04:14 +12:00
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
VerifyClick(e);
}
}
public event Action Click;
public event Action OpenLog;
2019-07-05 05:04:14 +12:00
public void Dispose()
{
notifyIcon.Icon = null;
notifyIcon.Dispose();
}
public void LoadingStart()
2019-07-05 05:04:14 +12:00
{
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
2019-07-05 05:04:14 +12:00
}
public void LoadingStop()
{
notifyIcon.Icon = Config.GetAppIcon();
2019-07-05 05:04:14 +12:00
}
private void VerifyClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Click?.Invoke();
}
}
2019-07-05 05:04:14 +12:00
}
}