23
23
using System . Windows . Forms ;
24
24
using NAudio . CoreAudioApi ;
25
25
using Serilog ;
26
+ using SoundSwitch . Audio . Manager ;
27
+ using SoundSwitch . Audio . Manager . Interop . Enum ;
26
28
using SoundSwitch . Common . Framework . Audio . Device ;
27
29
using SoundSwitch . Framework ;
28
30
using SoundSwitch . Framework . Configuration ;
@@ -72,10 +74,12 @@ public sealed class TrayIcon : IDisposable
72
74
private readonly ToolStripMenuItem _updateMenuItem ;
73
75
private TimerForm _animationTimer ;
74
76
private readonly UpdateDownloadForm _updateDownloadForm ;
77
+ private readonly MethodInfo ? _showContextMenu ;
75
78
76
79
public TrayIcon ( )
77
80
{
78
81
UpdateIcon ( ) ;
82
+ _showContextMenu = typeof ( NotifyIcon ) . GetMethod ( "ShowContextMenu" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
79
83
_tooltipInfoManager = new TooltipInfoManager ( NotifyIcon ) ;
80
84
_profileTrayIconBuilder = new ProfileTrayIconBuilder ( ) ;
81
85
@@ -89,10 +93,18 @@ public TrayIcon()
89
93
90
94
_selectionMenu . Items . Add ( TrayIconStrings . noDevicesSelected , RessourceSettingsSmallBitmap , ( sender , e ) => ShowSettings ( ) ) ;
91
95
92
- NotifyIcon . MouseDoubleClick += ( sender , args ) => { AppModel . Instance . CycleActiveDevice ( DataFlow . Render ) ; } ;
96
+ // NotifyIcon.MouseDoubleClick += (sender, args) => { AppModel.Instance.CycleActiveDevice(DataFlow.Render); };
93
97
94
- NotifyIcon . MouseClick += ( sender , e ) =>
98
+ NotifyIcon . MouseDown += ( sender , e ) =>
95
99
{
100
+ Log . Debug ( "Click on systray icon: {times} {button}" , e . Clicks , e . Button ) ;
101
+ if ( e . Clicks == 2 )
102
+ {
103
+ NotifyIcon . ContextMenuStrip . Close ( ) ;
104
+ AppModel . Instance . CycleActiveDevice ( DataFlow . Render ) ;
105
+ return ;
106
+ }
107
+
96
108
if ( e . Button != MouseButtons . Left ) return ;
97
109
98
110
if ( _updateMenuItem . Tag != null )
@@ -103,9 +115,7 @@ public TrayIcon()
103
115
104
116
UpdateDeviceSelectionList ( ) ;
105
117
NotifyIcon . ContextMenuStrip = _selectionMenu ;
106
- var mi = typeof ( NotifyIcon ) . GetMethod ( "ShowContextMenu" ,
107
- BindingFlags . Instance | BindingFlags . NonPublic ) ;
108
- mi . Invoke ( NotifyIcon , null ) ;
118
+ _showContextMenu . Invoke ( NotifyIcon , null ) ;
109
119
110
120
NotifyIcon . ContextMenuStrip = _settingsMenu ;
111
121
} ;
@@ -295,6 +305,7 @@ public void ShowSettings()
295
305
/// </summary>
296
306
public void UpdateDeviceSelectionList ( )
297
307
{
308
+ Log . Information ( "Set tray icon menu devices" ) ;
298
309
_selectionMenu . Items . Clear ( ) ;
299
310
var playbackDevices = AppModel . Instance . AvailablePlaybackDevices ;
300
311
var recordingDevices = AppModel . Instance . AvailableRecordingDevices ;
@@ -313,13 +324,15 @@ public void UpdateDeviceSelectionList()
313
324
return ;
314
325
}
315
326
316
- Log . Information ( "Set tray icon menu devices" ) ;
317
- _selectionMenu . Items . AddRange ( playbackDevices . Select ( info => new ToolStripDeviceItem ( DeviceClicked , info ) ) . ToArray ( ) ) ;
327
+ var defaultPlayback = AudioSwitcher . Instance . GetDefaultAudioEndpoint ( EDataFlow . eRender , ERole . eConsole ) ;
328
+ _selectionMenu . Items . AddRange ( playbackDevices . Select ( info => new ToolStripDeviceItem ( DeviceClicked , info , info . Equals ( defaultPlayback ) ) ) . ToArray ( ) ) ;
318
329
319
330
if ( recordingDevices . Count > 0 )
320
331
{
332
+ var defaultRecording = AudioSwitcher . Instance . GetDefaultAudioEndpoint ( EDataFlow . eCapture , ERole . eConsole ) ;
333
+
321
334
_selectionMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
322
- _selectionMenu . Items . AddRange ( recordingDevices . Select ( info => new ToolStripDeviceItem ( DeviceClicked , info ) ) . ToArray ( ) ) ;
335
+ _selectionMenu . Items . AddRange ( recordingDevices . Select ( info => new ToolStripDeviceItem ( DeviceClicked , info , info . Equals ( defaultRecording ) ) ) . ToArray ( ) ) ;
323
336
}
324
337
}
325
338
0 commit comments