-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IconChanger): Fix issue where the icon wouldn't change when the d…
…efault device is switched.
- Loading branch information
Showing
6 changed files
with
36 additions
and
76 deletions.
There are no files selected for viewing
32 changes: 28 additions & 4 deletions
32
SoundSwitch/Framework/TrayIcon/Icon/Changer/AbstractIconChanger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 3 additions & 26 deletions
29
SoundSwitch/Framework/TrayIcon/Icon/Changer/AlwaysIconChanger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,19 @@ | ||
using NAudio.CoreAudioApi; | ||
using SoundSwitch.Common.Framework.Audio.Device; | ||
using SoundSwitch.Localization; | ||
using SoundSwitch.Properties; | ||
|
||
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer | ||
{ | ||
public class AlwaysIconChanger : AbstractIconChanger | ||
{ | ||
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Always; | ||
public override string Label => TrayIconStrings.iconChanger_both; | ||
internal const int E_NOT_SET = unchecked((int)0x80070490); | ||
public override bool NeedsToChangeIcon(DeviceInfo deviceInfo) | ||
|
||
protected override bool NeedsToChangeIcon(DeviceInfo deviceInfo) | ||
{ | ||
return true; | ||
} | ||
|
||
public override void ChangeIcon(UI.Component.TrayIcon trayIcon) | ||
{ | ||
using var enumerator = new MMDeviceEnumerator(); | ||
try | ||
{ | ||
using var defaultAudio = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); | ||
trayIcon.ReplaceIcon(new DeviceFullInfo(defaultAudio).SmallIcon); | ||
} | ||
catch (System.Runtime.InteropServices.COMException e) | ||
{ | ||
// Only handle "Element Not Found" | ||
if (e.ErrorCode == E_NOT_SET) | ||
{ | ||
// Set to app icon | ||
trayIcon.ReplaceIcon(Resources.Switch_SoundWave); | ||
} | ||
else | ||
{ | ||
// Throw other ErrorCodes | ||
throw e; | ||
} | ||
} | ||
} | ||
protected override DataFlow Flow => DataFlow.Render; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 2 additions & 17 deletions
19
SoundSwitch/Framework/TrayIcon/Icon/Changer/PlaybackIconChanger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,12 @@ | ||
using NAudio.CoreAudioApi; | ||
using SoundSwitch.Audio.Manager; | ||
using SoundSwitch.Audio.Manager.Interop.Enum; | ||
using SoundSwitch.Common.Framework.Audio.Device; | ||
using SoundSwitch.Localization; | ||
using SoundSwitch.Model; | ||
|
||
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer | ||
{ | ||
public class PlaybackIconChanger : AbstractIconChanger | ||
{ | ||
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Playback; | ||
public override string Label => TrayIconStrings.iconChanger_playback; | ||
|
||
public override bool NeedsToChangeIcon(DeviceInfo deviceInfo) | ||
{ | ||
return deviceInfo.Type == DataFlow.Render; | ||
} | ||
|
||
public override void ChangeIcon(UI.Component.TrayIcon trayIcon) | ||
{ | ||
var defaultAudio = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eConsole); | ||
if (defaultAudio != null) | ||
trayIcon.ReplaceIcon(defaultAudio.SmallIcon); | ||
} | ||
public override string Label => TrayIconStrings.iconChanger_playback; | ||
protected override DataFlow Flow => DataFlow.Render; | ||
} | ||
} |
18 changes: 2 additions & 16 deletions
18
SoundSwitch/Framework/TrayIcon/Icon/Changer/RecordingIconChanger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
using NAudio.CoreAudioApi; | ||
using SoundSwitch.Audio.Manager; | ||
using SoundSwitch.Audio.Manager.Interop.Enum; | ||
using SoundSwitch.Common.Framework.Audio.Device; | ||
using SoundSwitch.Localization; | ||
|
||
namespace SoundSwitch.Framework.TrayIcon.Icon.Changer | ||
{ | ||
public class RecordingIconChanger : AbstractIconChanger | ||
{ | ||
public override IconChangerFactory.ActionEnum TypeEnum => IconChangerFactory.ActionEnum.Recording; | ||
public override string Label => TrayIconStrings.iconChanger_recording; | ||
|
||
public override bool NeedsToChangeIcon(DeviceInfo deviceInfo) | ||
{ | ||
return deviceInfo.Type == DataFlow.Capture; | ||
} | ||
|
||
public override void ChangeIcon(UI.Component.TrayIcon trayIcon) | ||
{ | ||
var defaultAudio = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eConsole); | ||
if (defaultAudio != null) | ||
trayIcon.ReplaceIcon(defaultAudio.SmallIcon); | ||
} | ||
public override string Label => TrayIconStrings.iconChanger_recording; | ||
protected override DataFlow Flow => DataFlow.Capture; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters