2021-02-28 12:55:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
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);
|
2021-02-28 12:55:47 +00:00
|
|
|
|
window.Closed += WindowOnClosed;
|
2021-02-24 18:35:01 +00:00
|
|
|
|
|
|
|
|
|
hideTimer = new Timer(state =>
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
}, null, OSDTimeout, Timeout.Infinite);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
hideTimer.Change(OSDTimeout, Timeout.Infinite);
|
|
|
|
|
|
|
|
|
|
windowViewModel.SetDevice(device);
|
|
|
|
|
window.Show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 12:55:47 +00:00
|
|
|
|
|
|
|
|
|
private static void WindowOnClosed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
hideTimer?.Dispose();
|
|
|
|
|
hideTimer = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-02-24 18:35:01 +00:00
|
|
|
|
private static void Hide()
|
|
|
|
|
{
|
2021-02-28 12:55:47 +00:00
|
|
|
|
Application.Current?.Dispatcher.Invoke(() =>
|
2021-02-24 18:35:01 +00:00
|
|
|
|
{
|
|
|
|
|
window?.Close();
|
|
|
|
|
window = null;
|
|
|
|
|
windowViewModel = null;
|
|
|
|
|
|
|
|
|
|
hideTimer?.Dispose();
|
|
|
|
|
hideTimer = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|