Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed May 8, 2019
2 parents 0dfde4a + 7489cb3 commit 047a364
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions shadowsocks-csharp/View/MenuViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -140,6 +141,22 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e)
MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message));
}

private static void SetNotifyIconText(NotifyIcon ni, string text)
{
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;
Expand Down Expand Up @@ -212,14 +229,41 @@ private void UpdateTrayIcon()
_notifyIcon.Icon = newIcon;
}

// 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")) :
var strServer = random ? config.balanceAlgorithm : config.configs[config.index].remarks;
switch (strServer)
{
case "OneByOne":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("OneByOne")}";
break;
case "Random":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("Random")}";
break;
case "FastDownloadSpeed":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("FastDownloadSpeed")}";
break;
case "LowLatency":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("LowLatency")}";
break;
case "LowException":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("LowException")}";
break;
case "SelectedFirst":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("SelectedFirst")}";
break;
case "Timer":
strServer = $@"{I18N.GetString("Balance")} : {I18N.GetString("OneByOne")}";
break;
}
// 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"
+ String.Format(I18N.GetString("Running: Port {0}"), config.localPort) // this feedback is very important because they need to know Shadowsocks is running
+ Environment.NewLine
+ strServer
+ 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);
}

private MenuItem CreateMenuItem(string text, EventHandler click)
Expand Down

0 comments on commit 047a364

Please sign in to comment.