SystemTrayMenu/UserInterface/AppNotifyIcon.cs
Peter Kirmeier ea02181408 Refactor native DLL imports
Adjust namespace
Enforce calling conventions
Mark as Windows specific API
Remove empty wrapper calls
Remove obsolete calls
Combine/group logically in files instead of "by function"
2023-05-09 23:33:56 +02:00

50 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;
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;
}
}
}