forked from piksel/forever-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SysTrayContext.cs
58 lines (45 loc) · 1.48 KB
/
SysTrayContext.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace forever {
class SysTrayContext : ApplicationContext {
private System.ComponentModel.IContainer container;
private NotifyIcon notifyIcon;
private ContextMenuStrip contextMenu;
private ToolStripMenuItem menuItemExit;
private Timer timer;
public SysTrayContext() {
container = new System.ComponentModel.Container();
notifyIcon = new NotifyIcon(this.container);
notifyIcon.Icon = forever.icon;
notifyIcon.Text = "Forever";
notifyIcon.Visible = true;
//Instantiate the context menu and items
contextMenu = new ContextMenuStrip();
menuItemExit = new ToolStripMenuItem();
//Attach the menu to the notify icon
notifyIcon.ContextMenuStrip = contextMenu;
menuItemExit.Text = "Exit";
menuItemExit.Click += new EventHandler(menuItemExit_Click);
contextMenu.Items.Add(menuItemExit);
timer = new Timer(this.container);
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e) {
if(!Program.WatchersRunning)
ExitThreadCore();
}
void menuItemExit_Click(object sender, EventArgs e) {
ExitThreadCore();
}
protected override void ExitThreadCore() {
Program._stop = true;
notifyIcon.Visible = false;
base.ExitThreadCore();
}
}
}