SystemTrayMenu/UserInterface/AppNotifyIcon.cs

50 lines
1.5 KiB
C#
Raw Normal View History

// <copyright file="AppNotifyIcon.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.UserInterface
{
using System;
using System.Windows.Threading;
using H.NotifyIcon.Core;
internal class AppNotifyIcon : IDisposable
{
private readonly Dispatcher dispatchter = Dispatcher.CurrentDispatcher;
private readonly TrayIconWithContextMenu notifyIcon = new ();
public AppNotifyIcon()
{
notifyIcon.ToolTip = "SystemTrayMenu";
notifyIcon.Icon = Config.GetAppIcon().Handle;
2022-12-06 09:46:53 +13:00
notifyIcon.ContextMenu = new AppContextMenu().Create();
notifyIcon.MessageWindow.MouseEventReceived += (sender, e) =>
{
if (e.MouseEvent == MouseEvent.IconLeftMouseUp ||
e.MouseEvent == MouseEvent.IconLeftDoubleClick)
{
dispatchter.Invoke(() => Click?.Invoke());
}
};
notifyIcon.Create();
}
2022-12-05 13:27:57 +13:00
public event Action? Click;
public void Dispose()
{
notifyIcon.Icon = IntPtr.Zero;
notifyIcon.Dispose();
}
public void LoadingStart()
{
notifyIcon.Icon = Resources.StaticResources.LoadingIcon.Handle;
}
public void LoadingStop()
{
notifyIcon.Icon = Config.GetAppIcon().Handle;
}
}
2019-07-05 05:04:14 +12:00
}