2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="AppNotifyIcon.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2019-07-05 05:04:14 +12:00
|
|
|
|
|
2020-03-28 12:42:32 +13:00
|
|
|
|
namespace SystemTrayMenu.UserInterface
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.Helper;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
internal class AppNotifyIcon : IDisposable
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2021-11-17 12:13:46 +13:00
|
|
|
|
private readonly NotifyIcon notifyIcon = new();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
public AppNotifyIcon()
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2020-07-07 09:37:55 +12:00
|
|
|
|
notifyIcon.Text = Translator.GetText("SystemTrayMenu");
|
2021-11-18 11:46:43 +13:00
|
|
|
|
notifyIcon.Icon = Config.GetAppIcon();
|
2022-02-22 05:25:31 +13:00
|
|
|
|
notifyIcon.Visible = true;
|
2021-06-07 00:46:48 +12:00
|
|
|
|
|
2021-11-17 12:13:46 +13:00
|
|
|
|
AppContextMenu contextMenus = new();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
|
|
|
|
|
contextMenus.ClickedOpenLog += ClickedOpenLog;
|
|
|
|
|
void ClickedOpenLog()
|
|
|
|
|
{
|
2020-06-29 06:56:03 +12:00
|
|
|
|
OpenLog?.Invoke();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notifyIcon.ContextMenuStrip = contextMenus.Create();
|
|
|
|
|
notifyIcon.MouseClick += NotifyIcon_MouseClick;
|
|
|
|
|
void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2020-04-16 03:23:42 +12:00
|
|
|
|
VerifyClick(e);
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2019-07-05 05:04:14 +12:00
|
|
|
|
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
|
|
|
|
|
void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2020-04-16 03:23:42 +12:00
|
|
|
|
VerifyClick(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
public event EventHandlerEmpty Click;
|
|
|
|
|
|
|
|
|
|
public event EventHandlerEmpty OpenLog;
|
|
|
|
|
|
2019-07-05 05:04:14 +12:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Icon = null;
|
|
|
|
|
notifyIcon.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
public void LoadingStart()
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
2022-02-22 05:25:31 +13:00
|
|
|
|
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadingStop()
|
|
|
|
|
{
|
2022-02-22 05:25:31 +13:00
|
|
|
|
notifyIcon.Icon = Config.GetAppIcon();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
2020-04-16 03:23:42 +12:00
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
private void VerifyClick(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
Click?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
}
|