1
0
mirror of synced 2024-09-28 21:06:07 +00:00
MassiveKnob/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs
Mark van Renswoude 28c25c8b43 Implemented OSD
Implemented mute/unmute input and output actions
Changed MockDevice to EmulatorDevice with UI for easier testing
2021-02-24 19:35:01 +01:00

51 lines
1.4 KiB
C#

using System.Threading;
using System.Windows;
using AudioSwitcher.AudioApi;
namespace MassiveKnob.Plugin.CoreAudio.OSD
{
public static class OSDManager
{
private const int OSDTimeout = 2500;
private static OSDWindowViewModel windowViewModel;
private static Window window;
private static Timer hideTimer;
public static void Show(IDevice device)
{
Application.Current.Dispatcher.Invoke(() =>
{
if (window == null)
{
windowViewModel = new OSDWindowViewModel();
window = new OSDWindow(windowViewModel);
hideTimer = new Timer(state =>
{
Hide();
}, null, OSDTimeout, Timeout.Infinite);
}
else
hideTimer.Change(OSDTimeout, Timeout.Infinite);
windowViewModel.SetDevice(device);
window.Show();
});
}
private static void Hide()
{
Application.Current.Dispatcher.Invoke(() =>
{
window?.Close();
window = null;
windowViewModel = null;
hideTimer?.Dispose();
hideTimer = null;
});
}
}
}