-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (69 loc) · 2.27 KB
/
Program.cs
File metadata and controls
81 lines (69 loc) · 2.27 KB
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
71
72
73
74
75
76
77
78
79
80
81
namespace RokitIgniter
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//make sure only one instance of the application can be running at the same time
using var mutex = new Mutex(false, "RokitIgniter");
if (!mutex.WaitOne(0, false))
{
MessageBox.Show("RokitIgniter is already running.", "RokitIgniter", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// we don't need a form, so we can just run the ApplicationContext directly
Application.Run(new MyCustomApplicationContext());
}
public class MyCustomApplicationContext : ApplicationContext
{
private NotifyIcon notifyIcon;
private Igniter igniter;
public MyCustomApplicationContext()
{
notifyIcon = new();
igniter = new();
SetupNotifyIcon();
}
private void SetupNotifyIcon()
{
notifyIcon!.Text = "Rokit Igniter";
notifyIcon.Icon = new("RokitIgniter.ico");
notifyIcon.ContextMenuStrip = new();
notifyIcon.ContextMenuStrip.Items.Add("Ignite", null, async (s, e) => await Ignite_ClickAsync(s, e));
notifyIcon.ContextMenuStrip.Items.Add("About", null, ShowAboutMessageBox_Click);
notifyIcon.ContextMenuStrip.Items.Add("Exit", null, ExitApplication_Click);
notifyIcon!.Click += async (s, e) =>
{
if (e is MouseEventArgs me && me.Button == MouseButtons.Right)
{
return;
}
await igniter.IgniteAsync();
};
notifyIcon.Visible = true;
}
async Task Ignite_ClickAsync(object? sender, EventArgs? e)
{
await igniter!.IgniteAsync();
}
void ShowAboutMessageBox_Click(object? sender, EventArgs? e)
{
var packageVersion = typeof(Program).Assembly.GetName().Version;
MessageBox.Show($"RokitIgniter v{packageVersion}", "RokitIgniter", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ExitApplication_Click(object? sender, EventArgs e)
{
Environment.Exit(0);
}
}
}
}