-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrayIcon.cs
129 lines (110 loc) · 4.89 KB
/
TrayIcon.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using SteamStatus.Net.Properties;
using System.Linq;
using Timer = System.Threading.Timer;
namespace SteamStatus.Net
{
public partial class TrayIcon : Form
{
protected NotifyIcon notifyIcon = new NotifyIcon();
protected Client client = new Client();
protected Dictionary<string, MenuItem> menuItems;
protected Timer Timer;
protected Json json;
private async void Update(object state)
{
var data = await client.GetAsync();
if (json != null && json.Online < 75 && data.Online >= 75)
{
notifyIcon.ShowBalloonTip(5000, Resources.SteamIsBackOnline, string.Format(Resources.SteamOnlineText, data.Online), ToolTipIcon.Info);
}
json = data;
Rebuild();
}
private void Rebuild()
{
var menuItems = notifyIcon.ContextMenu.MenuItems;
menuItems.Clear();
if (json != null)
{
/* STEAM */
var steam = new List<MenuItem>
{
new MenuItem(string.Format(format: Resources.ItemTemplate,
arg0: Resources.SteamOnline,
arg1: json.Services.Where(p => (string) p[0] == "cms").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.CommunityOnline,
json.Services.Where(p => (string) p[0] == "community").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.WebApi,
json.Services.Where(p => (string) p[0] == "webapi").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.Store,
json.Services.Where(p => (string) p[0] == "store").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.Online,
json.Services.Where(p => (string) p[0] == "online").Select(p => p[2]).FirstOrDefault()))
};
menuItems.Add(Resources.Steam, steam.ToArray());
/* CS:GO */
var csgo = new List<MenuItem>
{
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.CSGO,
json.Services.Where(p => (string) p[0] == "csgo").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.CSGO_Inventory,
json.Services.Where(p => (string) p[0] == "csgo_community").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.CSGO_MM,
json.Services.Where(p => (string) p[0] == "csgo_mm_scheduler").Select(p => p[2]).FirstOrDefault())),
new MenuItem(String.Format(Resources.ItemTemplate,
Resources.CSGO_Sessions,
json.Services.Where(p => (string) p[0] == "csgo_sessions").Select(p => p[2]).FirstOrDefault()))
};
menuItems.Add(Resources.CSGO, csgo.ToArray());
/* TO-DO: regions */
var dict = json.ServicesDictionary();
foreach (var dictItem in dict)
{
Debugger.Log(255, "ServiceStatus", $"{dictItem.Key}: {dictItem.Value}\n");
}
}
menuItems.Add("-");
menuItems.Add(Resources.TrayIconExit, OnExit);
}
public TrayIcon()
{
var trayMenu = new ContextMenu();
notifyIcon.Text = Resources.TrayIconText;
notifyIcon.Icon = new Icon(Program.ApplicationIcon, 40, 40);
notifyIcon.ContextMenu = trayMenu;
notifyIcon.Visible = true;
Rebuild();
Timer = new Timer(Update, null, TimeSpan.Zero, TimeSpan.FromSeconds(45));
}
protected override void OnLoad(EventArgs e)
{
Visible = false;
ShowInTaskbar = false;
base.OnLoad(e);
}
private void OnExit(object sender, EventArgs e)
{
Application.Exit();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
notifyIcon.Dispose();
}
base.Dispose(disposing);
}
}
}