SystemTrayMenu/UserInterface/AppNotifyIcon.cs
Peter Kirmeier 026ab9a982 Replace Hardcodet.NotifyIcon.Wpf v1.1.0 with H.NotifyIcon v2.0.108
The former is no longer maintained and the new project is base on the former one.
The new one should also be usable for other platforms.
2023-04-30 21:10:55 +02:00

51 lines
1.5 KiB
C#

// <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;
using SystemTrayMenu.Helpers;
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;
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();
}
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;
}
}
}