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