File tree 6 files changed +36
-76
lines changed
SoundSwitch/Framework/TrayIcon/Icon
6 files changed +36
-76
lines changed Original file line number Diff line number Diff line change 1
- using SoundSwitch . Common . Framework . Audio . Device ;
1
+ using NAudio . CoreAudioApi ;
2
+ using SoundSwitch . Audio . Manager ;
3
+ using SoundSwitch . Audio . Manager . Interop . Enum ;
4
+ using SoundSwitch . Common . Framework . Audio . Device ;
2
5
3
6
namespace SoundSwitch . Framework . TrayIcon . Icon . Changer
4
7
{
5
8
public abstract class AbstractIconChanger : IIconChanger
6
9
{
7
10
public abstract IconChangerFactory . ActionEnum TypeEnum { get ; }
8
11
public abstract string Label { get ; }
9
- public abstract bool NeedsToChangeIcon ( DeviceInfo deviceInfo ) ;
10
- public abstract void ChangeIcon ( UI . Component . TrayIcon trayIcon ) ;
12
+
13
+ protected abstract DataFlow Flow { get ; }
14
+
15
+ protected virtual bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
16
+ {
17
+ return deviceInfo . Type == Flow ;
18
+ }
19
+
20
+ public void ChangeIcon ( UI . Component . TrayIcon trayIcon )
21
+ {
22
+ var audio = AudioSwitcher . Instance . GetDefaultAudioEndpoint ( ( EDataFlow ) Flow , ERole . eConsole ) ;
23
+ ChangeIcon ( trayIcon , audio ) ;
24
+ }
11
25
12
26
public void ChangeIcon ( UI . Component . TrayIcon trayIcon , DeviceFullInfo deviceInfo )
13
27
{
14
- if ( ! NeedsToChangeIcon ( deviceInfo ) ) return ;
28
+ if ( deviceInfo == null )
29
+ {
30
+ return ;
31
+ }
32
+
33
+ if ( ! NeedsToChangeIcon ( deviceInfo ) )
34
+ {
35
+ return ;
36
+ }
37
+
38
+
15
39
trayIcon . ReplaceIcon ( deviceInfo . SmallIcon ) ;
16
40
}
17
41
}
Original file line number Diff line number Diff line change 1
1
using NAudio . CoreAudioApi ;
2
2
using SoundSwitch . Common . Framework . Audio . Device ;
3
3
using SoundSwitch . Localization ;
4
- using SoundSwitch . Properties ;
5
4
6
5
namespace SoundSwitch . Framework . TrayIcon . Icon . Changer
7
6
{
8
7
public class AlwaysIconChanger : AbstractIconChanger
9
8
{
10
9
public override IconChangerFactory . ActionEnum TypeEnum => IconChangerFactory . ActionEnum . Always ;
11
10
public override string Label => TrayIconStrings . iconChanger_both ;
12
- internal const int E_NOT_SET = unchecked ( ( int ) 0x80070490 ) ;
13
- public override bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
11
+
12
+ protected override bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
14
13
{
15
14
return true ;
16
15
}
17
16
18
- public override void ChangeIcon ( UI . Component . TrayIcon trayIcon )
19
- {
20
- using var enumerator = new MMDeviceEnumerator ( ) ;
21
- try
22
- {
23
- using var defaultAudio = enumerator . GetDefaultAudioEndpoint ( DataFlow . Render , Role . Console ) ;
24
- trayIcon . ReplaceIcon ( new DeviceFullInfo ( defaultAudio ) . SmallIcon ) ;
25
- }
26
- catch ( System . Runtime . InteropServices . COMException e )
27
- {
28
- // Only handle "Element Not Found"
29
- if ( e . ErrorCode == E_NOT_SET )
30
- {
31
- // Set to app icon
32
- trayIcon . ReplaceIcon ( Resources . Switch_SoundWave ) ;
33
- }
34
- else
35
- {
36
- // Throw other ErrorCodes
37
- throw e ;
38
- }
39
- }
40
- }
17
+ protected override DataFlow Flow => DataFlow . Render ;
41
18
}
42
19
}
Original file line number Diff line number Diff line change 1
- using System ;
2
- using SoundSwitch . Common . Framework . Audio . Device ;
1
+ using SoundSwitch . Common . Framework . Audio . Device ;
3
2
using SoundSwitch . Localization ;
4
3
using SoundSwitch . Properties ;
5
4
@@ -10,11 +9,6 @@ public class NeverIconIconChanger : IIconChanger
10
9
public IconChangerFactory . ActionEnum TypeEnum => IconChangerFactory . ActionEnum . Never ;
11
10
public string Label => TrayIconStrings . iconChanger_none ;
12
11
13
- public bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
14
- {
15
- return false ;
16
- }
17
-
18
12
public void ChangeIcon ( UI . Component . TrayIcon trayIcon )
19
13
{
20
14
trayIcon . ReplaceIcon ( Resources . Switch_SoundWave ) ;
Original file line number Diff line number Diff line change 1
1
using NAudio . CoreAudioApi ;
2
- using SoundSwitch . Audio . Manager ;
3
- using SoundSwitch . Audio . Manager . Interop . Enum ;
4
- using SoundSwitch . Common . Framework . Audio . Device ;
5
2
using SoundSwitch . Localization ;
6
- using SoundSwitch . Model ;
7
3
8
4
namespace SoundSwitch . Framework . TrayIcon . Icon . Changer
9
5
{
10
6
public class PlaybackIconChanger : AbstractIconChanger
11
7
{
12
8
public override IconChangerFactory . ActionEnum TypeEnum => IconChangerFactory . ActionEnum . Playback ;
13
- public override string Label => TrayIconStrings . iconChanger_playback ;
14
-
15
- public override bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
16
- {
17
- return deviceInfo . Type == DataFlow . Render ;
18
- }
19
-
20
- public override void ChangeIcon ( UI . Component . TrayIcon trayIcon )
21
- {
22
- var defaultAudio = AudioSwitcher . Instance . GetDefaultAudioEndpoint ( EDataFlow . eRender , ERole . eConsole ) ;
23
- if ( defaultAudio != null )
24
- trayIcon . ReplaceIcon ( defaultAudio . SmallIcon ) ;
25
- }
9
+ public override string Label => TrayIconStrings . iconChanger_playback ;
10
+ protected override DataFlow Flow => DataFlow . Render ;
26
11
}
27
12
}
Original file line number Diff line number Diff line change 1
1
using NAudio . CoreAudioApi ;
2
- using SoundSwitch . Audio . Manager ;
3
- using SoundSwitch . Audio . Manager . Interop . Enum ;
4
- using SoundSwitch . Common . Framework . Audio . Device ;
5
2
using SoundSwitch . Localization ;
6
3
7
4
namespace SoundSwitch . Framework . TrayIcon . Icon . Changer
8
5
{
9
6
public class RecordingIconChanger : AbstractIconChanger
10
7
{
11
8
public override IconChangerFactory . ActionEnum TypeEnum => IconChangerFactory . ActionEnum . Recording ;
12
- public override string Label => TrayIconStrings . iconChanger_recording ;
13
-
14
- public override bool NeedsToChangeIcon ( DeviceInfo deviceInfo )
15
- {
16
- return deviceInfo . Type == DataFlow . Capture ;
17
- }
18
-
19
- public override void ChangeIcon ( UI . Component . TrayIcon trayIcon )
20
- {
21
- var defaultAudio = AudioSwitcher . Instance . GetDefaultAudioEndpoint ( EDataFlow . eCapture , ERole . eConsole ) ;
22
- if ( defaultAudio != null )
23
- trayIcon . ReplaceIcon ( defaultAudio . SmallIcon ) ;
24
- }
9
+ public override string Label => TrayIconStrings . iconChanger_recording ;
10
+ protected override DataFlow Flow => DataFlow . Capture ;
25
11
}
26
12
}
Original file line number Diff line number Diff line change @@ -5,12 +5,6 @@ namespace SoundSwitch.Framework.TrayIcon.Icon
5
5
{
6
6
public interface IIconChanger : IEnumImpl < IconChangerFactory . ActionEnum >
7
7
{
8
- /// <summary>
9
- /// Should the icon change
10
- /// </summary>
11
- /// <param name="deviceInfo"></param>
12
- /// <returns></returns>
13
- bool NeedsToChangeIcon ( DeviceInfo deviceInfo ) ;
14
8
15
9
/// <summary>
16
10
/// Change the icon to the current default device
You can’t perform that action at this time.
0 commit comments