mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-16 17:27:30 +12:00
de483c874c
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)
54 lines
No EOL
1.7 KiB
C#
54 lines
No EOL
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;
|
|
}
|
|
}
|
|
} |