Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 9e900b5

Browse files
authored
Merge pull request #10 from wxlg1117/develop
2 parents a0385ac + b8e57db commit 9e900b5

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

shadowsocks-csharp/View/MenuViewController.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Drawing;
88
using System.Runtime.InteropServices;
9+
using System.Reflection;
910
using System.Text.RegularExpressions;
1011
using System.Threading;
1112
using System.Windows.Forms;
@@ -139,7 +140,15 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e)
139140
{
140141
MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message));
141142
}
142-
143+
public static void SetNotifyIconText(NotifyIcon ni, string text)
144+
{
145+
if (text.Length >= 128) throw new ArgumentOutOfRangeException("Text limited to 127 characters");
146+
Type t = typeof(NotifyIcon);
147+
BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance;
148+
t.GetField("text", hidden).SetValue(ni, text);
149+
if ((bool)t.GetField("added", hidden).GetValue(ni))
150+
t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true });
151+
}
143152
private void UpdateTrayIcon()
144153
{
145154
int dpi = 96;
@@ -149,6 +158,16 @@ private void UpdateTrayIcon()
149158
}
150159
Configuration config = controller.GetCurrentConfiguration();
151160
bool enabled = config.sysProxyMode != (int)ProxyMode.NoModify && config.sysProxyMode != (int)ProxyMode.Direct;
161+
string server;
162+
if (config.random)
163+
{
164+
server = config.balanceAlgorithm;
165+
}
166+
else
167+
{
168+
int server_current = config.index;
169+
server = config.configs[server_current].remarks;
170+
}
152171
bool global = config.sysProxyMode == (int)ProxyMode.Global;
153172
bool random = config.random;
154173

@@ -212,14 +231,45 @@ private void UpdateTrayIcon()
212231
_notifyIcon.Icon = newIcon;
213232
}
214233

234+
string strServer = server;
235+
switch (strServer)
236+
{
237+
case "OneByOne":
238+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne");
239+
break;
240+
case "Random":
241+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("Random");
242+
break;
243+
case "FastDownloadSpeed":
244+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("FastDownloadSpeed");
245+
break;
246+
case "LowLatency":
247+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowLatency");
248+
break;
249+
case "LowException":
250+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowException");
251+
break;
252+
case "SelectedFirst":
253+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("SelectedFirst");
254+
break;
255+
case "Timer":
256+
strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne");
257+
break;
258+
default:
259+
strServer = server;
260+
break;
261+
}
215262
// we want to show more details but notify icon title is limited to 63 characters
216263
string text = (enabled ?
217264
(global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
218265
I18N.GetString("Disable system proxy"))
219266
+ "\r\n"
267+
+ strServer
268+
+ "\r\n"
220269
+ String.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running
221270
;
222-
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
271+
//_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
272+
SetNotifyIconText(_notifyIcon, text);
223273
}
224274

225275
private MenuItem CreateMenuItem(string text, EventHandler click)

0 commit comments

Comments
 (0)