-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
70 lines (59 loc) · 1.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace TopTeam.Gear
{
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using TopTeam.Gear.Parsers;
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var menuStrip = new ContextMenuStrip();
var gear = Parser.ReadConfigs();
if (gear == null || gear.MenuItems == null || gear.MenuItems.Count == 0)
{
TurnOffAsync();
return;
}
menuStrip.Items.AddRange(gear.MenuItems.ToArray());
menuStrip.Closed += MenuStripClosed;
menuStrip.Show(gear.StartX, gear.StartY);
menuStrip.Focus();
menuStrip.Items[gear.SelectedIndex].Select();
Application.Run();
}
static void MenuStripClosed(object sender, ToolStripDropDownClosedEventArgs e)
{
TurnOffAsync();
}
/// <summary>
/// Turn off the application
/// </summary>
public static void TurnOff()
{
Application.Exit();
}
private static void TurnOffAsync()
{
Task.Run(
async () =>
{
await Task.Delay(150);
if (!HandledTurnOFf)
{
TurnOff();
}
});
}
/// <summary>
/// Used to turn off application if there is no any action is active (for example if pressed alt+tab)
/// </summary>
public static bool HandledTurnOFf = false;
}
}