SystemTrayMenu/UserInterface/AppNotifyIcon.cs
Peter Kirmeier de483c874c Refactored resource file management..
Remove use of resx file
Resource files are marked as "Resource" instead
Resources are loaded via resource dictionaries (either from code behind or XAML directly through binding)
Reduce amount of required image conversions

Also fix overlay of 50 percent transparency (is now rendered half transparent correct instead of adding "white fog")
Remove obsolete image as rendering is done directly in code

Also fix rendering of link indicator at correct image position

Also remove setting Icons of all Windows (as default is application icon anyway)
2023-08-12 02:33:11 +02:00

54 lines
1.7 KiB
C#

// <copyright file="AppNotifyIcon.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu.UserInterface
{
using System;
using System.Drawing;
using System.Windows.Threading;
using H.NotifyIcon.Core;
internal class AppNotifyIcon : IDisposable
{
private readonly Dispatcher dispatchter = Dispatcher.CurrentDispatcher;
private readonly TrayIconWithContextMenu notifyIcon = new ();
private Icon? loadingIcon;
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();
loadingIcon?.Dispose();
}
public void LoadingStart()
{
loadingIcon ??= App.LoadIconFromResource("Resources/Loading.ico");
notifyIcon.Icon = loadingIcon.Handle;
}
public void LoadingStop()
{
notifyIcon.Icon = Config.GetAppIcon().Handle;
}
}
}