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-08-12 12:33:11 +12:00
|
|
|
|
using System.Drawing;
|
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 ();
|
2023-08-12 12:33:11 +12:00
|
|
|
|
private Icon? loadingIcon;
|
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()
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Dispose();
|
2023-08-12 12:33:11 +12:00
|
|
|
|
loadingIcon?.Dispose();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadingStart()
|
|
|
|
|
{
|
2023-08-12 12:33:11 +12:00
|
|
|
|
loadingIcon ??= App.LoadIconFromResource("Resources/Loading.ico");
|
2023-08-12 12:44:48 +12:00
|
|
|
|
notifyIcon.UpdateIcon(loadingIcon.Handle);
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadingStop()
|
|
|
|
|
{
|
2023-08-12 12:44:48 +12:00
|
|
|
|
notifyIcon.UpdateIcon(Config.GetAppIcon().Handle);
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|