17
17
using System . Diagnostics ;
18
18
using System . Drawing ;
19
19
using System . IO ;
20
+ using System . Linq ;
20
21
using System . Reflection ;
21
22
using System . Threading ;
22
23
using System . Windows . Forms ;
25
26
using SoundSwitch . Common . Framework . Audio . Device ;
26
27
using SoundSwitch . Framework ;
27
28
using SoundSwitch . Framework . Configuration ;
29
+ using SoundSwitch . Framework . Profile . UI ;
28
30
using SoundSwitch . Framework . TrayIcon . Icon ;
29
31
using SoundSwitch . Framework . TrayIcon . TooltipInfoManager ;
30
32
using SoundSwitch . Framework . Updater ;
@@ -52,19 +54,20 @@ public sealed class TrayIcon : IDisposable
52
54
private static readonly Icon SoundSwitchLogoIcon = Resources . Switch_SoundWave ;
53
55
private static readonly Icon ResourceDiscord = Resources . DiscordIcon ;
54
56
55
- private readonly ContextMenuStrip _selectionMenu = new ContextMenuStrip ( ) ;
56
- private readonly ContextMenuStrip _settingsMenu = new ContextMenuStrip ( ) ;
57
+ private readonly ContextMenuStrip _selectionMenu = new ( ) ;
58
+ private readonly ContextMenuStrip _settingsMenu = new ( ) ;
57
59
58
60
private readonly SynchronizationContext _context =
59
61
SynchronizationContext . Current ?? new SynchronizationContext ( ) ;
60
62
61
- public NotifyIcon NotifyIcon { get ; } = new NotifyIcon
63
+ public NotifyIcon NotifyIcon { get ; } = new ( )
62
64
{
63
65
Visible = true ,
64
66
Text = Application . ProductName
65
67
} ;
66
68
67
69
private readonly TooltipInfoManager _tooltipInfoManager ;
70
+ private readonly ProfileTrayIconBuilder _profileTrayIconBuilder ;
68
71
69
72
private readonly ToolStripMenuItem _updateMenuItem ;
70
73
private TimerForm _animationTimer ;
@@ -74,6 +77,7 @@ public TrayIcon()
74
77
{
75
78
UpdateIcon ( ) ;
76
79
_tooltipInfoManager = new TooltipInfoManager ( NotifyIcon ) ;
80
+ _profileTrayIconBuilder = new ProfileTrayIconBuilder ( ) ;
77
81
78
82
_updateMenuItem = new ToolStripMenuItem ( AppConfigs . Configuration . UpdateMode == UpdateMode . Never ? TrayIconStrings . updateDisabled : TrayIconStrings . noUpdate , RessourceUpdateBitmap , OnUpdateClick )
79
83
{
@@ -161,9 +165,7 @@ private void PopulateSettingsMenu()
161
165
var applicationDirectory = Path . GetDirectoryName ( ApplicationPath . Executable ) ;
162
166
Debug . Assert ( applicationDirectory != null , "applicationDirectory != null" ) ;
163
167
var readmeHtml = Path . Combine ( applicationDirectory , "Readme.html" ) ;
164
- _settingsMenu . Items . Add (
165
- Application . ProductName + ' ' + AssemblyUtils . GetReleaseState ( ) + " (" + Application . ProductVersion +
166
- ")" , SoundSwitchLogoIcon . ToBitmap ( ) ) ;
168
+ _settingsMenu . Items . Add ( Application . ProductName + ' ' + AssemblyUtils . GetReleaseState ( ) + " (" + Application . ProductVersion + ")" , SoundSwitchLogoIcon . ToBitmap ( ) ) ;
167
169
_settingsMenu . Items . Add ( "-" ) ;
168
170
_settingsMenu . Items . Add ( TrayIconStrings . playbackDevices , RessourcePlaybackDevicesBitmap ,
169
171
( sender , e ) => { Process . Start ( new ProcessStartInfo ( "control" , "mmsys.cpl sounds" ) ) ; } ) ;
@@ -294,16 +296,27 @@ public void ShowSettings()
294
296
/// </summary>
295
297
public void UpdateDeviceSelectionList ( )
296
298
{
299
+ _selectionMenu . Items . Clear ( ) ;
297
300
var playbackDevices = AppModel . Instance . AvailablePlaybackDevices ;
298
301
var recordingDevices = AppModel . Instance . AvailableRecordingDevices ;
302
+ var profiles = _profileTrayIconBuilder . GetMenuItems ( ) . ToArray ( ) ;
303
+
304
+
305
+ if ( profiles . Length > 0 )
306
+ {
307
+ var profileMenu = new ContextMenuStrip ( ) ;
308
+ var profileMenuItem = new ToolStripMenuItem ( SettingsStrings . profile_tab ) { DropDown = profileMenu } ;
309
+ profileMenu . Items . AddRange ( profiles ) ;
310
+ _selectionMenu . Items . Add ( profileMenuItem ) ;
311
+ _selectionMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
312
+ }
299
313
if ( playbackDevices . Count < 0 &&
300
314
recordingDevices . Count < 0 )
301
315
{
302
316
Log . Information ( "Device list empty" ) ;
303
317
return ;
304
318
}
305
319
306
- _selectionMenu . Items . Clear ( ) ;
307
320
Log . Information ( "Set tray icon menu devices" ) ;
308
321
foreach ( var item in playbackDevices )
309
322
{
0 commit comments