sync icons

This commit is contained in:
wildtail
2026-03-04 19:37:30 +03:00
parent be8ca26bde
commit 332064609b
12 changed files with 70 additions and 33 deletions
+8 -4
View File
@@ -24,7 +24,7 @@ public partial class App : Application
private const string TsDeviceId =
"{0.0.1.00000000}.{cf287ff4-c39e-4b09-bc8d-b927c7d59779}";
public void UpdateIcon()
public MicMode UpdateIcon()
{
using var enumerator = new MMDeviceEnumerator();
@@ -40,7 +40,7 @@ public partial class App : Application
if (devices.Count == 0)
{
_trayIcon.Icon = _trayIcons[MicMode.None];
return;
return MicMode.None;
}
bool tsMuted = devices.Any(x =>
@@ -56,9 +56,13 @@ public partial class App : Application
if (anyMuted)
mode |= MicMode.Any;
_trayIcon.Icon = _trayIcons[mode];
Dispatcher.Invoke(() =>
{
_trayIcon.Icon = _trayIcons[mode];
});
return mode;
}
protected override void OnStartup(StartupEventArgs e)
+14 -4
View File
@@ -2,6 +2,7 @@
using System.Net;
using System.Text;
using System.Text.Json;
using Application = System.Windows.Application;
namespace HttpKeys;
@@ -62,19 +63,28 @@ public class Listener
if (p.ActionId == "tsmute")
MicController.ToggleTsMicsSimple(p.IsOn);
await WriteText(ctx, 200, "OK");
await WriteText(ctx, 200);
}
catch (Exception ex)
{
Log("Error: " + ex.Message);
await WriteText(ctx, 500, "Error");
await WriteText(ctx, 500);
}
}
}
private static async Task WriteText(HttpListenerContext ctx, int statusCode, string text)
private static async Task WriteText(HttpListenerContext ctx, int statusCode)
{
var bytes = Encoding.UTF8.GetBytes(text);
var mode = ((App)Application.Current).UpdateIcon();
var response = new
{
mode = mode
};
var json = JsonSerializer.Serialize(response);
var bytes = Encoding.UTF8.GetBytes(json);
ctx.Response.StatusCode = statusCode;
ctx.Response.ContentType = "text/plain; charset=utf-8";
ctx.Response.ContentLength64 = bytes.Length;
-1
View File
@@ -37,6 +37,5 @@ public partial class MainWindow : Window
private void Log(string log)
{
Dispatcher.Invoke(() => Logs.Add($"{DateTime.Now}:: {log}"));
Console.WriteLine(log);
}
}
+1 -9
View File
@@ -1,5 +1,4 @@
using NAudio.CoreAudioApi;
using Application = System.Windows.Application;
namespace HttpKeys;
@@ -42,9 +41,6 @@ public static class MicController
endpoint.Mute = shouldBeMuted;
}
var app = Application.Current;
app.Dispatcher.Invoke(() =>(app as App)?.UpdateIcon());
}
/// <summary>
@@ -56,9 +52,6 @@ public static class MicController
"{0.0.1.00000000}.{cf287ff4-c39e-4b09-bc8d-b927c7d59779}",
isOn
);
var app = Application.Current;
app.Dispatcher.Invoke(() =>(app as App)?.UpdateIcon());
}
private static void SetMicStateById(string deviceId, bool isOn)
@@ -85,8 +78,7 @@ public static class MicController
var endpoint = device.AudioEndpointVolume;
bool shouldBeMuted = !isOn;
// Уже в нужном состоянии — выходим
if (endpoint.Mute == shouldBeMuted)
return;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+25 -13
View File
@@ -11,6 +11,8 @@ const ACTION_MAP = {
},
};
let cts = [];
// подключение от D6
function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo) {
uuid = inUUID;
@@ -24,33 +26,36 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo)
}));
};
websocket.onmessage = function (evt) {
websocket.onmessage = async function (evt) {
const msg = JSON.parse(evt.data);
const { event, action, context, payload } = msg;
if (event === "willAppear") {
cts.push(context)
const s = (payload && payload.settings) || { isOn: false };
ctxSettings.set(context, s);
setState(context, s.isOn ? 1 : 0);
// setState(context, s.isOn ? 1 : 0);
const cfg = ACTION_MAP[action];
if (!cfg) return;
post("http://127.0.0.1:16888/press", {
var resp = await postJson("http://127.0.0.1:16888/press", {
actionUUID: action,
actionId: cfg.actionId,
toggleChanged: false,
isOn: !s.isOn,
});
setState(element, resp?.mode);
return;
}
if (event === "didReceiveSettings") {
const s = payload.settings || { isOn: false };
ctxSettings.set(context, s);
setState(context, s.isOn ? 1 : 0);
// setState(context, s.isOn ? 1 : 0);
return;
}
@@ -62,32 +67,37 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo)
}
// обработка нажатия
function handleKeyDown(action, context) {
async function handleKeyDown(action, context) {
let s = ctxSettings.get(context) || { isOn: false };
const prevState = s.isOn;
s.isOn = !s.isOn;
const newState = s.isOn;
ctxSettings.set(context, s);
setState(context, newState ? 1 : 0);
websocket.send(JSON.stringify({
event: "setSettings",
context: context,
payload: s
}));
// setState(context, newState ? 1 : 0);
const cfg = ACTION_MAP[action];
if (!cfg) return;
post("http://127.0.0.1:16888/press", {
var resp = await postJson("http://127.0.0.1:16888/press", {
actionUUID: action,
actionId: cfg.actionId,
toggleChanged: prevState !== newState,
isOn: !newState,
cts
});
cts.forEach(element => {
console.log(element)
setState(element, resp?.mode);
});
}
@@ -101,10 +111,12 @@ function setState(context, stateIndex) {
}
// HTTP POST
function post(url, data) {
fetch(url, {
async function postJson(url, data) {
const res = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data)
}).catch(err => console.error(err));
});
if (!res.ok) throw new Error("HTTP " + res.status);
return await res.json();
}
@@ -4,10 +4,10 @@
"Description": "D6 plugin: button -> HTTP POST to localhost",
"Icon": "icon",
"Name": "HTTP Keys",
"Version": "0.1.0",
"Version": "0.2.0",
"SDKVersion": 2,
"OS": [
{ "Platform": "windows", "MinimumVersion": "10" }
{ "Platform": "windows", "MinimumVersion": "11" }
],
"Software": { "MinimumVersion": "1.0" },
"Category": "Utilities",
@@ -26,6 +26,16 @@
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/any_off",
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/ts_off",
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/micro_off",
"TitleAlignment": "middle",
@@ -45,6 +55,16 @@
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/groupmicro_on",
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/groupmicro_off",
"TitleAlignment": "middle",
"FontSize": "12"
},
{
"Image": "icons/groupmicro_off",
"TitleAlignment": "middle",