From e6693ebf5128fe59d6872ab402273d4349be6af5 Mon Sep 17 00:00:00 2001 From: Wx1glll7 Date: Tue, 7 May 2019 16:58:33 +0800 Subject: [PATCH 1/4] Bubble shows the current connection server name or load balancing type --- shadowsocks-csharp/View/MenuViewController.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 5671076290..9be9ae1db9 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -149,6 +149,16 @@ private void UpdateTrayIcon() } Configuration config = controller.GetCurrentConfiguration(); bool enabled = config.sysProxyMode != (int)ProxyMode.NoModify && config.sysProxyMode != (int)ProxyMode.Direct; + string server; + if (config.random) + { + server = config.balanceAlgorithm; + } + else + { + int server_current = config.index; + server = config.configs[server_current].remarks; + } bool global = config.sysProxyMode == (int)ProxyMode.Global; bool random = config.random; @@ -212,11 +222,52 @@ private void UpdateTrayIcon() _notifyIcon.Icon = newIcon; } + /*Balance = 负载均衡 + OneByOne = 按次序 + Random = 随机 + FastDownloadSpeed = 下载速度优先 + LowLatency = 低延迟优先 + LowException = 低错误优先 + SelectedFirst = 选中优先 + Timer = 定时切换*/ + + string strServer = server; + + switch (strServer) + { + case "OneByOne": + strServer = "负载均衡 : 按次序"; + break; + case "Random": + strServer = "负载均衡 : 随机"; + break; + case "FastDownloadSpeed": + strServer = "负载均衡 : 下载速度优先"; + break; + case "LowLatency": + strServer = "负载均衡 : 低延迟优先"; + break; + case "LowException": + strServer = "负载均衡 : 低错误优先"; + break; + case "SelectedFirst": + strServer = "负载均衡 : 选中优先"; + break; + case "Timer": + strServer = "负载均衡 : 定时切换"; + break; + default: + strServer = server; + break; + + } // we want to show more details but notify icon title is limited to 63 characters string text = (enabled ? (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : I18N.GetString("Disable system proxy")) + "\r\n" + + strServer + + "\r\n" + String.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running ; _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); From 54e06a35450c347b8bd29692693f799f08caf839 Mon Sep 17 00:00:00 2001 From: Wx1glll7 Date: Wed, 8 May 2019 06:16:00 +0800 Subject: [PATCH 2/4] fix tranlastions for bubble shows the current connection server name or load balancing type --- shadowsocks-csharp/View/MenuViewController.cs | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 9be9ae1db9..be5a442829 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -222,44 +222,33 @@ private void UpdateTrayIcon() _notifyIcon.Icon = newIcon; } - /*Balance = 负载均衡 - OneByOne = 按次序 - Random = 随机 - FastDownloadSpeed = 下载速度优先 - LowLatency = 低延迟优先 - LowException = 低错误优先 - SelectedFirst = 选中优先 - Timer = 定时切换*/ - string strServer = server; - switch (strServer) { case "OneByOne": - strServer = "负载均衡 : 按次序"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne"); break; case "Random": - strServer = "负载均衡 : 随机"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("Random"); break; case "FastDownloadSpeed": - strServer = "负载均衡 : 下载速度优先"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("FastDownloadSpeed"); break; case "LowLatency": - strServer = "负载均衡 : 低延迟优先"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowLatency"); break; case "LowException": - strServer = "负载均衡 : 低错误优先"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowException"); break; case "SelectedFirst": - strServer = "负载均衡 : 选中优先"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("SelectedFirst"); break; case "Timer": - strServer = "负载均衡 : 定时切换"; + strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne"); break; default: strServer = server; break; - } // we want to show more details but notify icon title is limited to 63 characters string text = (enabled ? From b8e57dbbb4900aff3d4d967dc139750eaac7c0ed Mon Sep 17 00:00:00 2001 From: Wx1glll7 Date: Wed, 8 May 2019 16:59:26 +0800 Subject: [PATCH 3/4] fix show more details but notify icon title is limited to 63 characters --- shadowsocks-csharp/View/MenuViewController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index be5a442829..76b3bf1fe1 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; +using System.Reflection; using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; @@ -139,7 +140,15 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e) { MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message)); } - + public static void SetNotifyIconText(NotifyIcon ni, string text) + { + if (text.Length >= 128) throw new ArgumentOutOfRangeException("Text limited to 127 characters"); + Type t = typeof(NotifyIcon); + BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance; + t.GetField("text", hidden).SetValue(ni, text); + if ((bool)t.GetField("added", hidden).GetValue(ni)) + t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true }); + } private void UpdateTrayIcon() { int dpi = 96; @@ -259,7 +268,8 @@ private void UpdateTrayIcon() + "\r\n" + String.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running ; - _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); + //_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); + SetNotifyIconText(_notifyIcon, text); } private MenuItem CreateMenuItem(string text, EventHandler click) From 7489cb3562229dbf6ede479d4cab6dacd4c5ff49 Mon Sep 17 00:00:00 2001 From: HMBSbige Date: Wed, 8 May 2019 23:17:28 +0800 Subject: [PATCH 4/4] Some improvements, optimizations and bugfixes for #10 --- shadowsocks-csharp/View/MenuViewController.cs | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 76b3bf1fe1..1f8bee8a6e 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -5,8 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.Runtime.InteropServices; using System.Reflection; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; @@ -140,15 +140,23 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e) { MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message)); } - public static void SetNotifyIconText(NotifyIcon ni, string text) + + private static void SetNotifyIconText(NotifyIcon ni, string text) { - if (text.Length >= 128) throw new ArgumentOutOfRangeException("Text limited to 127 characters"); - Type t = typeof(NotifyIcon); - BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance; - t.GetField("text", hidden).SetValue(ni, text); - if ((bool)t.GetField("added", hidden).GetValue(ni)) - t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true }); + if (text.Length > 127) + { + text = text.Substring(0, 127); + } + + var t = typeof(NotifyIcon); + const BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance; + t.GetField(@"text", hidden)?.SetValue(ni, text); + if (t.GetField(@"added", hidden)?.GetValue(ni) is bool b && b) + { + t.GetMethod(@"UpdateIcon", hidden)?.Invoke(ni, new object[] { true }); + } } + private void UpdateTrayIcon() { int dpi = 96; @@ -158,16 +166,6 @@ private void UpdateTrayIcon() } Configuration config = controller.GetCurrentConfiguration(); bool enabled = config.sysProxyMode != (int)ProxyMode.NoModify && config.sysProxyMode != (int)ProxyMode.Direct; - string server; - if (config.random) - { - server = config.balanceAlgorithm; - } - else - { - int server_current = config.index; - server = config.configs[server_current].remarks; - } bool global = config.sysProxyMode == (int)ProxyMode.Global; bool random = config.random; @@ -231,44 +229,40 @@ private void UpdateTrayIcon() _notifyIcon.Icon = newIcon; } - string strServer = server; + var strServer = random ? config.balanceAlgorithm : config.configs[config.index].remarks; switch (strServer) { case "OneByOne": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("OneByOne")}"; break; case "Random": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("Random"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("Random")}"; break; case "FastDownloadSpeed": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("FastDownloadSpeed"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("FastDownloadSpeed")}"; break; case "LowLatency": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowLatency"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("LowLatency")}"; break; case "LowException": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("LowException"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("LowException")}"; break; case "SelectedFirst": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("SelectedFirst"); + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("SelectedFirst")}"; break; case "Timer": - strServer = I18N.GetString("Balance") + " : " + I18N.GetString("OneByOne"); - break; - default: - strServer = server; + strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("OneByOne")}"; break; } - // we want to show more details but notify icon title is limited to 63 characters - string text = (enabled ? - (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : + // we want to show more details but notify icon title is limited to 127 characters + var text = (enabled ? + global ? I18N.GetString("Global") : I18N.GetString("PAC") : I18N.GetString("Disable system proxy")) - + "\r\n" + + Environment.NewLine + strServer - + "\r\n" - + String.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running + + Environment.NewLine + + string.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running ; - //_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); SetNotifyIconText(_notifyIcon, text); }