Rewrite how picking a matching audio session works
rewrite the UI layer to make it only send updates to the stream deck if needed
This commit is contained in:
65
src/FocusVolumeControl/UI/UIState.cs
Normal file
65
src/FocusVolumeControl/UI/UIState.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarRaider.SdTools;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace FocusVolumeControl.UI
|
||||
{
|
||||
internal class UIState
|
||||
{
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; private init; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public ValueWithOpacity<string> Value { get; private init; }
|
||||
|
||||
[JsonProperty("indicator")]
|
||||
public ValueWithOpacity<float>Indicator { get; private init; }
|
||||
|
||||
[JsonProperty("icon")]
|
||||
public ValueWithOpacity<string> icon { get; private init; }
|
||||
|
||||
public static UIState Build(ActiveAudioSessionWrapper session)
|
||||
{
|
||||
var volume = session.GetVolumeLevel();
|
||||
|
||||
var opacity = session.GetMuted() != true ? 1 : 0.5f;
|
||||
|
||||
var iconData = "";
|
||||
|
||||
if (session.Icon != null)
|
||||
{
|
||||
iconData = session.Icon;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var icon = Icon.ExtractAssociatedIcon(session.ExecutablePath);
|
||||
iconData = Tools.ImageToBase64(icon.ToBitmap(), true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
iconData = "Image/pluginIcon.png";
|
||||
}
|
||||
session.Icon = iconData;
|
||||
}
|
||||
|
||||
|
||||
return new UIState()
|
||||
{
|
||||
Title = session.DisplayName,
|
||||
Value = new() { Value = $"{volume}%", Opacity = opacity },
|
||||
Indicator = new() { Value = volume, Opacity = opacity },
|
||||
icon = new() { Value = iconData, Opacity = opacity },
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
20
src/FocusVolumeControl/UI/ValueWithOpacity.cs
Normal file
20
src/FocusVolumeControl/UI/ValueWithOpacity.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FocusVolumeControl.UI
|
||||
{
|
||||
internal class ValueWithOpacity<T>
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public required T Value { get; init; }
|
||||
|
||||
[JsonProperty("opacity")]
|
||||
public required float Opacity { get; init; }
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user