66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
|
|
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 },
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|