12
12
* GNU General Public License for more details.
13
13
********************************************************************/
14
14
15
+ using System ;
16
+ using System . Diagnostics ;
17
+ using System . Drawing ;
18
+ using System . Linq ;
15
19
using System . Windows . Forms ;
20
+ using NAudio . CoreAudioApi ;
16
21
using Serilog ;
22
+ using SoundSwitch . Common . Framework . Audio . Device ;
23
+ using SoundSwitch . Common . Framework . Icon ;
17
24
using SoundSwitch . Framework . Audio ;
18
25
using SoundSwitch . Framework . NotificationManager . Notification ;
19
26
using SoundSwitch . Framework . NotificationManager . Notification . Configuration ;
@@ -90,6 +97,15 @@ private void ModelOnDefaultDeviceChanged(object sender, DeviceDefaultChangedEven
90
97
_lastDeviceId = deviceDefaultChangedEvent . DeviceId ;
91
98
}
92
99
100
+ private DeviceFullInfo ? CheckDeviceAvailable ( DeviceInfo deviceInfo )
101
+ {
102
+ return deviceInfo . Type switch
103
+ {
104
+ DataFlow . Capture => _model . AvailableRecordingDevices . FirstOrDefault ( info => info . Equals ( deviceInfo ) ) ,
105
+ _ => _model . AvailablePlaybackDevices . FirstOrDefault ( info => info . Equals ( deviceInfo ) )
106
+ } ;
107
+ }
108
+
93
109
/// <summary>
94
110
/// Notify on Profile changed
95
111
/// </summary>
@@ -100,7 +116,42 @@ public void NotifyProfileChanged(Profile.Profile profile, uint? processId)
100
116
return ;
101
117
}
102
118
103
- _notification . NotifyProfileChanged ( profile , processId ) ;
119
+ var icon = GetIcon ( profile , processId ) ;
120
+
121
+ _notification . NotifyProfileChanged ( profile , icon , processId ) ;
122
+ }
123
+
124
+ private Bitmap GetIcon ( Profile . Profile profile , uint ? processId )
125
+ {
126
+ if ( ! _notification . SupportIcon )
127
+ {
128
+ return null ;
129
+ }
130
+
131
+ Bitmap icon = null ;
132
+ if ( processId . HasValue )
133
+ {
134
+ try
135
+ {
136
+ var process = Process . GetProcessById ( ( int ) processId . Value ) ;
137
+ icon = IconExtractor . Extract ( process . MainModule ? . FileName , 0 , true ) . ToBitmap ( ) ;
138
+ }
139
+ catch ( Exception )
140
+ {
141
+ // ignored
142
+ }
143
+ }
144
+
145
+ if ( icon == null )
146
+ {
147
+ var device = profile . Devices . Select ( wrapper => CheckDeviceAvailable ( wrapper . DeviceInfo ) ) . FirstOrDefault ( info => info != null ) ;
148
+ if ( device != null )
149
+ {
150
+ icon = device . LargeIcon . ToBitmap ( ) ;
151
+ }
152
+ }
153
+
154
+ return icon ?? Resources . default_profile_image ;
104
155
}
105
156
106
157
public void NotifyMuteChanged ( string microphoneName , bool newMuteState )
0 commit comments