2021-02-28 13:55:47 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2021-02-24 19:35:01 +01: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)
|
|
|
|
|
{
|
2021-03-08 20:18:47 +01:00
|
|
|
|
Application.Current?.Dispatcher.Invoke(() =>
|
2021-02-24 19:35:01 +01:00
|
|
|
|
{
|
|
|
|
|
if (window == null)
|
|
|
|
|
{
|
|
|
|
|
windowViewModel = new OSDWindowViewModel();
|
|
|
|
|
window = new OSDWindow(windowViewModel);
|
2021-02-28 13:55:47 +01:00
|
|
|
|
window.Closed += WindowOnClosed;
|
2021-02-24 19:35:01 +01:00
|
|
|
|
|
|
|
|
|
hideTimer = new Timer(state =>
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
}, null, OSDTimeout, Timeout.Infinite);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
hideTimer.Change(OSDTimeout, Timeout.Infinite);
|
|
|
|
|
|
|
|
|
|
windowViewModel.SetDevice(device);
|
|
|
|
|
window.Show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 13:55:47 +01:00
|
|
|
|
|
|
|
|
|
private static void WindowOnClosed(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-06-09 08:38:01 +02:00
|
|
|
|
// ReSharper disable once PossibleUnintendedReferenceComparison - it's intended.
|
|
|
|
|
if (sender != window)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-02-28 13:55:47 +01:00
|
|
|
|
hideTimer?.Dispose();
|
|
|
|
|
hideTimer = null;
|
2021-03-08 20:18:47 +01:00
|
|
|
|
|
|
|
|
|
window = null;
|
2021-02-28 13:55:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:18:47 +01:00
|
|
|
|
|
2021-02-24 19:35:01 +01:00
|
|
|
|
private static void Hide()
|
|
|
|
|
{
|
2021-02-28 13:55:47 +01:00
|
|
|
|
Application.Current?.Dispatcher.Invoke(() =>
|
2021-02-24 19:35:01 +01:00
|
|
|
|
{
|
|
|
|
|
window?.Close();
|
|
|
|
|
window = null;
|
|
|
|
|
windowViewModel = null;
|
|
|
|
|
|
|
|
|
|
hideTimer?.Dispose();
|
|
|
|
|
hideTimer = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|