MagicWindows
Open Source · v0.4.0Dual distribution channel — native Tauri/Rust desktop app (NSIS/MSI x64) AND public Svelte 5 web SPA on Cloudflare Workers with 12 downloadable ZIPs (6 layouts × 2 archs). Cross-compile x64 + ARM64, EN/FR i18n, monorepo workspaces, 78 tests, 0 TS errors, 0 clippy warnings. 140 commits.
Why I built it
The low-profile MacBook keyboard — I've never recaptured that typing feel on a stock Windows setup. The obvious fix: buy an Apple Magic Keyboard and plug it in over USB. Except the layout doesn't match, the modifiers are reversed, and off-the-shelf solutions (Magic Utilities & co) run at €20–30 per year on subscription for a problem solved with a few Windows Registry writes. So I built it — native Tauri/Rust, open source, one-click install, free. V4 opened a second channel: a public web site (Cloudflare Workers) that serves an interactive preview and hosts 12 downloadable ZIPs on R2 — for users who just want a DLL without installing the desktop wrapper.
Structural technical decisions
Native Windows binary able to touch Win32 / registry / elevation cleanly — impossible with Electron without shipping Node and Chromium in the bundle.
Windows refuses a purely logical layout — it wants a DLL in System32. `klc-codegen` (968 Rust LOC) generates the C source, `build.rs` (438 LOC) detects both MSVC Hostx64/{x64,arm64} toolchains and produces 12 DLLs (6 layouts × 2 archs). ARM64 is optional — a warning if the toolchain is missing, x64 build continues.
Modifier toggles + F12 remap + future remaps coexist in a single Scancode Map without clobber. Byte-by-byte identity tests on the composition. Allows adding new remaps without breaking previous ones.
The `KeyboardVisual` component (920 LOC) extracted to `@magicwindows/keyboard-visual` is consumed by 4 desktop pages + 1 web page — single source of truth. Web SPA Svelte 5 served by Cloudflare Workers static-assets, 12 ZIPs hosted on R2 behind `dl.mindvisionstudio.com` with custom domain. Deterministic release pipeline (EPOCH mtimes + `statConcurrency:1`) → byte-identical ZIPs between runs if sources didn't change.
The non-trivial challenge
Installing a Windows keyboard layout means: a DLL in C:\Windows\System32 + an HKLM\...\Keyboard Layouts\<id> key (admin) + an HKCU activation per user (non-admin). An elevated PowerShell can't reliably write into the original user's LOCALAPPDATA, and the non-elevated parent doesn't see the admin script's result. Solution in install.rs: the elevated PS script writes markers into HKLM (the only reliable shared channel), the non-elevated parent reads them back and performs the HKCU activation.
Lesson learned
On Windows, the real complexity is not "writing a keyboard file" — it is respecting the elevation / non-elevation boundary. Any flow that touches System32 + HKLM + HKCU needs a communication channel between the two worlds (HKLM here, used as a mailbox). And once the desktop is solid, opening a parallel web channel (R2 downloads + interactive preview) costs little but doubles the product's surface for discovery.
Features
Apple keyboard identification via scancode stream — 3 to 5 keystrokes are enough
`@magicwindows/keyboard-visual` component (920 LOC) consumed by 4 desktop pages + 1 web page — single source of truth
KLC → compiled DLL, copy to System32, HKLM registry, force-activate with no reboot
Cmd↔Ctrl, Opt↔Cmd, F12 → Calc/Search/Mail via Scancode Map composition — toggles + remaps coexist (V0.3)
`ToUnicodeEx` probe via PowerShell + live keyboard modal — verifies the layout is actually active (V0.3)
Auto-detects Apple HID (VID 0x05AC) + 2s/5min polling, redirects to Detect on pairing (V0.3)
magicwindows.mindvisionstudio.com (Cloudflare Workers) with interactive preview + 12 versioned ZIPs on dl.mindvisionstudio.com (R2 public)
`build.rs` drives MSVC Hostx64/{x64,arm64} and produces 12 deterministic DLLs — release reproducible byte-identical between runs