Skip to content

The agent that grows with you

fix(desktop): build and verify the Windows HUD helper without an SDK

brooklyn!d0381cea91db
diff --git a/apps/desktop/electron/native/hud-modifier-gesture.cs b/apps/desktop/electron/native/hud-modifier-gesture.cs
new file mode 100644
index 00000000000..778b858b6bd
--- /dev/null
+++ b/apps/desktop/electron/native/hud-modifier-gesture.cs
@@ -0,0 +1,31 @@
+// The same bounded, release-only gesture contract as hud-modifier-gesture.h.
+// No key history is retained, only the current chord's summary.
+internal sealed class HudModifierGesture
+{
+ private uint modifiers;
+ private bool started, both, blocked, releasing;
+ private long began;
+
+ internal bool Update(uint next, bool held, bool interrupted, long now)
+ {
+ if (held || interrupted || (next & ~3u) != 0) blocked = true;
+ uint pressed = next & ~modifiers;
+ if (releasing && pressed != 0) blocked = true;
+ if ((modifiers & ~next) != 0) releasing = true;
+ if (modifiers == 0 && !blocked && (next == 1 || next == 2))
+ {
+ started = true;
+ began = now;
+ }
+ if (next != 0 && !started) blocked = true;
+ if (next == 3 && started) both = true;
+ bool summon = next == 0 && both && !blocked && now >= began && now - began <= 500;
+ modifiers = next;
+ if (next == 0 && !held)
+ {
+ started = both = blocked = releasing = false;
+ began = 0;
+ }
+ return summon;
+ }
+}
diff --git a/apps/desktop/electron/native/hud-modifier-gesture.test.cs b/apps/desktop/electron/native/hud-modifier-gesture.test.cs
new file mode 100644
index 00000000000..04899a4b55c
--- /dev/null
+++ b/apps/desktop/electron/native/hud-modifier-gesture.test.cs
@@ -0,0 +1,42 @@
+using System;
+
+internal static class HudModifierGestureTests
+{
+ private static void Check(bool expected, params uint[] modifiers)
+ {
+ HudModifierGesture gesture = new HudModifierGesture();
+ bool summoned = false;
+ for (int i = 0; i < modifiers.Length; i++)
+ summoned |= gesture.Update(modifiers[i], false, false, i * 30);
+ if (summoned != expected) throw new Exception("Unexpected gesture result");
+ }
+
+ private static void Reject(bool held, bool interrupted, long release)
+ {
+ HudModifierGesture gesture = new HudModifierGesture();
+ gesture.Update(1, false, false, 0);
+ gesture.Update(3, held, interrupted, 30);
+ gesture.Update(2, false, false, 60);
+ if (gesture.Update(0, false, false, release)) throw new Exception("Interrupted/long gesture summoned");
+ // A rejected chord cannot poison the next clean tap.
+ gesture.Update(2, false, false, 1000);
+ gesture.Update(3, false, false, 1030);
+ gesture.Update(1, false, false, 1060);
+ if (!gesture.Update(0, false, false, 1090)) throw new Exception("Clean retry did not summon");
+ }
+
+ private static int Main()
+ {
+ Check(true, 1, 3, 2, 0);
+ Check(true, 2, 3, 1, 0);
+ Check(false, 1, 0);
+ Check(false, 3, 1, 0); // Startup-held chord.
+ Check(false, 1, 3, 1, 3, 2, 0); // Re-press during release.
+ Check(false, 1, 7, 3, 1, 0); // AltGr, extra modifiers, both Ctrl keys.
+ Reject(true, false, 90); // Another key or a held mouse button.
+ Reject(false, true, 90); // Repeat, click, wheel, or duplicate transition.
+ Reject(false, false, 501);
+ Console.WriteLine("gesture contracts passed");
+ return 0;
+ }
+}
diff --git a/apps/desktop/electron/native/hud-modifier-monitor-win.c b/apps/desktop/electron/native/hud-modifier-monitor-win.c
deleted file mode 100644
index 451f1c229a6..00000000000
--- a/apps/desktop/electron/native/hud-modifier-monitor-win.c
+++ /dev/null
@@ -1,122 +0,0 @@
-// Raw Input with INPUTSINK observes without hooks, grabs, or suppressing keys.
-#define WIN32_LEAN_AND_MEAN
-#define _WIN32_WINNT 0x0601
-#include <windows.h>
-#include <stdio.h>
-#include <string.h>
-#include "hud-modifier-gesture.h"
-
-static HudModifierGesture gesture;
-static bool keys[256]; // Current physical state, not a log or character buffer.
-static unsigned buttons;
-static HANDLE output;
-static void Emit(const char *line) {
- DWORD written = 0, size = (DWORD)strlen(line);
- if (!WriteFile(output, line, size, &written, NULL) || written != size) ExitProcess(0);
-}
-static void Unavailable(void) { Emit("{\"type\":\"error\",\"code\":\"unavailable\"}\n"); }
-static bool Target(unsigned key) { return key == VK_LCONTROL || key == VK_RCONTROL || key == VK_LMENU; }
-static bool MouseKey(unsigned key) {
- return key == VK_LBUTTON || key == VK_RBUTTON || key == VK_MBUTTON || key == VK_XBUTTON1 || key == VK_XBUTTON2;
-}
-static void Update(bool interrupted) {
- unsigned first = keys[VK_LCONTROL] + keys[VK_RCONTROL];
- // Right Alt is AltGr on many layouts. Never summon for the generated Ctrl+Alt
- // pair of an AltGr tap; Ctrl on either side + left Alt remains available.
- unsigned modifiers = (first ? 1u : 0u) | (keys[VK_LMENU] ? 2u : 0u) | (first > 1 ? 4u : 0u);
- bool held = buttons != 0;
- for (unsigned key = 0; key < 256; key++) {
- if (!Target(key) && !MouseKey(key) && key != VK_CONTROL && key != VK_MENU && key != VK_SHIFT) held |= keys[key];
- }
- if (HudModifierUpdate(&gesture, modifiers, held, interrupted, GetTickCount64())) Emit("{\"type\":\"summon\"}\n");
-}
-static void Snapshot(void) {
- for (unsigned key = 0; key < 256; key++) keys[key] = (GetAsyncKeyState((int)key) & 0x8000) != 0;
- buttons = keys[VK_LBUTTON] | (keys[VK_RBUTTON] << 1) | (keys[VK_MBUTTON] << 2)
- | (keys[VK_XBUTTON1] << 3) | (keys[VK_XBUTTON2] << 4);
- gesture = (HudModifierGesture){0};
- Update(true);
-}
-static LRESULT CALLBACK Observe(HWND window, UINT message, WPARAM wParam, LPARAM lParam) {
- if (message == WM_INPUT_DEVICE_CHANGE) {
- Snapshot();
- } else if (message == WM_INPUT) {
- RAWINPUT raw;
- UINT size = sizeof(raw);
- if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &raw, &size, sizeof(RAWINPUTHEADER)) == (UINT)-1) {
- Unavailable(); PostQuitMessage(3);
- } else if (raw.header.dwType == RIM_TYPEKEYBOARD) {
- RAWKEYBOARD *key = &raw.data.keyboard;
- unsigned code = key->VKey;
- if (code == VK_CONTROL) code = (key->Flags & RI_KEY_E0) ? VK_RCONTROL : VK_LCONTROL;
- if (code == VK_MENU) code = (key->Flags & RI_KEY_E0) ? VK_RMENU : VK_LMENU;
- if (code == VK_SHIFT) code = MapVirtualKeyW(key->MakeCode, MAPVK_VSC_TO_VK_EX);
- bool down = !(key->Flags & RI_KEY_BREAK);
- bool interrupted = code >= 256 || !Target(code);
- if (code < 256) {
- interrupted |= keys[code] == down; // Repeat, duplicate, or missed physical transition.
- keys[code] = down;
- }
- Update(interrupted);
- } else if (raw.header.dwType == RIM_TYPEMOUSE) {
- unsigned flags = raw.data.mouse.usButtonFlags;
- for (unsigned button = 0; button < 5; button++) {
- if (flags & (1u << (button * 2))) buttons |= 1u << button;
- if (flags & (2u << (button * 2))) buttons &= ~(1u << button);
- }
- Update(flags != 0 || buttons != 0); // Wheel, click, or motion while dragging.
- }
- // DefWindowProc performs Raw Input cleanup, not input consumption.
- } else if (message == WM_CLOSE) {
- DestroyWindow(window);
- return 0;
- } else if (message == WM_DESTROY) {
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProcW(window, message, wParam, lParam);
-}
-static DWORD WINAPI WatchParent(void *context) {
- char byte;
- DWORD count;
- HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
- while (ReadFile(input, &byte, 1, &count, NULL) && count) {}
- PostMessageW((HWND)context, WM_CLOSE, 0, 0);
- return 0;
-}
-int main(int argc, char **argv) {
- output = GetStdHandle(STD_OUTPUT_HANDLE);
- // Node supplies an anonymous/named pipe. Never block the window's input loop
- // behind a stalled parent; full-pipe writes fail and end this helper.
- DWORD mode = PIPE_NOWAIT;
- if (GetFileType(output) != FILE_TYPE_PIPE || !SetNamedPipeHandleState(output, &mode, NULL, NULL)) return 3;
- bool check = argc == 2 && strcmp(argv[1], "--check") == 0;
- if (argc > 1 && !check && !(argc == 2 && strcmp(argv[1], "--request-permission") == 0)) { Unavailable(); return 64; }
- HINSTANCE instance = GetModuleHandleW(NULL);
- WNDCLASSW definition = {0};
- definition.lpfnWndProc = Observe; definition.hInstance = instance;
- definition.lpszClassName = L"HermesHudModifierMonitor";
- if (!RegisterClassW(&definition)) { Unavailable(); return 3; }
- HWND window = CreateWindowExW(0, definition.lpszClassName, L"", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, instance, NULL);
- if (!window) { Unavailable(); return 3; }
- RAWINPUTDEVICE devices[] = {
- { 1, 6, RIDEV_INPUTSINK | RIDEV_DEVNOTIFY, window },
- { 1, 2, RIDEV_INPUTSINK | RIDEV_DEVNOTIFY, window }
- };
- if (!RegisterRawInputDevices(devices, 2, sizeof(RAWINPUTDEVICE))) { Unavailable(); DestroyWindow(window); return 3; }
- Snapshot();
- HANDLE parent = CreateThread(NULL, 0, WatchParent, window, 0, NULL);
- if (!parent) { Unavailable(); DestroyWindow(window); return 3; }
- Emit("{\"type\":\"ready\"}\n");
- MSG message;
- int result = 0;
- while (!check && (result = GetMessageW(&message, NULL, 0, 0)) > 0) {
- TranslateMessage(&message); DispatchMessageW(&message);
- }
- if (result < 0) Unavailable();
- DestroyWindow(window);
- CancelSynchronousIo(parent);
- CloseHandle(parent);
- UnregisterClassW(definition.lpszClassName, instance);
- return result < 0 ? 3 : 0;
-}
diff --git a/apps/desktop/electron/native/hud-modifier-monitor-win.cs b/apps/desktop/electron/native/hud-modifier-monitor-win.cs
new file mode 100644
index 00000000000..8164bd4eef0
--- /dev/null
+++ b/apps/desktop/electron/native/hud-modifier-monitor-win.cs
@@ -0,0 +1,212 @@
+// Built by the C# compiler included with Windows' .NET Framework. Raw Input is
+// passive: no hooks, event suppression, input injection, or recorded key data.
+using System;
+using System.Collections.Concurrent;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Windows.Forms;
+
+internal sealed class HudModifierWindow : NativeWindow, IDisposable
+{
+ [StructLayout(LayoutKind.Sequential)]
+ private struct RawDevice
+ {
+ internal ushort Page, Usage;
+ internal uint Flags;
+ internal IntPtr Target;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ private struct RawHeader
+ {
+ internal uint Type, Size;
+ internal IntPtr Device, WParam;
+ }
+
+ [DllImport("user32.dll", SetLastError = true)]
+ private static extern bool RegisterRawInputDevices(RawDevice[] devices, uint count, uint size);
+ [DllImport("user32.dll", SetLastError = true)]
+ private static extern uint GetRawInputData(IntPtr input, uint command, IntPtr data, ref uint size, uint headerSize);
+ [DllImport("user32.dll")]
+ private static extern short GetAsyncKeyState(int key);
+ [DllImport("user32.dll")]
+ internal static extern bool PostMessage(IntPtr window, uint message, IntPtr wParam, IntPtr lParam);
+
+ private readonly HudModifierGesture gesture = new HudModifierGesture();
+ private readonly bool[] keys = new bool[256];
+ private readonly Stopwatch clock = Stopwatch.StartNew();
+ private readonly IntPtr buffer = Marshal.AllocHGlobal(64);
+ private readonly int headerSize = Marshal.SizeOf(typeof(RawHeader));
+ private uint mouseButtons;
+
+ internal HudModifierWindow()
+ {
+ CreateHandle(new CreateParams { Caption = "Hermes HUD modifier input", Parent = new IntPtr(-3) });
+ RawDevice[] devices = {
+ new RawDevice { Page = 1, Usage = 6, Flags = 0x100 | 0x2000, Target = Handle },
+ new RawDevice { Page = 1, Usage = 2, Flags = 0x100 | 0x2000, Target = Handle }
+ };
+ if (!RegisterRawInputDevices(devices, 2, (uint)Marshal.SizeOf(typeof(RawDevice))))
+ throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
+ Snapshot();
+ }
+
+ private static bool ModifierKey(int key)
+ {
+ return (key >= 0xA0 && key <= 0xA5) || key == 0x5B || key == 0x5C ||
+ key == 0x10 || key == 0x11 || key == 0x12;
+ }
+
+ private uint Modifiers()
+ {
+ uint value = (keys[0xA2] || keys[0xA3]) ? 1u : 0u;
+ if (keys[0xA4]) value |= 2;
+ // Right Alt includes AltGr. It must never summon the HUD while typing.
+ if (keys[0xA5] || keys[0xA0] || keys[0xA1] || keys[0x5B] || keys[0x5C] ||
+ (keys[0xA2] && keys[0xA3])) value |= 4;
+ return value;
+ }
+
+ private bool Held()
+ {
+ if (mouseButtons != 0) return true;
+ for (int key = 8; key < 255; key++)
+ if (keys[key] && !ModifierKey(key)) return true;
+ return false;
+ }
+
+ private void Snapshot()
+ {
+ for (int key = 8; key < 255; key++) keys[key] = (GetAsyncKeyState(key) & 0x8000) != 0;
+ int[] buttons = { 1, 2, 4, 5, 6 };
+ mouseButtons = 0;
+ for (int i = 0; i < buttons.Length; i++)
+ if ((GetAsyncKeyState(buttons[i]) & 0x8000) != 0) mouseButtons |= 1u << i;
+ gesture.Update(Modifiers(), Held(), true, clock.ElapsedMilliseconds);
+ }
+
+ private void ReadInput(IntPtr input)
+ {
+ uint size = 64;
+ uint read = GetRawInputData(input, 0x10000003, buffer, ref size, (uint)headerSize);
+ if (read == uint.MaxValue || read < headerSize)
+ {
+ HudModifierMonitor.Emit("{\"type\":\"error\",\"code\":\"unavailable\"}");
+ Application.ExitThread();
+ return;
+ }
+ uint type = (uint)Marshal.ReadInt32(buffer);
+ IntPtr data = IntPtr.Add(buffer, headerSize);
+ bool interrupted;
+ if (type == 1 && read >= headerSize + 16)
+ {
+ int key = (ushort)Marshal.ReadInt16(data, 6);
+ int flags = (ushort)Marshal.ReadInt16(data, 2);
+ bool extended = (flags & 2) != 0;
+ if (key == 0x11) key = extended ? 0xA3 : 0xA2;
+ if (key == 0x12) key = extended ? 0xA5 : 0xA4;
+ if (key == 0x10) key = Marshal.ReadInt16(data) == 0x36 ? 0xA1 : 0xA0;
+ if (key < 8 || key >= 255) return;
+ bool down = (flags & 1) == 0;
+ interrupted = keys[key] == down || (key != 0xA2 && key != 0xA3 && key != 0xA4);
+ keys[key] = down;
+ }
+ else if (type == 0 && read >= headerSize + 24)
+ {
+ uint flags = (ushort)Marshal.ReadInt16(data, 4);
+ for (int i = 0; i < 5; i++)
+ {
+ if ((flags & (1u << (2 * i))) != 0) mouseButtons |= 1u << i;
+ if ((flags & (2u << (2 * i))) != 0) mouseButtons &= ~(1u << i);
+ }
+ interrupted = flags != 0;
+ }
+ else return;
+ if (gesture.Update(Modifiers(), Held(), interrupted, clock.ElapsedMilliseconds))
+ HudModifierMonitor.Emit("{\"type\":\"summon\"}");
+ }
+
+ protected override void WndProc(ref Message message)
+ {
+ if (message.Msg == 0x00FF) ReadInput(message.LParam);
+ else if (message.Msg == 0x00FE) Snapshot();
+ else if (message.Msg == 0x0010)
+ {
+ Application.ExitThread();
+ return;
+ }
+ base.WndProc(ref message);
+ }
+
+ public void Dispose()
+ {
+ DestroyHandle();
+ Marshal.FreeHGlobal(buffer);
+ }
+}
+
+internal static class HudModifierMonitor
+{
+ // Pipe writes never block the input loop, and a stalled parent cannot grow
+ // an unbounded queue. Stdin EOF tears down Raw Input registration on exit.
+ private static readonly BlockingCollection<string> Output = new BlockingCollection<string>(16);
+
+ internal static void Emit(string message)
+ {
+ if (!Output.TryAdd(message)) Environment.Exit(3);
+ }
+
+ [STAThread]
+ private static int Main(string[] args)
+ {
+ Thread writer = new Thread(delegate()
+ {
+ try
+ {
+ foreach (string message in Output.GetConsumingEnumerable())
+ {
+ Console.Out.WriteLine(message);
+ Console.Out.Flush();
+ }
+ }
+ catch (IOException) { Environment.Exit(3); }
+ });
+ writer.IsBackground = true;
+ writer.Start();
+ int exitCode = 0;
+ try
+ {
+ Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
+ using (HudModifierWindow window = new HudModifierWindow())
+ {
+ Emit("{\"type\":\"ready\"}");
+ if (Array.IndexOf(args, "--check") < 0)
+ {
+ IntPtr handle = window.Handle;
+ Thread parent = new Thread(delegate()
+ {
+ try
+ {
+ using (Stream input = Console.OpenStandardInput())
+ while (input.ReadByte() >= 0) { }
+ }
+ catch (IOException) { }
+ HudModifierWindow.PostMessage(handle, 0x0010, IntPtr.Zero, IntPtr.Zero);
+ });
+ parent.IsBackground = true;
+ parent.Start();
+ Application.Run();
+ }
+ }
+ }
+ catch (Exception)
+ {
+ Emit("{\"type\":\"error\",\"code\":\"unavailable\"}");
+ exitCode = 1;
+ }
+ Output.CompleteAdding();
+ return writer.Join(1000) ? exitCode : 3;
+ }
+}
diff --git a/apps/desktop/electron/native/hud-modifier-windows.test.mjs b/apps/desktop/electron/native/hud-modifier-windows.test.mjs
new file mode 100644
index 00000000000..d42155469f1
--- /dev/null
+++ b/apps/desktop/electron/native/hud-modifier-windows.test.mjs
@@ -0,0 +1,87 @@
+import assert from 'node:assert/strict'
+import { execFile, spawn } from 'node:child_process'
+import { once } from 'node:events'
+import { mkdtempSync, rmSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { promisify } from 'node:util'
+import { test } from 'node:test'
+import { fileURLToPath } from 'node:url'
+
+import { buildHudModifierMonitor, resolveWindowsFrameworkCompiler } from '../../scripts/build-hud-modifier-monitor.mjs'
+
+// Run on Windows, without a developer compiler on PATH, using the real Node
+// pipe transport. No input is synthesized and no user desktop is controlled.
+test('Windows builds and starts its HUD helper without Clang or a developer SDK', {
+ skip: process.platform !== 'win32', timeout: 60_000
+}, async () => {
+ const distDir = mkdtempSync(join(tmpdir(), 'hud-windows-'))
+ const path = process.env.PATH
+ const cc = process.env.CC
+ let child
+ try {
+ process.env.PATH = ''
+ process.env.CC = 'hermes-test-no-native-compiler'
+ let binary
+ try {
+ binary = buildHudModifierMonitor({ distDir })
+ } finally {
+ process.env.PATH = path
+ if (cc === undefined) delete process.env.CC
+ else process.env.CC = cc
+ }
+ assert.ok(binary, 'A Windows build must include a working HUD helper, not silently skip it')
+ const check = await promisify(execFile)(binary, ['--check'], { timeout: 15_000, windowsHide: true })
+ assert.equal(JSON.parse(check.stdout.trim()).type, 'ready')
+ child = spawn(binary, [], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] })
+ const exited = once(child, 'exit')
+ exited.catch(() => {})
+ await new Promise((resolve, reject) => {
+ let output = ''
+ const timer = setTimeout(() => reject(new Error('HUD helper did not become ready')), 15_000)
+ child.once('error', error => { clearTimeout(timer); reject(error) })
+ child.once('exit', (code, signal) => {
+ clearTimeout(timer)
+ reject(new Error(`HUD helper exited before readiness: ${code}/${signal}`))
+ })
+ child.stdout.on('data', chunk => {
+ output += chunk.toString()
+ if (output.includes('\n')) {
+ clearTimeout(timer)
+ try {
+ assert.equal(JSON.parse(output.trim()).type, 'ready')
+ resolve()
+ } catch (error) { reject(error) }
+ }
+ })
+ })
+ child.stdin.end()
+ assert.deepEqual(await exited, [0, null], 'stdin EOF must release the listener and exit')
+ } finally {
+ if (child?.pid && child.exitCode === null) {
+ const closed = once(child, 'close')
+ child.kill()
+ await closed
+ }
+ rmSync(distDir, { recursive: true, force: true })
+ }
+})
+
+test('Windows gesture rejects ordinary shortcuts and recovers for the next tap', {
+ skip: process.platform !== 'win32', timeout: 30_000
+}, async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'hud-gesture-'))
+ const exe = join(dir, 'gesture.exe')
+ const run = promisify(execFile)
+ try {
+ await run(resolveWindowsFrameworkCompiler(), [
+ '/nologo', '/target:exe', '/warnaserror+', `/out:${exe}`,
+ fileURLToPath(new URL('./hud-modifier-gesture.cs', import.meta.url)),
+ fileURLToPath(new URL('./hud-modifier-gesture.test.cs', import.meta.url))
+ ], { windowsHide: true })
+ const result = await run(exe, [], { windowsHide: true })
+ assert.equal(result.stdout.trim(), 'gesture contracts passed')
+ } finally {
+ rmSync(dir, { recursive: true, force: true })
+ }
+})
diff --git a/apps/desktop/scripts/build-hud-modifier-monitor.mjs b/apps/desktop/scripts/build-hud-modifier-monitor.mjs
index 57242ed2fb4..c4386ff4fbd 100644
--- a/apps/desktop/scripts/build-hud-modifier-monitor.mjs
+++ b/apps/desktop/scripts/build-hud-modifier-monitor.mjs
@@ -1,13 +1,22 @@
#!/usr/bin/env node
-// Optional, host-native helper. No compiler or development headers at runtime.
+// Host-built helper. Windows uses its in-box .NET Framework compiler; no SDK download.
import { execFileSync } from 'node:child_process'
-import { chmodSync, mkdirSync, renameSync, rmSync } from 'node:fs'
+import { chmodSync, existsSync, mkdirSync, renameSync, rmSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const script = fileURLToPath(import.meta.url)
const root = resolve(dirname(script), '..')
+export function resolveWindowsFrameworkCompiler() {
+ const framework = resolve(process.env.SystemRoot || 'C:\\Windows', 'Microsoft.NET')
+ const compiler = ['Framework64', 'Framework']
+ .map(dir => resolve(framework, dir, 'v4.0.30319', 'csc.exe'))
+ .find(existsSync)
+ if (!compiler) throw new Error('The Windows HUD helper needs the .NET Framework included with Windows.')
+ return compiler
+}
+
export function hudModifierBinaryRelativePath(platform = process.platform, arch = process.arch) {
return `native/${platform}-${platform === 'darwin' ? 'universal' : arch}/hud-modifier-monitor${platform === 'win32' ? '.exe' : ''}`
}
@@ -19,7 +28,8 @@ export function buildHudModifierMonitor({
} = {}) {
// Cross-packaging must not ship a host binary under the target's name. The
// capability stays unavailable unless that target was built on its own host.
- if (platform !== process.platform || (platform !== 'darwin' && arch !== process.arch)) {
+ if (platform !== process.platform || (platform === 'linux' && arch !== process.arch)) {
+ if (platform === 'win32') throw new Error('Build Windows packages on Windows so the HUD helper is included.')
console.warn(`[hud-modifier] ${platform}-${arch} needs a native build; modifier tap unavailable for this target`)
return null
}
@@ -56,19 +66,24 @@ export function buildHudModifierMonitor({
],
{ stdio: 'pipe', timeout: 120_000 }
)
+ } else if (platform === 'win32') {
+ execFileSync(resolveWindowsFrameworkCompiler(), [
+ '/nologo', '/target:exe', '/platform:anycpu', '/optimize+', '/warnaserror+',
+ '/reference:System.Windows.Forms.dll', `/out:${staging}`,
+ source('hud-modifier-monitor-win.cs'), source('hud-modifier-gesture.cs')
+ ], { stdio: 'pipe', timeout: 120_000 })
} else {
- const windows = platform === 'win32'
execFileSync(
- process.env.CC || (windows ? 'clang' : 'cc'),
+ process.env.CC || 'cc',
[
'-std=gnu11',
'-O2',
'-Wall',
'-Wextra',
- source(windows ? 'hud-modifier-monitor-win.c' : 'hud-modifier-monitor-x11.c'),
+ source('hud-modifier-monitor-x11.c'),
'-o',
staging,
- ...(windows ? ['-luser32'] : ['-lX11', '-lXi'])
+ '-lX11', '-lXi'
],
{ stdio: 'pipe', timeout: 120_000 }
)
@@ -79,9 +94,8 @@ export function buildHudModifierMonitor({
return output
} catch (error) {
rmSync(output, { force: true }) // Never keep a stale helper after a failed rebuild.
- if (platform === 'darwin') throw error // The existing macOS build already requires Xcode.
- const prerequisite = platform === 'linux' ? 'a C compiler, libx11-dev and libxi-dev' : 'Clang and the Windows SDK'
- console.warn(`[hud-modifier] unavailable: native build needs ${prerequisite}; desktop packaging continues`)
+ if (platform !== 'linux') throw error
+ console.warn('[hud-modifier] unavailable: native build needs a C compiler, libx11-dev and libxi-dev; desktop packaging continues')
console.warn(String(error.stderr || error.message))
return null
} finally {