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