Skip to content

Commit 5305b69

Browse files
Merge pull request #631 from Belphemur/dev
Release
2 parents 7065aad + b9d9a3d commit 5305b69

27 files changed

+768
-295
lines changed

SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs

+44-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Linq;
1718
using NAudio.CoreAudioApi;
1819
using Serilog;
1920
using SoundSwitch.Common.Framework.Audio.Device;
@@ -26,16 +27,37 @@ namespace SoundSwitch.Framework.Audio.Lister
2627
public class CachedAudioDeviceLister : IAudioDeviceLister
2728
{
2829
/// <inheritdoc />
29-
public IReadOnlyCollection<DeviceFullInfo> PlaybackDevices => _playbackDevices;
30+
public IReadOnlyCollection<DeviceFullInfo> PlaybackDevices
31+
{
32+
get
33+
{
34+
lock (_lockPlayback)
35+
{
36+
return _playbackList;
37+
}
38+
}
39+
}
3040

3141
/// <inheritdoc />
32-
public IReadOnlyCollection<DeviceFullInfo> RecordingDevices => _recordingDevices;
42+
public IReadOnlyCollection<DeviceFullInfo> RecordingDevices
43+
{
44+
get
45+
{
46+
lock (_lockRecording)
47+
{
48+
return _recordingList;
49+
}
50+
}
51+
}
3352

3453
private readonly DeviceState _state;
3554
private readonly DebounceDispatcher _dispatcher = new();
36-
private readonly object _lock = new();
37-
private readonly HashSet<DeviceFullInfo> _playbackDevices = new();
38-
private readonly HashSet<DeviceFullInfo> _recordingDevices = new();
55+
private readonly object _lockRefresh = new();
56+
private readonly object _lockRecording = new();
57+
private readonly object _lockPlayback = new();
58+
private IReadOnlyCollection<DeviceFullInfo> _playbackList = new DeviceFullInfo[0];
59+
private IReadOnlyCollection<DeviceFullInfo> _recordingList = new DeviceFullInfo[0];
60+
3961

4062
public CachedAudioDeviceLister(DeviceState state)
4163
{
@@ -47,12 +69,13 @@ private void DeviceChanged(object sender, DeviceChangedEventBase e)
4769
{
4870
_dispatcher.Debounce(100, o => Refresh());
4971
}
72+
5073
public void Refresh()
5174
{
52-
lock (_lock)
75+
var playbackDevices = new Dictionary<string, DeviceFullInfo>();
76+
var recordingDevices = new Dictionary<string, DeviceFullInfo>();
77+
lock (_lockRefresh)
5378
{
54-
_recordingDevices.Clear();
55-
_playbackDevices.Clear();
5679
Log.Information("[{@State}] Refreshing all devices", _state);
5780
using var enumerator = new MMDeviceEnumerator();
5881
foreach (var endPoint in enumerator.EnumerateAudioEndPoints(DataFlow.All, _state))
@@ -68,10 +91,10 @@ public void Refresh()
6891
switch (deviceInfo.Type)
6992
{
7093
case DataFlow.Render:
71-
_playbackDevices.Add(deviceInfo);
94+
playbackDevices.Add(deviceInfo.Id, deviceInfo);
7295
break;
7396
case DataFlow.Capture:
74-
_recordingDevices.Add(deviceInfo);
97+
recordingDevices.Add(deviceInfo.Id, deviceInfo);
7598
break;
7699
case DataFlow.All:
77100
break;
@@ -85,7 +108,17 @@ public void Refresh()
85108
}
86109
}
87110

88-
Log.Information("[{@State}] Refreshed all devices. {@Recording}/rec, {@Playback}/play", _state, _recordingDevices.Count, _playbackDevices.Count);
111+
lock (_lockPlayback)
112+
{
113+
_playbackList = playbackDevices.Values.ToArray();
114+
}
115+
116+
lock (_lockRecording)
117+
{
118+
_recordingList = recordingDevices.Values.ToArray();
119+
}
120+
121+
Log.Information("[{@State}] Refreshed all devices. {@Recording}/rec, {@Playback}/play", _state, recordingDevices.Count, playbackDevices.Count);
89122
}
90123
}
91124

SoundSwitch/Framework/Logger/Configuration/LoggerConfigurator.cs

+10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using System.Diagnostics;
33
using System.IO;
44
using Serilog;
5+
using Serilog.Events;
56
using Serilog.Exceptions;
67
using SoundSwitch.Framework.Logger.Enricher;
8+
using SoundSwitch.Util;
79

810
namespace SoundSwitch.Framework.Logger.Configuration
911
{
@@ -24,6 +26,14 @@ public static void ConfigureLogger()
2426
rollingInterval: RollingInterval.Day, retainedFileCountLimit: 3,
2527
flushToDiskInterval: TimeSpan.FromMinutes(10),
2628
outputTemplate: "[{Timestamp:HH:mm:ss.fff} {Level:u3}] {Message} (at {Caller}){NewLine}{Exception}")
29+
.WriteTo.Sentry(o =>
30+
{
31+
o.InitializeSdk = false;
32+
o.Dsn = "https://[email protected]/5755327";
33+
o.MinimumBreadcrumbLevel = LogEventLevel.Debug;
34+
o.MinimumEventLevel = LogEventLevel.Error;
35+
o.Environment = AssemblyUtils.GetReleaseState().ToString();
36+
})
2737
.CreateLogger();
2838
var listener = new global::SerilogTraceListener.SerilogTraceListener();
2939
Trace.Listeners.Add(listener);

SoundSwitch/Framework/NotificationManager/MMNotificationClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace SoundSwitch.Framework.NotificationManager
88
{
99
public class MMNotificationClient : IMMNotificationClient, IDisposable
1010
{
11-
public static MMNotificationClient Instance { get; } = new MMNotificationClient();
11+
public static MMNotificationClient Instance { get; } = new ();
1212
private MMDeviceEnumerator _enumerator;
1313

1414
public event EventHandler<DeviceDefaultChangedEvent> DefaultDeviceChanged;

SoundSwitch/Framework/Profile/UI/ProfileTrayIconBuilder.cs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using SoundSwitch.Common.Framework.Icon;
77
using SoundSwitch.Framework.Profile.Trigger;
88
using SoundSwitch.Model;
9+
using SoundSwitch.Properties;
910

1011
namespace SoundSwitch.Framework.Profile.UI
1112
{
@@ -58,6 +59,8 @@ private ProfileToolStripMenuItem BuildMenuItem(Profile profile)
5859
}
5960
}
6061

62+
image ??= Resources.profile_menu_icon;
63+
6164
return new ProfileToolStripMenuItem(profile, image, profileClicked => ProfileManager.SwitchAudio(profileClicked));
6265
}
6366
}

