Skip to content

Commit 8fc9cc4

Browse files
committed
fix(Tooltip::Volume): Be sure the volume of the tooltip is properly shown
See #1096
1 parent 9b692c8 commit 8fc9cc4

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

SoundSwitch/Framework/TrayIcon/TooltipInfoManager/TooltipInfoManager.cs

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public void SetIconText()
7272

7373
if (text == null)
7474
return;
75+
//Only if changed
76+
if (_icon.Text == text)
77+
{
78+
return;
79+
}
7580
Fixes.SetNotifyIconText(_icon, $"{Application.ProductName}\n{text}");
7681
}
7782
}

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

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

15+
using NAudio.CoreAudioApi;
1516
using SoundSwitch.Audio.Manager;
1617
using SoundSwitch.Audio.Manager.Interop.Enum;
18+
using SoundSwitch.Common.Framework.Audio.Device;
1719
using SoundSwitch.Localization;
20+
using SoundSwitch.Model;
1821

1922
namespace SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo
2023
{
2124
public class TooltipInfoPlayback : ITooltipInfo
2225
{
26+
private DeviceFullInfo _defaultDevice;
2327
public TooltipInfoTypeEnum TypeEnum => TooltipInfoTypeEnum.Playback;
2428
public string Label => SettingsStrings.tooltipOnHoverOptionPlaybackDevice;
2529

30+
public TooltipInfoPlayback()
31+
{
32+
AppModel.Instance.DefaultDeviceChanged += (sender, @event) =>
33+
{
34+
if (@event.Device.Type != DataFlow.Render)
35+
return;
36+
_defaultDevice = @event.Device;
37+
};
38+
_defaultDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eConsole);
39+
}
40+
2641
/// <summary>
2742
/// The text to display for this ToolTip
2843
/// </summary>
2944
/// <returns></returns>
3045
public string TextToDisplay()
3146
{
32-
var playbackDefaultDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eConsole);
33-
return playbackDefaultDevice == null
47+
return _defaultDevice == null
3448
? null
35-
: string.Format(SettingsStrings.activePlayback + " - {1}%", playbackDefaultDevice.NameClean, playbackDefaultDevice.Volume);
49+
: string.Format(SettingsStrings.activePlayback + " - {1}%", _defaultDevice.NameClean, _defaultDevice.Volume);
3650
}
3751

3852
public override string ToString()

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

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

15+
using NAudio.CoreAudioApi;
1516
using SoundSwitch.Audio.Manager;
1617
using SoundSwitch.Audio.Manager.Interop.Enum;
18+
using SoundSwitch.Common.Framework.Audio.Device;
1719
using SoundSwitch.Localization;
20+
using SoundSwitch.Model;
1821

1922
namespace SoundSwitch.Framework.TrayIcon.TooltipInfoManager.TootipInfo
2023
{
2124
public class TooltipInfoRecording : ITooltipInfo
2225
{
26+
private DeviceFullInfo _defaultDevice;
2327
public TooltipInfoTypeEnum TypeEnum => TooltipInfoTypeEnum.Recording;
2428
public string Label => SettingsStrings.tooltipOnHoverOptionRecordingDevice;
2529

30+
public TooltipInfoRecording()
31+
{
32+
AppModel.Instance.DefaultDeviceChanged += (sender, @event) =>
33+
{
34+
if (@event.Device.Type != DataFlow.Capture)
35+
return;
36+
_defaultDevice = @event.Device;
37+
};
38+
_defaultDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eConsole);
39+
}
40+
2641
/// <summary>
2742
/// The text to display for this ToolTip
2843
/// </summary>
2944
/// <returns></returns>
3045
public string TextToDisplay()
3146
{
32-
var recordingDevice = AudioSwitcher.Instance.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eConsole);
33-
return recordingDevice == null
47+
return _defaultDevice == null
3448
? null
35-
: string.Format(SettingsStrings.activeRecording + " - {1}%", recordingDevice.NameClean, recordingDevice.Volume);
49+
: string.Format(SettingsStrings.activeRecording + " - {1}%", _defaultDevice.NameClean, _defaultDevice.Volume);
3650
}
3751

3852
public override string ToString()

SoundSwitch/UI/Component/TrayIcon.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private void PopulateSettingsMenu()
185185
_settingsMenu.Items.Add(TrayIconStrings.about, RessourceHelpSmallBitmap, (sender, e) => new About().Show());
186186
_settingsMenu.Items.Add(new ToolStripSeparator());
187187
_settingsMenu.Items.Add(TrayIconStrings.exit, RessourceExitBitmap, (sender, e) => Application.Exit());
188-
188+
189189
RoundedCorner.RoundCorner(_settingsMenu.Handle, RoundedCorner.DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND);
190190
}
191191

@@ -239,12 +239,12 @@ private void SetEventHandlers()
239239
break;
240240
}
241241
};
242-
AppModel.Instance.DefaultDeviceChanged += (_, _) => { _tooltipInfoManager.SetIconText(); };
243242
AppModel.Instance.UpdateModeChanged += (_, mode) =>
244243
{
245244
SetUpdateMenuItem(mode);
246245
PopulateSettingsMenu();
247246
};
247+
NotifyIcon.MouseMove += (sender, args) => { _tooltipInfoManager.SetIconText(); };
248248
}
249249

250250
private void NewReleaseAvailable(object sender, UpdateChecker.NewReleaseEvent newReleaseEvent)
@@ -336,8 +336,8 @@ public void UpdateDeviceSelectionList()
336336
_selectionMenu.Items.Add(new ToolStripSeparator());
337337
_selectionMenu.Items.AddRange(recordingDevices.Select(info => new ToolStripDeviceItem(DeviceClicked, info, info.Equals(defaultRecording))).ToArray());
338338
}
339+
339340
RoundedCorner.RoundCorner(_selectionMenu.Handle, RoundedCorner.DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND);
340-
341341
}
342342

343343
private void DeviceClicked(object sender, EventArgs e)

0 commit comments

Comments
 (0)