1
0
mirror of synced 2024-11-23 16:23:50 +00:00
MassiveKnob/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs
Mark van Renswoude 543b55f3ba Added support for analog outputs (basic PWM) to Arduino Sketch
Added support for binding digital output actions to analog outputs
Fixed a few NullReferenceExceptions
Fixed Serial "Connecting..." state
Fixed update issues when multiple VoiceMeeter output actions are configured
Fixed VoiceMeeter Remote not logging out
2021-03-08 20:18:47 +01:00

63 lines
1.6 KiB
C#

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;
});
}
}
}