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.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.Helper;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
2021-06-27 21:35:07 +12:00
|
|
|
|
using R = SystemTrayMenu.Properties.Resources;
|
2020-07-07 07:15:45 +12:00
|
|
|
|
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
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
private const int Interval60FPS = 16; // 60fps=>1s/60fps=~16.6ms
|
2021-06-27 21:35:07 +12:00
|
|
|
|
private static Icon systemTrayMenu = R.SystemTrayMenu;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
private readonly Timer load = new Timer();
|
2020-03-24 00:35:10 +13:00
|
|
|
|
private readonly NotifyIcon notifyIcon = new NotifyIcon();
|
2021-04-17 12:39:48 +12:00
|
|
|
|
private readonly int indexLoad;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
private readonly List<Icon> bitmapsLoading = new List<Icon>()
|
|
|
|
|
{
|
|
|
|
|
R.L010, R.L020, R.L030,
|
|
|
|
|
R.L040, R.L050, R.L060, R.L070, R.L080, R.L090, R.L100, R.L110, R.L120,
|
|
|
|
|
R.L130, R.L140, R.L150, R.L160, R.L170, R.L180,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-05 05:04:14 +12:00
|
|
|
|
private DateTime timeLoadingStart;
|
2021-04-17 12:39:48 +12:00
|
|
|
|
private bool threadsLoading;
|
|
|
|
|
private int loadCount;
|
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
|
|
|
|
{
|
|
|
|
|
indexLoad = bitmapsLoading.Count;
|
|
|
|
|
notifyIcon.Icon = bitmapsLoading.First();
|
|
|
|
|
load.Tick += Load_Tick;
|
2020-04-01 07:42:49 +13:00
|
|
|
|
load.Interval = Interval60FPS;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
notifyIcon.Text = Translator.GetText("SystemTrayMenu");
|
2019-07-05 05:04:14 +12:00
|
|
|
|
notifyIcon.Visible = true;
|
2021-06-07 00:46:48 +12:00
|
|
|
|
|
|
|
|
|
if (Properties.Settings.Default.UseIconFromRootFolder)
|
|
|
|
|
{
|
2021-06-27 21:35:07 +12:00
|
|
|
|
systemTrayMenu = IconReader.GetFolderIconSTA(
|
2021-06-07 00:46:48 +12:00
|
|
|
|
Config.Path,
|
|
|
|
|
IconReader.FolderType.Closed,
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-27 21:35:07 +12:00
|
|
|
|
notifyIcon.Icon = systemTrayMenu;
|
2019-07-05 05:04:14 +12:00
|
|
|
|
AppContextMenu contextMenus = new AppContextMenu();
|
|
|
|
|
|
|
|
|
|
contextMenus.ClickedOpenLog += ClickedOpenLog;
|
|
|
|
|
void ClickedOpenLog()
|
|
|
|
|
{
|
2020-06-29 06:56:03 +12:00
|
|
|
|
OpenLog?.Invoke();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contextMenus.ClickedRestart += ClickedRestart;
|
|
|
|
|
void ClickedRestart()
|
|
|
|
|
{
|
2020-06-29 06:56:03 +12:00
|
|
|
|
Restart?.Invoke();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contextMenus.ClickedExit += ClickedExit;
|
|
|
|
|
void ClickedExit()
|
|
|
|
|
{
|
2020-06-29 06:56:03 +12:00
|
|
|
|
Exit?.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;
|
|
|
|
|
|
|
|
|
|
public event EventHandlerEmpty Restart;
|
|
|
|
|
|
|
|
|
|
public event EventHandlerEmpty Exit;
|
|
|
|
|
|
2019-07-05 05:04:14 +12:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Icon = null;
|
|
|
|
|
notifyIcon.Dispose();
|
2020-03-25 02:39:43 +13:00
|
|
|
|
load.Dispose();
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
public void LoadingStart()
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
|
|
|
|
timeLoadingStart = DateTime.Now;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
threadsLoading = true;
|
2019-07-05 05:04:14 +12:00
|
|
|
|
load.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadingStop()
|
|
|
|
|
{
|
2021-05-14 01:20:40 +12:00
|
|
|
|
Cursor.Current = Cursors.Default;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
threadsLoading = false;
|
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
|
|
|
|
private void Load_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (threadsLoading)
|
2019-07-05 05:04:14 +12:00
|
|
|
|
{
|
|
|
|
|
if (DateTime.Now - timeLoadingStart > new TimeSpan(0, 0, 0, 0, 500))
|
|
|
|
|
{
|
2021-05-14 01:20:40 +12:00
|
|
|
|
Cursor.Current = Cursors.WaitCursor;
|
2019-07-05 05:04:14 +12:00
|
|
|
|
notifyIcon.Icon = bitmapsLoading[loadCount++ % indexLoad];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-27 21:35:07 +12:00
|
|
|
|
notifyIcon.Icon = systemTrayMenu;
|
2019-07-05 05:04:14 +12:00
|
|
|
|
load.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|