1
0
mirror of synced 2024-11-23 16:23:50 +00:00
MassiveKnob/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs

63 lines
1.6 KiB
C#
Raw Normal View History

using System;
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);
window.Closed += WindowOnClosed;
hideTimer = new Timer(state =>
{
Hide();
}, null, OSDTimeout, Timeout.Infinite);
}
else
hideTimer.Change(OSDTimeout, Timeout.Infinite);
windowViewModel.SetDevice(device);
window.Show();
});
}
private static void WindowOnClosed(object sender, EventArgs e)
{
hideTimer?.Dispose();
hideTimer = null;
window = null;
}
private static void Hide()
{
Application.Current?.Dispatcher.Invoke(() =>
{
window?.Close();
window = null;
windowViewModel = null;
hideTimer?.Dispose();
hideTimer = null;
});
}
}
}