@@ -64,7 +64,7 @@ private void Application_Startup(object sender, StartupEventArgs e)
64
64
{
65
65
if ( Int32 . TryParse ( e . Args [ 1 ] , out int id ) )
66
66
{
67
- ProcessDetailWindow w = new ProcessDetailWindow ( id , null ) ;
67
+ ProcessDetailWindow w = new ProcessDetailWindow ( id ) ;
68
68
Dispatcher . InvokeAsync ( new Action ( ( ) => { w . Show ( ) ; } ) ) ;
69
69
}
70
70
}
@@ -94,7 +94,7 @@ private void Application_Startup(object sender, StartupEventArgs e)
94
94
{
95
95
Dispatcher . InvokeAsync ( new Action ( ( ) =>
96
96
{
97
- InitViewAndNeedCloseResourcees ( ) ;
97
+ InitViewAndNeedClosedResourcees ( ) ;
98
98
welcomeWindow . ReduceAndClose ( new Point ( mainWindow . Left + mainWindow . Width / 2 , mainWindow . Top + mainWindow . Height / 2 ) ) ;
99
99
} ) ) ;
100
100
}
@@ -138,12 +138,9 @@ private void InitLanguage()
138
138
}
139
139
}
140
140
141
- private void InitViewAndNeedCloseResourcees ( )
141
+ private void InitViewAndNeedClosedResourcees ( )
142
142
{
143
143
mainWindow = new MainWindow ( ) ;
144
- detailWindow = new DetailWindow ( mainWindow ) ;
145
- mainWindow . SetDetailWindow ( detailWindow ) ;
146
- detailWindow . IsVisibleChanged += DetailWindow_IsVisibleChanged ;
147
144
if ( Settings . Default . MainWindowLeft > - 200000 && Settings . Default . MainWindowTop > - 200000 )
148
145
{
149
146
mainWindow . Left = Settings . Default . MainWindowLeft ;
@@ -241,12 +238,15 @@ private void CheckScreenCount()
241
238
}
242
239
}
243
240
244
- private void DetailWindow_IsVisibleChanged ( object sender , DependencyPropertyChangedEventArgs e )
241
+ public void NeedPortProcessMap ( object sender , bool need )
245
242
{
246
- portProcessMap . Enabled = detailWindow . IsVisible ;
247
- if ( ! detailWindow . IsVisible )
243
+ if ( need )
248
244
{
249
- mainWindow . TryToEdgeHide ( ) ;
245
+ portProcessMap . RegisterCustomer ( sender ) ;
246
+ }
247
+ else
248
+ {
249
+ portProcessMap . UnRegisterCustomer ( sender ) ;
250
250
}
251
251
}
252
252
@@ -258,6 +258,10 @@ private void InitializeTray()
258
258
{
259
259
Checked = Settings . Default . edgeHide
260
260
} ;
261
+ menuShowTrayIcon = new System . Windows . Forms . MenuItem ( FindResource ( "ShowTrayIcon" ) . ToString ( ) , TrayMenu_Click )
262
+ {
263
+ Checked = Settings . Default . ShowTrayIcon
264
+ } ;
261
265
menuStartOnBoot = new System . Windows . Forms . MenuItem ( FindResource ( "StartOnBoot" ) . ToString ( ) , TrayMenu_Click )
262
266
{
263
267
Checked = Settings . Default . startOnBoot
@@ -270,7 +274,7 @@ private void InitializeTray()
270
274
Tag = ""
271
275
} ;
272
276
menuLanguage . MenuItems . Add ( menuDefault ) ;
273
- List < OneLanguage > languages = Languages . getLanguages ( ) ;
277
+ List < OneLanguage > languages = Languages . GetLanguages ( ) ;
274
278
foreach ( OneLanguage i in languages )
275
279
{
276
280
System . Windows . Forms . MenuItem menuItem = new System . Windows . Forms . MenuItem ( )
@@ -297,13 +301,13 @@ private void InitializeTray()
297
301
298
302
menuAbout = new System . Windows . Forms . MenuItem ( FindResource ( "AboutNetSpeedMonitor" ) . ToString ( ) , TrayMenu_Click ) ;
299
303
System . Windows . Forms . ContextMenu menu = new System . Windows . Forms . ContextMenu ( new System . Windows . Forms . MenuItem [ ] {
300
- menuStartOnBoot , menuEdgeHide , menuLanguage , menuUpdate , menuAbout , menuExit } ) ;
304
+ menuStartOnBoot , menuEdgeHide , menuShowTrayIcon , menuLanguage , menuUpdate , menuAbout , menuExit } ) ;
301
305
302
306
notifyIcon = new System . Windows . Forms . NotifyIcon
303
307
{
304
308
Icon = new System . Drawing . Icon ( GetResourceStream ( new Uri ( "pack://application:,,,/icon.ico" , UriKind . RelativeOrAbsolute ) ) . Stream ) ,
305
309
ContextMenu = menu ,
306
- Visible = true
310
+ Visible = Settings . Default . ShowTrayIcon
307
311
} ;
308
312
}
309
313
@@ -365,7 +369,6 @@ public void TryToExit()
365
369
{
366
370
Microsoft . Win32 . SystemEvents . DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged ;
367
371
SystemParameters . StaticPropertyChanged -= SystemParameters_StaticPropertyChanged ;
368
- portProcessMap . Enabled = false ;
369
372
mainWindow . RegisterAppBar ( false ) ;
370
373
timer . Enabled = false ;
371
374
notifyIcon . Dispose ( ) ;
@@ -375,6 +378,13 @@ public void TryToExit()
375
378
t . Start ( ) ;
376
379
}
377
380
381
+ public void TryToSetShowTrayIcon ( bool showTrayIcon )
382
+ {
383
+ Settings . Default . ShowTrayIcon = showTrayIcon ;
384
+ Settings . Default . Save ( ) ;
385
+ notifyIcon . Visible = showTrayIcon ;
386
+ }
387
+
378
388
public void TryToSetEdgeHide ( bool edgeHide )
379
389
{
380
390
Settings . Default . edgeHide = edgeHide ;
@@ -407,6 +417,12 @@ private void TrayMenu_Click(object sender, EventArgs e)
407
417
mainWindow . WindowMenuEdgeHide . IsChecked = menuEdgeHide . Checked ;
408
418
TryToSetEdgeHide ( menuEdgeHide . Checked ) ;
409
419
}
420
+ else if ( sender == menuShowTrayIcon )
421
+ {
422
+ menuShowTrayIcon . Checked = ! menuShowTrayIcon . Checked ;
423
+ mainWindow . WindowMenuShowTrayIcon . IsChecked = menuShowTrayIcon . Checked ;
424
+ TryToSetShowTrayIcon ( menuShowTrayIcon . Checked ) ;
425
+ }
410
426
else if ( sender == menuAutoUpdate )
411
427
{
412
428
menuAutoUpdate . Checked = ! menuAutoUpdate . Checked ;
@@ -428,20 +444,14 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
428
444
UDStatistic statistics = udMap . NextStatistic ( 10 , portProcessMap ) ;
429
445
Dispatcher . Invoke ( new Action ( ( ) =>
430
446
{
431
- mainWindow . UploadLabel . Content = Tool . GetNetSpeedString ( statistics . upload , statistics . timeSpan ) ;
432
- mainWindow . DownloadLabel . Content = Tool . GetNetSpeedString ( statistics . download , statistics . timeSpan ) ;
433
- if ( detailWindow . Visibility == Visibility . Visible )
434
- {
435
- detailWindow . NewData ( statistics . items , statistics . timeSpan ) ;
436
- }
447
+ mainWindow . NewData ( statistics ) ;
437
448
} ) ) ;
438
449
}
439
450
440
- public System . Windows . Forms . MenuItem menuExit , menuEdgeHide , menuStartOnBoot , menuAutoUpdate , menuCheckUpdate , menuAbout ;
451
+ public System . Windows . Forms . MenuItem menuExit , menuEdgeHide , menuShowTrayIcon , menuStartOnBoot , menuAutoUpdate , menuCheckUpdate , menuAbout ;
441
452
442
453
private System . Windows . Forms . NotifyIcon notifyIcon ;
443
454
private MainWindow mainWindow ;
444
- private DetailWindow detailWindow ;
445
455
private WelcomeWindow welcomeWindow ;
446
456
private CaptureManager captureManager ;
447
457
private UDMap udMap = new UDMap ( ) ;
0 commit comments