SoundSwitch/Framework/TrayIcon/TooltipInfoManager/TootipInfo/TooltipInfoBoth.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo
1818
{
1919
public class TooltipInfoBoth : ITooltipInfo
2020
{
21+
private readonly TooltipInfoRecording _tooltipInfoRecording = new();
22+
private readonly TooltipInfoPlayback _tooltipInfoPlayback = new();
23+
2124
public TooltipInfoTypeEnum TypeEnum => TooltipInfoTypeEnum.Both;
2225
public string Label => SettingsStrings.tooltipOnHoverOptionBothDevices;
2326

@@ -27,8 +30,8 @@ public class TooltipInfoBoth : ITooltipInfo
2730
/// <returns></returns>
2831
public string TextToDisplay()
2932
{
30-
var playbackToDisplay = new TooltipInfoPlayback().TextToDisplay();
31-
var recordingToDisplay = new TooltipInfoRecording().TextToDisplay();
33+
var playbackToDisplay = _tooltipInfoPlayback.TextToDisplay();
34+
var recordingToDisplay = _tooltipInfoRecording.TextToDisplay();
3235

3336
if (playbackToDisplay == null || recordingToDisplay == null)
3437
return null;

SoundSwitch/Framework/TrayIcon/TooltipInfoManager/TootipInfo/TooltipInfoPlayback.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
* GNU General Public License for more details.
1313
********************************************************************/
1414

15-
using System.Linq;
1615
using SoundSwitch.Audio.Manager;
1716
using SoundSwitch.Audio.Manager.Interop.Enum;
1817
using SoundSwitch.Localization;
19-
using SoundSwitch.Model;
2018

2119
namespace SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo
2220
{
@@ -31,18 +29,10 @@ public class TooltipInfoPlayback : ITooltipInfo
3129
/// <returns></returns>
3230
public string TextToDisplay()
3331
{
34-
var audioDevices = AppModel.Instance.ActiveAudioDeviceLister?.PlaybackDevices;
35-
if (audioDevices == null)
36-
{
37-
return string.Format(SettingsStrings.activePlayback, "Unknown");
38-
}
39-
40-
var playbackDefaultDevice = audioDevices
41-
.FirstOrDefault(device =>
42-
AudioSwitcher.Instance.IsDefault(device.Id, (EDataFlow)device.Type, ERole.eConsole));
32+
var playbackDefaultDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eConsole);
4333
return playbackDefaultDevice == null
4434
? null
45-
: string.Format(SettingsStrings.activePlayback, playbackDefaultDevice);
35+
: string.Format(SettingsStrings.activePlayback, playbackDefaultDevice.NameClean);
4636
}
4737

4838
public override string ToString()

SoundSwitch/Framework/TrayIcon/TooltipInfoManager/TootipInfo/TooltipInfoRecording.cs

+5-12
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,27 @@
1212
* GNU General Public License for more details.
1313
********************************************************************/
1414

15-
using System.Linq;
1615
using SoundSwitch.Audio.Manager;
1716
using SoundSwitch.Audio.Manager.Interop.Enum;
1817
using SoundSwitch.Localization;
19-
using SoundSwitch.Model;
2018

2119
namespace SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo
2220
{
2321
public class TooltipInfoRecording : ITooltipInfo
2422
{
2523
public TooltipInfoTypeEnum TypeEnum => TooltipInfoTypeEnum.Recording;
26-
public string Label => SettingsStrings.tooltipOnHoverOptionRecordingDevice;
24+
public string Label => SettingsStrings.tooltipOnHoverOptionRecordingDevice;
2725

2826
/// <summary>
2927
/// The text to display for this ToolTip
3028
/// </summary>
3129
/// <returns></returns>
3230
public string TextToDisplay()
3331
{
34-
var recordingDevices = AppModel.Instance.ActiveAudioDeviceLister?.RecordingDevices;
35-
if (recordingDevices == null)
36-
{
37-
return string.Format(SettingsStrings.activeRecording, "Unknown");
38-
}
39-
40-
var recordingDevice = recordingDevices?.FirstOrDefault(device =>
41-
AudioSwitcher.Instance.IsDefault(device.Id, (EDataFlow) device.Type, ERole.eConsole));
42-
return recordingDevice == null ? null : string.Format(SettingsStrings.activeRecording, recordingDevice);
32+
var recordingDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eConsole);
33+
return recordingDevice == null
34+
? null
35+
: string.Format(SettingsStrings.activeRecording, recordingDevice.NameClean);
4336
}
4437

4538
public override string ToString()

SoundSwitch/Localization/AboutStrings.es.resx

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,21 @@
107107
<value>Versión</value>
108108
</data>
109109
<data name="author" xml:space="preserve">
110-
<value>Autor e Información de Programa</value>
110+
<value>Información de autoría y del programa</value>
111111
</data>
112112
<data name="credits" xml:space="preserve">
113-
<value>Creditos y Atribuciones</value>
113+
<value>Créditos y atribuciones</value>
114114
</data>
115115
<data name="defaultPlaybackDeviceChange" xml:space="preserve">
116-
<value>Cambio de dispositivo de reproducción</value>
116+
<value>Cambio de dispositivo de reproducción predeterminado</value>
117117
</data>
118118
<data name="keyboardHotkeys" xml:space="preserve">
119-
<value>Sistema de accesos directos de teclado</value>
119+
<value>Sistema de atajos de teclado</value>
120120
</data>
121121
<data name="icons" xml:space="preserve">
122122
<value>Iconos</value>
123123
</data>
124124
<data name="logo" xml:space="preserve">
125-
<value>Logo hecho por</value>
125+
<value>Logotipo creado por</value>
126126
</data>
127127
</root>

SoundSwitch/Localization/AboutStrings.pt.resx

+10-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<value>Ícones</value>
6363
</data>
6464
<data name="defaultPlaybackDeviceChange" xml:space="preserve">
65-
<value>Troca de aparelho de reprodução</value>
65+
<value>Trocar aparelho de reprodução predefinido</value>
6666
</data>
6767
<data name="credits" xml:space="preserve">
6868
<value>Contribuidores</value>
@@ -76,4 +76,13 @@
7676
<data name="created" xml:space="preserve">
7777
<value>Criado por</value>
7878
</data>
79+
<data name="logo" xml:space="preserve">
80+
<value>Logótipo feito por</value>
81+
</data>
82+
<data name="keyboardHotkeys" xml:space="preserve">
83+
<value>Sistema de acesso direto de teclado</value>
84+
</data>
85+
<data name="maintained" xml:space="preserve">
86+
<value>Mantido por</value>
87+
</data>
7988
</root>

0 commit comments

Comments
 (0)