diff --git a/HttpKeys/App.xaml.cs b/HttpKeys/App.xaml.cs index 6a1f0a6..ba8f59b 100644 --- a/HttpKeys/App.xaml.cs +++ b/HttpKeys/App.xaml.cs @@ -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) diff --git a/HttpKeys/Listener.cs b/HttpKeys/Listener.cs index 0d86923..f62ae5f 100644 --- a/HttpKeys/Listener.cs +++ b/HttpKeys/Listener.cs @@ -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; diff --git a/HttpKeys/MainWindow.xaml.cs b/HttpKeys/MainWindow.xaml.cs index 7d1418b..3e8596f 100644 --- a/HttpKeys/MainWindow.xaml.cs +++ b/HttpKeys/MainWindow.xaml.cs @@ -37,6 +37,5 @@ public partial class MainWindow : Window private void Log(string log) { Dispatcher.Invoke(() => Logs.Add($"{DateTime.Now}:: {log}")); - Console.WriteLine(log); } } \ No newline at end of file diff --git a/HttpKeys/MicController.cs b/HttpKeys/MicController.cs index a993812..243c871 100644 --- a/HttpKeys/MicController.cs +++ b/HttpKeys/MicController.cs @@ -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()); } /// @@ -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; diff --git a/HttpKeys/all_mute.wav b/HttpKeys/all_mute.wav new file mode 100644 index 0000000..f5ac160 Binary files /dev/null and b/HttpKeys/all_mute.wav differ diff --git a/HttpKeys/all_unmute.wav b/HttpKeys/all_unmute.wav new file mode 100644 index 0000000..fb3657f Binary files /dev/null and b/HttpKeys/all_unmute.wav differ diff --git a/HttpKeys/any_mute.wav b/HttpKeys/any_mute.wav new file mode 100644 index 0000000..ed9e889 Binary files /dev/null and b/HttpKeys/any_mute.wav differ diff --git a/HttpKeys/any_unmute.wav b/HttpKeys/any_unmute.wav new file mode 100644 index 0000000..ef07142 Binary files /dev/null and b/HttpKeys/any_unmute.wav differ diff --git a/HttpKeys/ts_mute.wav b/HttpKeys/ts_mute.wav new file mode 100644 index 0000000..ac5f843 Binary files /dev/null and b/HttpKeys/ts_mute.wav differ diff --git a/HttpKeys/ts_unmute.wav b/HttpKeys/ts_unmute.wav new file mode 100644 index 0000000..6423170 Binary files /dev/null and b/HttpKeys/ts_unmute.wav differ diff --git a/Plugin/ru.wildtail.httpkeys.sdPlugin/main.js b/Plugin/ru.wildtail.httpkeys.sdPlugin/main.js index c585081..3c89d46 100644 --- a/Plugin/ru.wildtail.httpkeys.sdPlugin/main.js +++ b/Plugin/ru.wildtail.httpkeys.sdPlugin/main.js @@ -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(); } \ No newline at end of file diff --git a/Plugin/ru.wildtail.httpkeys.sdPlugin/manifest.json b/Plugin/ru.wildtail.httpkeys.sdPlugin/manifest.json index 3c1837f..4eacce6 100644 --- a/Plugin/ru.wildtail.httpkeys.sdPlugin/manifest.json +++ b/Plugin/ru.wildtail.httpkeys.sdPlugin/manifest.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",