6
6
using System . Diagnostics ;
7
7
using System . Drawing ;
8
8
using System . Runtime . InteropServices ;
9
+ using System . Reflection ;
9
10
using System . Text . RegularExpressions ;
10
11
using System . Threading ;
11
12
using System . Windows . Forms ;
@@ -139,7 +140,15 @@ void controller_Errored(object sender, System.IO.ErrorEventArgs e)
139
140
{
140
141
MessageBox . Show ( e . GetException ( ) . ToString ( ) , String . Format ( I18N . GetString ( "Shadowsocks Error: {0}" ) , e . GetException ( ) . Message ) ) ;
141
142
}
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
+ }
143
152
private void UpdateTrayIcon ( )
144
153
{
145
154
int dpi = 96 ;
@@ -149,6 +158,16 @@ private void UpdateTrayIcon()
149
158
}
150
159
Configuration config = controller . GetCurrentConfiguration ( ) ;
151
160
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
+ }
152
171
bool global = config . sysProxyMode == ( int ) ProxyMode . Global ;
153
172
bool random = config . random ;
154
173
@@ -212,14 +231,45 @@ private void UpdateTrayIcon()
212
231
_notifyIcon . Icon = newIcon ;
213
232
}
214
233
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
+ }
215
262
// we want to show more details but notify icon title is limited to 63 characters
216
263
string text = ( enabled ?
217
264
( global ? I18N . GetString ( "Global" ) : I18N . GetString ( "PAC" ) ) :
218
265
I18N . GetString ( "Disable system proxy" ) )
219
266
+ "\r \n "
267
+ + strServer
268
+ + "\r \n "
220
269
+ String . Format ( I18N . GetString ( "Running: Port {0}" ) , config . localPort ) // this feedback is very important because they need to know Shadowsocks is running
221
270
;
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 ) ;
223
273
}
224
274
225
275
private MenuItem CreateMenuItem ( string text , EventHandler click )
0 commit comments