A truly modular keyboard
C
app: Keyword Monitor desktop app
Nathandced24e9a6e3
diff --git a/app/.gitignore b/app/.gitignorenew file mode 100644index 0000000..3191ead--- /dev/null+++ b/app/.gitignore@@ -0,0 +1,3 @@+node_modules/+out/+dist/diff --git a/app/PROTOCOL.md b/app/PROTOCOL.mdnew file mode 100644index 0000000..882dea4--- /dev/null+++ b/app/PROTOCOL.md@@ -0,0 +1,74 @@+# Keyword host protocol (v1)++How the desktop app talks to the Keyword. The same protocol runs over USB and Bluetooth.++## Transport++- **USB:** CDC ACM (virtual serial port). The baud rate is ignored.+- **Bluetooth LE:** Nordic UART Service, with the advertised name starting with `Keyword`.+ - Service `6e400001-b5a3-f393-e0a9-e50e24dcca9e`+ - RX `6e400002-…` (the host writes here, in chunks of 20 bytes or less)+ - TX `6e400003-…` (the Keyword notifies here)+- **Framing:** ASCII lines ending in `\n`, with `\r\n` also accepted. Over BLE a line can be split across several notifications, so the host buffers until it sees `\n`.+- **Fields** are `name=value` pairs separated by spaces. Hex values are uppercase, and either case is accepted.++## Keys++Each Keybit is identified by its full 96-bit CH32V003 UID. The Keybit holds it at registers 0x10..0x1B, little-endian, and the protocol prints it as 24 uppercase hex digits, MSB first (for example `3B0A4F1C88D2E61F5F1821C1`). The app also accepts an 8-digit UID.++Profiles are keyed by UID and never by I2C address, because the Keyword can reassign an address.++Only Keybits that touch the Keyword directly are visible. `at` is the Keyword side the Keybit is on: `L` (left), `R` (right) or `T` (top edge).++## Host → Keyword++| Command | Reply |+|---|---|+| `HELLO` | `KEYWORD v=<fw> proto=1` |+| `SIDES?` | `SIDES L=<0\|1> R=<0\|1> T=<0\|1>` |+| `KEYS?` | one `KEY+ uid=<uid> at=<L\|R\|T>` per present Keybit, then `KEYS END` |+| `MAP uid=<uid> mods=<2hex> key=<2hex>` | `OK MAP uid=<uid>` |+| `MAP? uid=<uid>` | `MAP uid=<uid> mods=<2hex> key=<2hex>` (`00`/`00` if unmapped) |+| `UNMAP uid=<uid>` | `OK UNMAP uid=<uid>` |+| `CLEAR` | `OK CLEAR` (drop every mapping) |+| `SAVE` | `OK SAVE` (write the table to flash) |+| anything invalid | `ERR <text>` |++- `mods` is the HID boot keyboard modifier byte:+ - bit 0 = LCtrl, 1 = LShift, 2 = LAlt, 3 = LGUI (Cmd/Win)+ - bits 4 to 7 are the right-hand versions of the same keys+- `key` is a HID keyboard usage ID (page 0x07): `04` = A, `3A` = F1, `68` = F13.+- `key=00` with only `mods` set is a valid mapping.+- When a mapped Keybit is pressed, the Keyword sends a HID report containing `mods` and `key`.++## Keyword → host (unsolicited)++| Line | When |+|---|---|+| `SIDES L=.. R=.. T=..` | any side changes (after debounce) |+| `KEY+ uid=<uid> at=<L\|R\|T>` | a Keybit is attached |+| `KEY- uid=<uid>` | a Keybit is removed |+| `PRESS uid=<uid> down=<0\|1>` | a Keybit is pressed or released |++## How the app uses it++- **On connect,** the app sends `HELLO`, `SIDES?` and `KEYS?`, then pushes the active profile: `CLEAR`, one `MAP` per key, then `SAVE`. Firmware can skip the flash write when the table is unchanged.+- **While connected,** it polls `SIDES?` every 2 s and `KEYS?` every 10 s, in case an unsolicited line was missed.+- **Profiles** live only in the app. The Keyword holds just the current table.++## Side detection (Keyword ↔ Keybit, I2C)++The full Keybit side is in `firmware/keybit/README.md`. In short:++- **One shared bus on the Keyword.** All three Keyword side joints sit on the same I2C bus (I2C3: left U5/U6, right U4/U7, top edge U13/U15).+- **Four separate buses on the Keybit.** Each Keybit has its own bit-banged bus per side.+- **Addressing.** A new Keybit answers on 0x30. The Keyword reads its UID, then assigns it an address from 0x08..0x77, which the Keybit keeps in flash. If several new Keybits answer at once, they arbitrate by UID.+- **Which side.** Register 0x07 returns the Keybit side the request arrived on, as `N`, `E`, `S` or `W`. The Keyword maps that to its own side:++| Keybit side (reg 0x07) | Keyword side |+|---|---|+| `E` | `L`: the Keybit is on the Keyword's left |+| `W` | `R`: right |+| `S` | `T`: top edge |++A Keybit can only mate upright, since rotating it would land its SDA on the Keyword's SCL. So the side it reports always maps to exactly one Keyword side.diff --git a/app/README.md b/app/README.mdnew file mode 100644index 0000000..19ab581--- /dev/null+++ b/app/README.md@@ -0,0 +1,67 @@+# Keyword Monitor++A desktop app for the Keyword. It connects over USB serial or Bluetooth and lets you:++- see which sides of the Keyword have a Keybit, live+- assign any key or shortcut to each Keybit+- keep keymap profiles, and switch between, import and export them++It's built with Electron, so it runs on macOS, Windows and Linux. It uses Chromium's Web Serial and Web Bluetooth, so there are no native modules to compile.++## Run++```sh+cd app+npm install+npm start+```++**Demo** works without hardware. Click a side of the Keyword to attach or remove a Keybit, and click **Tap** to simulate a key press.++To run the tests:++```sh+npm test+```++They cover the protocol parser, the HID key table and profile import/export.++## Using it++- **USB serial / Bluetooth:** pick the Keyword from the list. ST devices (USB VID 0483) and BLE names starting with `Keyword` are highlighted.+- **Keys:** every Keybit the Keyword reports, with its side, its UID and what it's assigned to.+ - A key lights up while it's held.+ - Keys from the profile that aren't attached right now show greyed out.+- **Assign…:** press the key or shortcut you want, for example `Ctrl+Shift+K`, `Cmd+Space` or `F13`. Modifiers on their own work too.+ - For combos the OS grabs first, like Cmd+Tab, tick the modifiers and pick the key from the list instead.+ - You can also give the key a name.+- **Profiles:** edits save automatically to `profiles.json` in the app's user-data folder. Switching profiles sends the new keymap to the Keyword.+ - **Export…** writes a `.keyword.json` file and **Import…** reads one back.+- **Activity:** shows connects, disconnects and assignments as they happen. The raw protocol log is at the bottom.++## Protocol++[PROTOCOL.md](PROTOCOL.md) has the line protocol the Keyword firmware needs to speak, and the I2C address scheme used for left/right detection.++## Firmware status++The app is ready, but the Keyword firmware doesn't speak this protocol yet:++- USB CDC, the BLE Nordic UART Service, the I2C3 side scan and the keymap table still need adding on the Keyword.+- The Keybit side (assigned addresses, and the side register 0x07) lives in `firmware/keybit/`.++Until then, use **Demo**.++## Ways to detect a Keybit's side++The Keyword's three side joints share one I2C bus, so an ACK on its own can't tell you the side. These are the options:++1. **The Keybit reports which of its sides was addressed (used).** Each Keybit side has its own bus, so the Keybit knows which one a request came in on, and returns it in register 0x07.+ - A Keybit on the Keyword's left touches with its east side, so `E` means left, `W` means right and `S` means the top edge.+ - Two Keybits on the shared bus are kept apart by Keyword-assigned addresses, with UID arbitration for new ones.+ - It relies on Keybits being upright. The pogo layout forces that anyway, since a rotated Keybit swaps SDA and SCL.+2. **Side-encoded addresses.** The Keybit answers on a different address per side (for example E=0x32, W=0x34). This is simpler, but it leaves no room for addressing several Keybits individually.+3. **SWIO presence on PB5.** This tells you a Keybit is on the stud contacts, and it's needed for flashing. It can't say which side.+4. **A sense pin per side.** Use a pull-up on the Keyword and pull it to GND on the Keybit, or give each side its own I2C bus.+ - This is the most robust option and works for any rotation.+ - It needs a board revision.diff --git a/app/main.js b/app/main.jsnew file mode 100644index 0000000..c096c3f--- /dev/null+++ b/app/main.js@@ -0,0 +1,139 @@+// Electron main process. The renderer talks to the Keyword with Web Serial and+// Web Bluetooth; Electron has no built-in device picker for either, so we forward+// the device lists to the renderer and hand back whatever the user picks.+const { app, BrowserWindow, ipcMain, dialog } = require('electron');+const fs = require('fs');+const path = require('path');++const storePath = () => path.join(app.getPath('userData'), 'profiles.json');++// Chromium gates Web Bluetooth behind this flag on some platforms.+app.commandLine.appendSwitch('enable-experimental-web-platform-features');++let win;+let pendingPick = null; // { kind, callback }+let capturing = false;++function finishPick(id) {+ if (!pendingPick) return;+ const { callback } = pendingPick;+ pendingPick = null;+ callback(id || '');+}++function createWindow() {+ win = new BrowserWindow({+ width: 900,+ height: 640,+ minWidth: 520,+ minHeight: 480,+ title: 'Keyword Monitor',+ backgroundColor: '#14161a',+ webPreferences: {+ preload: path.join(__dirname, 'preload.js'),+ contextIsolation: true,+ nodeIntegration: false,+ },+ });++ const ses = win.webContents.session;++ ses.setPermissionCheckHandler((_wc, permission) =>+ ['serial', 'bluetooth'].includes(permission));+ ses.setDevicePermissionHandler((details) =>+ ['serial', 'bluetooth'].includes(details.deviceType));++ ses.on('select-serial-port', (event, portList, _wc, callback) => {+ event.preventDefault();+ finishPick(''); // cancel any older picker+ pendingPick = { kind: 'serial', callback };+ win.webContents.send('chooser:list', {+ kind: 'serial',+ devices: portList.map((p) => ({+ id: p.portId,+ name: p.displayName || p.portName,+ detail: [p.portName, p.vendorId && `VID ${p.vendorId}`, p.productId && `PID ${p.productId}`]+ .filter(Boolean).join(' · '),+ // 0x0483 is ST's USB vendor id, so it's most likely the Keyword.+ likely: String(p.vendorId).toLowerCase() === '0483' || p.vendorId === '1155',+ })),+ });+ });+ ses.on('serial-port-added', () => {});+ ses.on('serial-port-removed', () => {});++ // Fires again every time a new device is found while the scan runs.+ win.webContents.on('select-bluetooth-device', (event, devices, callback) => {+ event.preventDefault();+ if (!pendingPick || pendingPick.kind !== 'bluetooth') {+ finishPick('');+ pendingPick = { kind: 'bluetooth', callback };+ } else {+ pendingPick.callback = callback;+ }+ win.webContents.send('chooser:list', {+ kind: 'bluetooth',+ devices: devices.map((d) => ({+ id: d.deviceId,+ name: d.deviceName || 'Unnamed device',+ detail: d.deviceId,+ likely: /^keyword/i.test(d.deviceName || ''),+ })),+ });+ });++ // While the shortcut recorder is open, swallow keys before menus and the OS-level+ // accelerators (Cmd+W, Cmd+Q, Alt+F4...) see them and pass them to the page.+ win.webContents.on('before-input-event', (event, input) => {+ if (!capturing) return;+ event.preventDefault();+ win.webContents.send('capture:key', {+ type: input.type, code: input.code,+ ctrlKey: input.control, shiftKey: input.shift, altKey: input.alt, metaKey: input.meta,+ });+ });++ win.loadFile(path.join(__dirname, 'renderer', 'index.html'));+}++ipcMain.on('chooser:pick', (_e, id) => finishPick(id));+ipcMain.on('capture:set', (_e, on) => { capturing = !!on; });++ipcMain.handle('store:load', () => {+ try { return JSON.parse(fs.readFileSync(storePath(), 'utf8')); } catch { return null; }+});+ipcMain.handle('store:save', (_e, store) => {+ const tmp = storePath() + '.tmp';+ fs.writeFileSync(tmp, JSON.stringify(store, null, 2));+ fs.renameSync(tmp, storePath());+});+ipcMain.handle('profile:export', async (_e, name, text) => {+ const { canceled, filePath } = await dialog.showSaveDialog(win, {+ title: 'Export profile',+ defaultPath: `${name.replace(/[^\w -]+/g, '_') || 'profile'}.keyword.json`,+ filters: [{ name: 'Keyword profile', extensions: ['json'] }],+ });+ if (canceled || !filePath) return false;+ fs.writeFileSync(filePath, text);+ return true;+});+ipcMain.handle('profile:import', async () => {+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {+ title: 'Import profile',+ filters: [{ name: 'Keyword profile', extensions: ['json'] }],+ properties: ['openFile'],+ });+ if (canceled || !filePaths.length) return null;+ return fs.readFileSync(filePaths[0], 'utf8');+});++app.whenReady().then(() => {+ createWindow();+ app.on('activate', () => {+ if (BrowserWindow.getAllWindows().length === 0) createWindow();+ });+});++app.on('window-all-closed', () => {+ if (process.platform !== 'darwin') app.quit();+});diff --git a/app/package-lock.json b/app/package-lock.jsonnew file mode 100644index 0000000..ec8b467--- /dev/null+++ b/app/package-lock.json@@ -0,0 +1,871 @@+{+ "name": "keyword-monitor",+ "version": "0.1.0",+ "lockfileVersion": 3,+ "requires": true,+ "packages": {+ "": {+ "name": "keyword-monitor",+ "version": "0.1.0",+ "devDependencies": {+ "electron": "33.2.1"+ }+ },+ "node_modules/@electron/get": {+ "version": "2.0.3",+ "resolved": "https://registry.npmjs.org/@electron/get/-/get-2.0.3.tgz",+ "integrity": "sha512-Qkzpg2s9GnVV2I2BjRksUi43U5e6+zaQMcjoJy0C+C5oxaKl+fmckGDQFtRpZpZV0NQekuZZ+tGz7EA9TVnQtQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "debug": "^4.1.1",+ "env-paths": "^2.2.0",+ "fs-extra": "^8.1.0",+ "got": "^11.8.5",+ "progress": "^2.0.3",+ "semver": "^6.2.0",+ "sumchecker": "^3.0.1"+ },+ "engines": {+ "node": ">=12"+ },+ "optionalDependencies": {+ "global-agent": "^3.0.0"+ }+ },+ "node_modules/@sindresorhus/is": {+ "version": "4.6.0",+ "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",+ "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sindresorhus/is?sponsor=1"+ }+ },+ "node_modules/@szmarczak/http-timer": {+ "version": "4.0.6",+ "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",+ "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "defer-to-connect": "^2.0.0"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/@types/cacheable-request": {+ "version": "6.0.3",+ "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz",+ "integrity": "sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/http-cache-semantics": "*",+ "@types/keyv": "^3.1.4",+ "@types/node": "*",+ "@types/responselike": "^1.0.0"+ }+ },+ "node_modules/@types/http-cache-semantics": {+ "version": "4.2.0",+ "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.2.0.tgz",+ "integrity": "sha512-L3LgimLHXtGkWikKnsPg0/VFx9OGZaC+eN1u4r+OB1XRqH3meBIAVC2zr1WdMH+RHmnRkqliQAOHNJ/E0j/e0Q==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/@types/keyv": {+ "version": "3.1.4",+ "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz",+ "integrity": "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/node": "*"+ }+ },+ "node_modules/@types/node": {+ "version": "20.19.43",+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.43.tgz",+ "integrity": "sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "undici-types": "~6.21.0"+ }+ },+ "node_modules/@types/responselike": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.3.tgz",+ "integrity": "sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/node": "*"+ }+ },+ "node_modules/@types/yauzl": {+ "version": "2.10.3",+ "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz",+ "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "@types/node": "*"+ }+ },+ "node_modules/boolean": {+ "version": "3.2.0",+ "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.2.0.tgz",+ "integrity": "sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==",+ "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",+ "dev": true,+ "license": "MIT",+ "optional": true+ },+ "node_modules/buffer-crc32": {+ "version": "0.2.13",+ "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",+ "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": "*"+ }+ },+ "node_modules/cacheable-lookup": {+ "version": "5.0.4",+ "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",+ "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10.6.0"+ }+ },+ "node_modules/cacheable-request": {+ "version": "7.0.4",+ "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.4.tgz",+ "integrity": "sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "clone-response": "^1.0.2",+ "get-stream": "^5.1.0",+ "http-cache-semantics": "^4.0.0",+ "keyv": "^4.0.0",+ "lowercase-keys": "^2.0.0",+ "normalize-url": "^6.0.1",+ "responselike": "^2.0.0"+ },+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/clone-response": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz",+ "integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "mimic-response": "^1.0.0"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/debug": {+ "version": "4.4.3",+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",+ "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "ms": "^2.1.3"+ },+ "engines": {+ "node": ">=6.0"+ },+ "peerDependenciesMeta": {+ "supports-color": {+ "optional": true+ }+ }+ },+ "node_modules/decompress-response": {+ "version": "6.0.0",+ "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",+ "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "mimic-response": "^3.1.0"+ },+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/decompress-response/node_modules/mimic-response": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",+ "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/defer-to-connect": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz",+ "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/define-data-property": {+ "version": "1.1.4",+ "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz",+ "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "es-define-property": "^1.0.0",+ "es-errors": "^1.3.0",+ "gopd": "^1.0.1"+ },+ "engines": {+ "node": ">= 0.4"+ },+ "funding": {+ "url": "https://github.com/sponsors/ljharb"+ }+ },+ "node_modules/define-properties": {+ "version": "1.2.1",+ "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz",+ "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "define-data-property": "^1.0.1",+ "has-property-descriptors": "^1.0.0",+ "object-keys": "^1.1.1"+ },+ "engines": {+ "node": ">= 0.4"+ },+ "funding": {+ "url": "https://github.com/sponsors/ljharb"+ }+ },+ "node_modules/detect-node": {+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz",+ "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==",+ "dev": true,+ "license": "MIT",+ "optional": true+ },+ "node_modules/electron": {+ "version": "33.2.1",+ "resolved": "https://registry.npmjs.org/electron/-/electron-33.2.1.tgz",+ "integrity": "sha512-SG/nmSsK9Qg1p6wAW+ZfqU+AV8cmXMTIklUL18NnOKfZLlum4ZsDoVdmmmlL39ZmeCaq27dr7CgslRPahfoVJg==",+ "dev": true,+ "hasInstallScript": true,+ "license": "MIT",+ "dependencies": {+ "@electron/get": "^2.0.0",+ "@types/node": "^20.9.0",+ "extract-zip": "^2.0.1"+ },+ "bin": {+ "electron": "cli.js"+ },+ "engines": {+ "node": ">= 12.20.55"+ }+ },+ "node_modules/end-of-stream": {+ "version": "1.4.5",+ "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",+ "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "once": "^1.4.0"+ }+ },+ "node_modules/env-paths": {+ "version": "2.2.1",+ "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",+ "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=6"+ }+ },+ "node_modules/es-define-property": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 0.4"+ }+ },+ "node_modules/es-errors": {+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 0.4"+ }+ },+ "node_modules/es6-error": {+ "version": "4.1.1",+ "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz",+ "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",+ "dev": true,+ "license": "MIT",+ "optional": true+ },+ "node_modules/escape-string-regexp": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",+ "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/extract-zip": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz",+ "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==",+ "dev": true,+ "license": "BSD-2-Clause",+ "dependencies": {+ "debug": "^4.1.1",+ "get-stream": "^5.1.0",+ "yauzl": "^2.10.0"+ },+ "bin": {+ "extract-zip": "cli.js"+ },+ "engines": {+ "node": ">= 10.17.0"+ },+ "optionalDependencies": {+ "@types/yauzl": "^2.9.1"+ }+ },+ "node_modules/fd-slicer": {+ "version": "1.1.0",+ "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",+ "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "pend": "~1.2.0"+ }+ },+ "node_modules/fs-extra": {+ "version": "8.1.0",+ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",+ "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "graceful-fs": "^4.2.0",+ "jsonfile": "^4.0.0",+ "universalify": "^0.1.0"+ },+ "engines": {+ "node": ">=6 <7 || >=8"+ }+ },+ "node_modules/get-stream": {+ "version": "5.2.0",+ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",+ "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "pump": "^3.0.0"+ },+ "engines": {+ "node": ">=8"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/global-agent": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-3.0.0.tgz",+ "integrity": "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==",+ "dev": true,+ "license": "BSD-3-Clause",+ "optional": true,+ "dependencies": {+ "boolean": "^3.0.1",+ "es6-error": "^4.1.1",+ "matcher": "^3.0.0",+ "roarr": "^2.15.3",+ "semver": "^7.3.2",+ "serialize-error": "^7.0.1"+ },+ "engines": {+ "node": ">=10.0"+ }+ },+ "node_modules/global-agent/node_modules/semver": {+ "version": "7.8.5",+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",+ "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",+ "dev": true,+ "license": "ISC",+ "optional": true,+ "bin": {+ "semver": "bin/semver.js"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/globalthis": {+ "version": "1.0.4",+ "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz",+ "integrity": "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "define-properties": "^1.2.1",+ "gopd": "^1.0.1"+ },+ "engines": {+ "node": ">= 0.4"+ },+ "funding": {+ "url": "https://github.com/sponsors/ljharb"+ }+ },+ "node_modules/gopd": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 0.4"+ },+ "funding": {+ "url": "https://github.com/sponsors/ljharb"+ }+ },+ "node_modules/got": {+ "version": "11.8.6",+ "resolved": "https://registry.npmjs.org/got/-/got-11.8.6.tgz",+ "integrity": "sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@sindresorhus/is": "^4.0.0",+ "@szmarczak/http-timer": "^4.0.5",+ "@types/cacheable-request": "^6.0.1",+ "@types/responselike": "^1.0.0",+ "cacheable-lookup": "^5.0.3",+ "cacheable-request": "^7.0.2",+ "decompress-response": "^6.0.0",+ "http2-wrapper": "^1.0.0-beta.5.2",+ "lowercase-keys": "^2.0.0",+ "p-cancelable": "^2.0.0",+ "responselike": "^2.0.0"+ },+ "engines": {+ "node": ">=10.19.0"+ },+ "funding": {+ "url": "https://github.com/sindresorhus/got?sponsor=1"+ }+ },+ "node_modules/graceful-fs": {+ "version": "4.2.11",+ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",+ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",+ "dev": true,+ "license": "ISC"+ },+ "node_modules/has-property-descriptors": {+ "version": "1.0.2",+ "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",+ "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "es-define-property": "^1.0.0"+ },+ "funding": {+ "url": "https://github.com/sponsors/ljharb"+ }+ },+ "node_modules/http-cache-semantics": {+ "version": "4.3.0",+ "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.3.0.tgz",+ "integrity": "sha512-M5t5LlJpS1UHMjvwRQVdFHvPISGeLAxNcrWuJkeGh0KxsqCHZ1O3NXZU/8x7cD0BDcGW8kapxMKTvwlqrNkHkA==",+ "dev": true,+ "license": "BSD-2-Clause"+ },+ "node_modules/http2-wrapper": {+ "version": "1.0.3",+ "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz",+ "integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "quick-lru": "^5.1.1",+ "resolve-alpn": "^1.0.0"+ },+ "engines": {+ "node": ">=10.19.0"+ }+ },+ "node_modules/json-buffer": {+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",+ "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/json-stringify-safe": {+ "version": "5.0.1",+ "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",+ "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==",+ "dev": true,+ "license": "ISC",+ "optional": true+ },+ "node_modules/jsonfile": {+ "version": "4.0.0",+ "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",+ "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==",+ "dev": true,+ "license": "MIT",+ "optionalDependencies": {+ "graceful-fs": "^4.1.6"+ }+ },+ "node_modules/keyv": {+ "version": "4.5.4",+ "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",+ "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "json-buffer": "3.0.1"+ }+ },+ "node_modules/lowercase-keys": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",+ "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/matcher": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz",+ "integrity": "sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "escape-string-regexp": "^4.0.0"+ },+ "engines": {+ "node": ">=10"+ }+ },+ "node_modules/mimic-response": {+ "version": "1.0.1",+ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",+ "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=4"+ }+ },+ "node_modules/ms": {+ "version": "2.1.3",+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/normalize-url": {+ "version": "6.1.0",+ "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",+ "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/object-keys": {+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",+ "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "engines": {+ "node": ">= 0.4"+ }+ },+ "node_modules/once": {+ "version": "1.4.0",+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",+ "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",+ "dev": true,+ "license": "ISC",+ "dependencies": {+ "wrappy": "1"+ }+ },+ "node_modules/p-cancelable": {+ "version": "2.1.1",+ "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",+ "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=8"+ }+ },+ "node_modules/pend": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",+ "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/progress": {+ "version": "2.0.3",+ "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",+ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=0.4.0"+ }+ },+ "node_modules/pump": {+ "version": "3.0.4",+ "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",+ "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "end-of-stream": "^1.1.0",+ "once": "^1.3.1"+ }+ },+ "node_modules/quick-lru": {+ "version": "5.1.1",+ "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz",+ "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/resolve-alpn": {+ "version": "1.2.1",+ "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz",+ "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/responselike": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz",+ "integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "lowercase-keys": "^2.0.0"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/roarr": {+ "version": "2.15.4",+ "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",+ "integrity": "sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==",+ "dev": true,+ "license": "BSD-3-Clause",+ "optional": true,+ "dependencies": {+ "boolean": "^3.0.1",+ "detect-node": "^2.0.4",+ "globalthis": "^1.0.1",+ "json-stringify-safe": "^5.0.1",+ "semver-compare": "^1.0.0",+ "sprintf-js": "^1.1.2"+ },+ "engines": {+ "node": ">=8.0"+ }+ },+ "node_modules/semver": {+ "version": "6.3.1",+ "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",+ "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",+ "dev": true,+ "license": "ISC",+ "bin": {+ "semver": "bin/semver.js"+ }+ },+ "node_modules/semver-compare": {+ "version": "1.0.0",+ "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz",+ "integrity": "sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==",+ "dev": true,+ "license": "MIT",+ "optional": true+ },+ "node_modules/serialize-error": {+ "version": "7.0.1",+ "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz",+ "integrity": "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==",+ "dev": true,+ "license": "MIT",+ "optional": true,+ "dependencies": {+ "type-fest": "^0.13.1"+ },+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/sprintf-js": {+ "version": "1.1.3",+ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",+ "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==",+ "dev": true,+ "license": "BSD-3-Clause",+ "optional": true+ },+ "node_modules/sumchecker": {+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz",+ "integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "debug": "^4.1.0"+ },+ "engines": {+ "node": ">= 8.0"+ }+ },+ "node_modules/type-fest": {+ "version": "0.13.1",+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz",+ "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==",+ "dev": true,+ "license": "(MIT OR CC0-1.0)",+ "optional": true,+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/sponsors/sindresorhus"+ }+ },+ "node_modules/undici-types": {+ "version": "6.21.0",+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/universalify": {+ "version": "0.1.2",+ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",+ "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">= 4.0.0"+ }+ },+ "node_modules/wrappy": {+ "version": "1.0.2",+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",+ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",+ "dev": true,+ "license": "ISC"+ },+ "node_modules/yauzl": {+ "version": "2.10.0",+ "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",+ "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "buffer-crc32": "~0.2.3",+ "fd-slicer": "~1.1.0"+ }+ }+ }+}diff --git a/app/package.json b/app/package.jsonnew file mode 100644index 0000000..b1f16f6--- /dev/null+++ b/app/package.json@@ -0,0 +1,14 @@+{+ "name": "keyword-monitor",+ "version": "0.1.0",+ "description": "Shows which sides of the Keyword have a Keybit attached, over USB serial or Bluetooth",+ "main": "main.js",+ "private": true,+ "scripts": {+ "start": "electron .",+ "test": "node --test test/protocol.test.js"+ },+ "devDependencies": {+ "electron": "33.2.1"+ }+}diff --git a/app/preload.js b/app/preload.jsnew file mode 100644index 0000000..a73bda1--- /dev/null+++ b/app/preload.js@@ -0,0 +1,15 @@+const { contextBridge, ipcRenderer } = require('electron');++contextBridge.exposeInMainWorld('devicePicker', {+ onList: (fn) => ipcRenderer.on('chooser:list', (_e, data) => fn(data)),+ pick: (id) => ipcRenderer.send('chooser:pick', id || ''),+});++contextBridge.exposeInMainWorld('desktop', {+ loadStore: () => ipcRenderer.invoke('store:load'),+ saveStore: (store) => ipcRenderer.invoke('store:save', store),+ exportProfile: (name, text) => ipcRenderer.invoke('profile:export', name, text),+ importProfile: () => ipcRenderer.invoke('profile:import'),+ setCapture: (on) => ipcRenderer.send('capture:set', on),+ onCaptureKey: (fn) => ipcRenderer.on('capture:key', (_e, k) => fn(k)),+});diff --git a/app/renderer/app.js b/app/renderer/app.jsnew file mode 100644index 0000000..466f854--- /dev/null+++ b/app/renderer/app.js@@ -0,0 +1,566 @@+/* global KeywordProtocol, Hid, Profiles */+const { SIDES, NUS, LineBuffer, parseLine, cmd, profileCommands } = KeywordProtocol;++const POLL_MS = 2000; // ask for SIDES? this often in case a push was missed+const KEYS_POLL_MS = 10000; // full KEYS? resync+const STALE_MS = 5000; // no line from the Keyword for this long means stale+const SIDE_NAMES = { L: 'left', R: 'right', T: 'top edge' };+const MAC = /Mac/i.test(navigator.platform);++const $ = (sel) => document.querySelector(sel);+const el = (tag, props = {}, ...children) => {+ const e = Object.assign(document.createElement(tag), props);+ e.append(...children.filter((c) => c != null));+ return e;+};+const logEl = $('#log');++function log(dir, text) {+ const t = new Date().toLocaleTimeString();+ logEl.textContent += `${t} ${dir} ${text}\n`;+ if (logEl.textContent.length > 20000) logEl.textContent = logEl.textContent.slice(-15000);+ logEl.scrollTop = logEl.scrollHeight;+}++// ---- Transports: each has open(onText, onClose), write(text), close() ----++class SerialTransport {+ label = 'USB serial';+ async open(onText, onClose) {+ this.port = await navigator.serial.requestPort();+ await this.port.open({ baudRate: 115200 }); // CDC ignores the baud rate+ this.writer = this.port.writable.getWriter();+ this.closed = false;+ (async () => {+ const decoder = new TextDecoder();+ try {+ while (!this.closed && this.port.readable) {+ this.reader = this.port.readable.getReader();+ try {+ for (;;) {+ const { value, done } = await this.reader.read();+ if (done) break;+ onText(decoder.decode(value, { stream: true }));+ }+ } finally {+ this.reader.releaseLock();+ }+ }+ } catch (e) {+ log('!!', `serial: ${e.message}`);+ }+ if (!this.closed) onClose();+ })();+ }+ async write(text) {+ await this.writer.write(new TextEncoder().encode(text));+ }+ async close() {+ this.closed = true;+ try { await this.reader?.cancel(); } catch {}+ try { this.writer?.releaseLock(); } catch {}+ try { await this.port?.close(); } catch {}+ }+}++class BleTransport {+ label = 'Bluetooth';+ async open(onText, onClose) {+ this.device = await navigator.bluetooth.requestDevice({+ filters: [{ namePrefix: 'Keyword' }, { services: [NUS.service] }],+ optionalServices: [NUS.service],+ });+ this.device.addEventListener('gattserverdisconnected', () => { if (!this.closed) onClose(); });+ const server = await this.device.gatt.connect();+ const svc = await server.getPrimaryService(NUS.service);+ this.rx = await svc.getCharacteristic(NUS.rx);+ const tx = await svc.getCharacteristic(NUS.tx);+ const decoder = new TextDecoder();+ tx.addEventListener('characteristicvaluechanged', (e) =>+ onText(decoder.decode(e.target.value, { stream: true })));+ await tx.startNotifications();+ this.closed = false;+ }+ async write(text) {+ const bytes = new TextEncoder().encode(text);+ for (let i = 0; i < bytes.length; i += 20) { // fits the default 23-byte ATT MTU+ const chunk = bytes.slice(i, i + 20);+ if (this.rx.writeValueWithoutResponse) await this.rx.writeValueWithoutResponse(chunk);+ else await this.rx.writeValue(chunk);+ }+ }+ async close() {+ this.closed = true;+ if (this.device?.gatt.connected) this.device.gatt.disconnect();+ }+}++// Pretends to be a Keyword so the app can be tried without hardware.+class DemoTransport {+ label = 'Demo';+ uids = { L: '3B0A4F1C88D2E61F5F1821C1', R: '91C7002DE4B3A75C0A33B7E2', T: '0F5E19A2C6B84D37C4D90015' };+ present = { L: true, R: false, T: false };+ maps = {};+ async open(onText) { this.onText = onText; }+ emit(line) { setTimeout(() => this.onText(line + '\n'), 20); }+ sidesLine() { return 'SIDES ' + SIDES.map((s) => `${s}=${this.present[s] ? 1 : 0}`).join(' '); }+ toggle(side) {+ this.present[side] = !this.present[side];+ this.emit(this.present[side] ? `KEY+ uid=${this.uids[side]} at=${side}` : `KEY- uid=${this.uids[side]}`);+ this.emit(this.sidesLine());+ }+ tap(uid) {+ if (!Object.entries(this.uids).some(([s, u]) => u === uid && this.present[s])) return;+ this.emit(`PRESS uid=${uid} down=1`);+ setTimeout(() => this.emit(`PRESS uid=${uid} down=0`), 180);+ }+ async write(text) {+ for (const line of text.split('\n').map((s) => s.trim()).filter(Boolean)) {+ const [c] = line.split(' ');+ const f = Object.fromEntries(line.split(' ').slice(1).map((p) => p.split('=')));+ if (c === 'HELLO') this.emit('KEYWORD v=demo proto=1');+ else if (c === 'SIDES?') this.emit(this.sidesLine());+ else if (c === 'KEYS?') {+ for (const s of SIDES) if (this.present[s]) this.emit(`KEY+ uid=${this.uids[s]} at=${s}`);+ this.emit('KEYS END');+ } else if (c === 'MAP') { this.maps[f.uid] = f; this.emit(`OK MAP uid=${f.uid}`); }+ else if (c === 'UNMAP') { delete this.maps[f.uid]; this.emit(`OK UNMAP uid=${f.uid}`); }+ else if (c === 'CLEAR') { this.maps = {}; this.emit('OK CLEAR'); }+ else if (c === 'SAVE') this.emit('OK SAVE');+ else this.emit(`ERR unknown command ${c}`);+ }+ }+ async close() {}+}++// ---- Profiles (persisted by main.js, or localStorage when run in a browser) ----++const storage = window.desktop+ ? { load: () => window.desktop.loadStore(), save: (s) => window.desktop.saveStore(s) }+ : {+ load: async () => { try { return JSON.parse(localStorage.getItem('keyword-profiles')); } catch { return null; } },+ save: async (s) => { try { localStorage.setItem('keyword-profiles', JSON.stringify(s)); } catch {} },+ };++let store = Profiles.normalizeStore(null);+const activeProfile = () => store.profiles.find((p) => p.id === store.active);+function persist() {+ storage.save(store).catch((e) => log('!!', `could not save profiles: ${e.message}`));+}++// ---- Connection state ----++let transport = null;+let timers = [];+let lastRx = 0;+const keys = new Map(); // uid -> { at, pressed } for Keybits the Keyword reports+let sides = {}; // from SIDES lines+let syncSeen = null; // uids seen during a KEYS? reply++function setStatus(text, cls) {+ $('#status-text').textContent = text;+ $('#status').className = 'status ' + (cls || '');+}++function activity(text, cls) {+ const list = $('#activity');+ list.prepend(el('li', { className: cls || '' }, el('time', { textContent: new Date().toLocaleTimeString() }), el('span', { textContent: text })));+ while (list.children.length > 100) list.lastChild.remove();+}++const shortUid = (uid) => uid.slice(-4);+const keyName = (uid) => activeProfile().keys[uid]?.name || `Keybit ${shortUid(uid)}`;+const comboFor = (uid) => {+ const m = activeProfile().keys[uid];+ return m && (m.mods || m.key) ? Hid.comboLabel(m.mods, m.key, MAC) : '';+};++function addKey(uid, at, quiet) {+ const known = keys.get(uid);+ keys.set(uid, { at, pressed: known?.pressed || false });+ if (!known && !quiet) {+ activity(`${keyName(uid)} connected${at ? ` on the ${SIDE_NAMES[at]}` : ''}`, 'add');+ flashUid = uid;+ }+}+function removeKey(uid) {+ if (!keys.has(uid)) return;+ const { at } = keys.get(uid);+ keys.delete(uid);+ activity(`${keyName(uid)} disconnected${at ? ` from the ${SIDE_NAMES[at]}` : ''}`, 'remove');+}++let flashUid = null;++function render() {+ // Board+ for (const s of SIDES) {+ const uid = [...keys].find(([, k]) => k.at === s)?.[0];+ const present = !!uid || !!sides[s];+ const slot = $(`.slot[data-side="${s}"]`);+ slot.classList.toggle('present', present);+ slot.querySelector('.slot-label').textContent = !present ? '' : uid ? (comboFor(uid) || keyName(uid)) : 'Keybit';+ slot.title = uid ? `${keyName(uid)} · uid ${uid}` : '';+ }++ // Key list: connected first (left, top, right), then mapped keys that are offline.+ const order = { L: 0, T: 1, R: 2 };+ const online = [...keys].sort((a, b) => (order[a[1].at] ?? 9) - (order[b[1].at] ?? 9)).map(([u]) => u);+ const offline = Object.keys(activeProfile().keys).filter((u) => !keys.has(u)).sort();+ const list = $('#keys');+ list.replaceChildren();+ for (const uid of [...online, ...offline]) {+ const k = keys.get(uid);+ const combo = comboFor(uid);+ const where = k ? (k.at ? SIDE_NAMES[k.at][0].toUpperCase() + SIDE_NAMES[k.at].slice(1) : 'Connected') : 'Not connected';+ const btns = el('div', { className: 'btns' });+ btns.append(el('button', { className: 'ghost small', textContent: 'Assign…', onclick: () => openAssign(uid) }));+ if (k && transport instanceof DemoTransport) {+ btns.append(el('button', { className: 'ghost small', textContent: 'Tap', onclick: () => transport.tap(uid) }));+ }+ if (!k) btns.append(el('button', { className: 'ghost small', textContent: 'Forget', onclick: () => forgetKey(uid) }));+ const li = el('li', { className: [k ? '' : 'offline', k?.pressed ? 'pressed' : '', flashUid === uid ? 'flash' : ''].join(' ') },+ el('div', {}, el('div', { className: 'name', textContent: keyName(uid) }),+ el('div', { className: 'meta' }, `${where} · uid `, el('code', { textContent: uid }))),+ el('span', { className: 'combo' + (combo ? '' : ' none'), textContent: combo || 'not assigned' }),+ btns);+ li.dataset.uid = uid;+ list.append(li);+ }+ flashUid = null;+ $('#keys-empty').hidden = list.children.length > 0;+ $('#keys-empty').textContent = transport+ ? "No Keybits connected. Attach one to the Keyword's left, right or top edge."+ : 'Connect to the Keyword to see its Keybits.';++ // Profiles+ const sel = $('#profile-select');+ sel.replaceChildren(...store.profiles.map((p) => el('option', { value: p.id, textContent: p.name, selected: p.id === store.active })));+ $('#p-delete').disabled = store.profiles.length < 2;+ $('#p-apply').disabled = !transport;+}++function handleLine(line) {+ lastRx = Date.now();+ log('<-', line);+ const msg = parseLine(line);+ switch (msg.type) {+ case 'hello':+ setStatus(`Connected over ${transport.label} · Keyword firmware ${msg.fw}`, 'connected');+ if (msg.proto !== 1) log('!!', `protocol ${msg.proto}, app expects 1`);+ break;+ case 'sides':+ for (const [s, v] of Object.entries(msg.sides)) {+ sides[s] = v;+ // A KEY- may have been missed: drop keys on a side that is now empty.+ if (!v) for (const [uid, k] of keys) if (k.at === s) removeKey(uid);+ }+ break;+ case 'keyAdd':+ syncSeen?.add(msg.uid);+ addKey(msg.uid, msg.at, false);+ break;+ case 'keysEnd':+ if (syncSeen) for (const uid of [...keys.keys()]) if (!syncSeen.has(uid)) removeKey(uid);+ syncSeen = null;+ break;+ case 'keyRemove':+ removeKey(msg.uid);+ break;+ case 'press': {+ const k = keys.get(msg.uid);+ if (k) k.pressed = msg.down;+ else addKey(msg.uid, null, false);+ const li = document.querySelector(`#keys li[data-uid="${msg.uid}"]`);+ if (li) { li.classList.toggle('pressed', msg.down); return; } // skip a full re-render+ break;+ }+ case 'error':+ log('!!', msg.message);+ activity(`Keyword error: ${msg.message}`, 'remove');+ break;+ }+ render();+}++async function send(...lines) {+ if (!transport) return;+ for (const l of lines) {+ log('->', l);+ try { await transport.write(l + '\n'); } catch (e) { log('!!', `write failed: ${e.message}`); return; }+ }+}++function syncKeys() {+ syncSeen = new Set();+ send(cmd.keys());+}++function applyProfile() {+ if (!transport) return;+ send(...profileCommands(activeProfile().keys));+ activity(`Sent profile "${activeProfile().name}" to the Keyword`);+}++async function connect(t) {+ await disconnect();+ setStatus(`Connecting over ${t.label}…`, 'busy');+ const lines = new LineBuffer(handleLine);+ try {+ await t.open((text) => lines.push(text), () => { log('!!', 'device disconnected'); disconnect(); });+ } catch (e) {+ closeDialog(chooser);+ setStatus(e.name === 'NotFoundError' ? 'Not connected' : `Could not connect: ${e.message}`);+ return;+ }+ transport = t;+ lastRx = Date.now();+ setStatus(`Connected over ${t.label} · waiting for Keyword…`, 'busy');+ const demo = t instanceof DemoTransport;+ document.body.classList.toggle('demo', demo);+ $('#demo-hint').hidden = !demo;+ $('#btn-disconnect').hidden = false;+ activity(`Connected over ${t.label}`);+ render();+ await send(cmd.hello(), cmd.sides());+ syncKeys();+ applyProfile();+ timers = [+ setInterval(() => {+ send(cmd.sides());+ if (Date.now() - lastRx > STALE_MS) setStatus(`Connected over ${t.label} · no reply from the Keyword`, 'stale');+ }, POLL_MS),+ setInterval(syncKeys, KEYS_POLL_MS),+ ];+}++async function disconnect() {+ timers.forEach(clearInterval);+ timers = [];+ const t = transport;+ transport = null;+ if (t) {+ await t.close();+ activity('Disconnected');+ }+ document.body.classList.remove('demo');+ $('#demo-hint').hidden = true;+ $('#btn-disconnect').hidden = true;+ keys.clear();+ sides = {};+ render();+ setStatus('Not connected');+}++// ---- Dialog helpers ----++function closeDialog(d) { if (d.open) d.close(); }++function askText(title, value) {+ const d = $('#prompt');+ $('#prompt-title').textContent = title;+ const input = $('#prompt-input');+ input.value = value || '';+ return new Promise((resolve) => {+ const done = (v) => { closeDialog(d); resolve(v); };+ $('#prompt-ok').onclick = () => done(input.value.trim() || null);+ $('#prompt-cancel').onclick = () => done(null);+ input.onkeydown = (e) => { if (e.key === 'Enter') { e.preventDefault(); done(input.value.trim() || null); } };+ d.oncancel = () => resolve(null);+ d.showModal();+ input.select();+ });+}++// ---- Device chooser (Electron forwards the device list from main.js) ----++const chooser = $('#chooser');+if (window.devicePicker) {+ window.devicePicker.onList(({ kind, devices }) => {+ $('#chooser-title').textContent = kind === 'serial' ? 'Choose the Keyword serial port' : 'Choose the Keyword';+ const list = $('#chooser-list');+ list.replaceChildren();+ devices.sort((a, b) => b.likely - a.likely);+ for (const d of devices) {+ const b = el('button', { className: d.likely ? 'likely' : '' },+ el('span', { textContent: d.name }), el('small', { textContent: d.detail || '' }));+ b.onclick = () => { window.devicePicker.pick(d.id); closeDialog(chooser); };+ list.append(el('li', {}, b));+ }+ $('#chooser-empty').textContent = kind === 'serial' ? 'No serial ports found. Is the Keyword plugged in?' : 'Searching for Bluetooth devices…';+ $('#chooser-empty').hidden = devices.length > 0;+ if (!chooser.open) chooser.showModal();+ });+}+$('#chooser-cancel').onclick = () => { window.devicePicker?.pick(''); closeDialog(chooser); };+chooser.addEventListener('cancel', () => window.devicePicker?.pick(''));++// ---- Assign dialog ----++const assign = $('#assign');+const capture = $('#capture');+let assignUid = null;+let draft = { mods: 0, key: 0 };++$('#assign-mods').append(...Hid.MODS.map((m) =>+ el('label', {}, el('input', { type: 'checkbox', value: m.bit }), Hid.modName(m, MAC))));+$('#assign-key').append(el('option', { value: 0, textContent: '(no key, modifiers only)' }),+ ...Hid.KEYS.map((k) => el('option', { value: k.usage, textContent: k.label })));++function showDraft() {+ $('#assign-mods').querySelectorAll('input').forEach((c) => { c.checked = !!(draft.mods & (1 << c.value)); });+ $('#assign-key').value = draft.key;+ $('#capture-combo').textContent = Hid.comboLabel(draft.mods, draft.key, MAC) || 'Press a key or shortcut…';+}+$('#assign-mods').addEventListener('change', () => {+ draft.mods = [...$('#assign-mods').querySelectorAll('input')].reduce((m, c) => m | (c.checked ? 1 << c.value : 0), 0);+ showDraft();+});+$('#assign-key').addEventListener('change', (e) => { draft.key = Number(e.target.value); showDraft(); });++function captureKey(e) {+ const r = Hid.fromEvent(e);+ if (!r) return;+ draft = { mods: r.mods, key: r.usage };+ showDraft();+}+capture.addEventListener('keydown', (e) => { e.preventDefault(); e.stopPropagation(); captureKey(e); });+capture.addEventListener('focus', () => window.desktop?.setCapture(true));+capture.addEventListener('blur', () => window.desktop?.setCapture(false));+window.desktop?.onCaptureKey((k) => { if (k.type === 'keyDown') captureKey(k); });++function openAssign(uid) {+ assignUid = uid;+ const m = activeProfile().keys[uid];+ draft = { mods: m?.mods || 0, key: m?.key || 0 };+ $('#assign-name').textContent = keyName(uid);+ $('#assign-label').value = m?.name || '';+ $('#assign-clear').disabled = !m;+ showDraft();+ assign.showModal();+ capture.focus();+}+function closeAssign() {+ window.desktop?.setCapture(false);+ closeDialog(assign);+}+assign.addEventListener('close', () => window.desktop?.setCapture(false));+$('#assign-cancel').onclick = closeAssign;+$('#assign-save').onclick = () => {+ const uid = assignUid;+ const name = $('#assign-label').value.trim();+ const p = activeProfile();+ if (!draft.mods && !draft.key && !name) delete p.keys[uid];+ else p.keys[uid] = { mods: draft.mods, key: draft.key, ...(name ? { name } : {}) };+ persist();+ if (draft.mods || draft.key) send(cmd.map(uid, draft.mods, draft.key), cmd.save());+ else send(cmd.unmap(uid), cmd.save());+ activity(`${keyName(uid)} → ${comboFor(uid) || 'nothing'}`);+ closeAssign();+ render();+};+$('#assign-clear').onclick = () => {+ delete activeProfile().keys[assignUid];+ persist();+ send(cmd.unmap(assignUid), cmd.save());+ closeAssign();+ render();+};++function forgetKey(uid) {+ delete activeProfile().keys[uid];+ persist();+ render();+}++// ---- Profile buttons ----++function switchTo(id) {+ store.active = id;+ persist();+ render();+ applyProfile();+}+$('#profile-select').onchange = (e) => switchTo(e.target.value);+$('#p-new').onclick = async () => {+ const name = await askText('New profile name', `Profile ${store.profiles.length + 1}`);+ if (!name) return;+ const p = Profiles.newProfile(name);+ store.profiles.push(p);+ switchTo(p.id);+};+$('#p-dup').onclick = async () => {+ const cur = activeProfile();+ const name = await askText('Name for the copy', `${cur.name} copy`);+ if (!name) return;+ const p = Profiles.newProfile(name, JSON.parse(JSON.stringify(cur.keys)));+ store.profiles.push(p);+ switchTo(p.id);+};+$('#p-rename').onclick = async () => {+ const name = await askText('Rename profile', activeProfile().name);+ if (!name) return;+ activeProfile().name = name;+ persist();+ render();+};+$('#p-delete').onclick = () => {+ if (store.profiles.length < 2) return;+ if (!confirm(`Delete profile "${activeProfile().name}"?`)) return;+ store.profiles = store.profiles.filter((p) => p.id !== store.active);+ switchTo(store.profiles[0].id);+};+$('#p-export').onclick = async () => {+ const p = activeProfile();+ const text = Profiles.exportProfile(p);+ if (window.desktop) {+ if (await window.desktop.exportProfile(p.name, text)) activity(`Exported "${p.name}"`);+ return;+ }+ const a = el('a', { href: URL.createObjectURL(new Blob([text], { type: 'application/json' })), download: `${p.name}.keyword.json` });+ a.click();+ URL.revokeObjectURL(a.href);+};+function importText(text) {+ try {+ const p = Profiles.importProfile(text);+ store.profiles.push(p);+ activity(`Imported "${p.name}"`);+ switchTo(p.id);+ } catch (e) {+ activity(`Import failed: ${e.message}`, 'remove');+ }+}+$('#p-import').onclick = async () => {+ if (window.desktop) {+ const text = await window.desktop.importProfile();+ if (text != null) importText(text);+ return;+ }+ const input = el('input', { type: 'file', accept: '.json,application/json' });+ input.onchange = async () => { if (input.files[0]) importText(await input.files[0].text()); };+ input.click();+};+$('#p-apply').onclick = applyProfile;++// ---- Connection buttons ----++$('#btn-usb').onclick = () => {+ if (!('serial' in navigator)) return setStatus('Web Serial is not available here');+ connect(new SerialTransport());+};+$('#btn-ble').onclick = () => {+ if (!('bluetooth' in navigator)) return setStatus('Web Bluetooth is not available here');+ connect(new BleTransport());+};+$('#btn-demo').onclick = () => connect(new DemoTransport());+$('#btn-disconnect').onclick = () => disconnect();++document.querySelectorAll('.board .slot').forEach((slot) => {+ slot.addEventListener('click', () => {+ if (transport instanceof DemoTransport) transport.toggle(slot.dataset.side);+ });+});++storage.load().then((s) => { store = Profiles.normalizeStore(s); render(); });+render();diff --git a/app/renderer/hid.js b/app/renderer/hid.jsnew file mode 100644index 0000000..ef054db--- /dev/null+++ b/app/renderer/hid.js@@ -0,0 +1,80 @@+// USB HID keyboard usages (HID Usage Tables, page 0x07) keyed by KeyboardEvent.code.+(function (root) {+ const KEYS = [];+ const add = (code, usage, label) => KEYS.push({ code, usage, label });++ for (let i = 0; i < 26; i++) {+ const c = String.fromCharCode(65 + i);+ add(`Key${c}`, 0x04 + i, c);+ }+ '1234567890'.split('').forEach((d, i) => add(`Digit${d}`, 0x1e + i, d));+ [+ ['Enter', 0x28, 'Enter'], ['Escape', 0x29, 'Esc'], ['Backspace', 0x2a, 'Backspace'],+ ['Tab', 0x2b, 'Tab'], ['Space', 0x2c, 'Space'], ['Minus', 0x2d, '-'], ['Equal', 0x2e, '='],+ ['BracketLeft', 0x2f, '['], ['BracketRight', 0x30, ']'], ['Backslash', 0x31, '\\'],+ ['Semicolon', 0x33, ';'], ['Quote', 0x34, "'"], ['Backquote', 0x35, '`'], ['Comma', 0x36, ','],+ ['Period', 0x37, '.'], ['Slash', 0x38, '/'], ['CapsLock', 0x39, 'Caps Lock'],+ ].forEach((k) => add(...k));+ for (let i = 1; i <= 12; i++) add(`F${i}`, 0x39 + i, `F${i}`);+ [+ ['PrintScreen', 0x46, 'Print Screen'], ['ScrollLock', 0x47, 'Scroll Lock'], ['Pause', 0x48, 'Pause'],+ ['Insert', 0x49, 'Insert'], ['Home', 0x4a, 'Home'], ['PageUp', 0x4b, 'Page Up'],+ ['Delete', 0x4c, 'Delete'], ['End', 0x4d, 'End'], ['PageDown', 0x4e, 'Page Down'],+ ['ArrowRight', 0x4f, '→'], ['ArrowLeft', 0x50, '←'], ['ArrowDown', 0x51, '↓'], ['ArrowUp', 0x52, '↑'],+ ['NumLock', 0x53, 'Num Lock'], ['NumpadDivide', 0x54, 'Num /'], ['NumpadMultiply', 0x55, 'Num *'],+ ['NumpadSubtract', 0x56, 'Num -'], ['NumpadAdd', 0x57, 'Num +'], ['NumpadEnter', 0x58, 'Num Enter'],+ ].forEach((k) => add(...k));+ for (let i = 1; i <= 9; i++) add(`Numpad${i}`, 0x58 + i, `Num ${i}`);+ [+ ['Numpad0', 0x62, 'Num 0'], ['NumpadDecimal', 0x63, 'Num .'], ['IntlBackslash', 0x64, 'Intl \\'],+ ['ContextMenu', 0x65, 'Menu'], ['NumpadEqual', 0x67, 'Num ='],+ ].forEach((k) => add(...k));+ for (let i = 13; i <= 24; i++) add(`F${i}`, 0x5b + i, `F${i}`);+ [+ ['AudioVolumeMute', 0x7f, 'Mute'], ['AudioVolumeUp', 0x80, 'Volume Up'],+ ['AudioVolumeDown', 0x81, 'Volume Down'],+ ].forEach((k) => add(...k));++ const byCode = new Map(KEYS.map((k) => [k.code, k]));+ const byUsage = new Map(KEYS.map((k) => [k.usage, k]));++ // Modifier byte bits, as in the HID boot keyboard report.+ const MODS = [+ { bit: 0, code: 'ControlLeft', name: 'Ctrl' },+ { bit: 1, code: 'ShiftLeft', name: 'Shift' },+ { bit: 2, code: 'AltLeft', name: 'Alt' },+ { bit: 3, code: 'MetaLeft', name: 'GUI' },+ { bit: 4, code: 'ControlRight', name: 'Right Ctrl' },+ { bit: 5, code: 'ShiftRight', name: 'Right Shift' },+ { bit: 6, code: 'AltRight', name: 'Right Alt' },+ { bit: 7, code: 'MetaRight', name: 'Right GUI' },+ ];+ const modByCode = new Map(MODS.map((m) => [m.code, m]));++ function modName(m, mac) {+ if (!mac) return m.name.replace('GUI', 'Win');+ return m.name.replace('GUI', 'Cmd').replace('Alt', 'Option');+ }++ // "Ctrl+Shift+A", "Cmd+Space", "Shift" (modifier only), "" when empty.+ function comboLabel(mods, usage, mac) {+ const parts = MODS.filter((m) => mods & (1 << m.bit)).map((m) => modName(m, mac));+ if (usage) parts.push(byUsage.get(usage)?.label || `0x${usage.toString(16).padStart(2, '0')}`);+ return parts.join('+');+ }++ // Turns a key event ({code, ctrlKey, shiftKey, altKey, metaKey}) into {mods, usage}.+ // usage is 0 when only modifiers are held. Returns null for keys HID can't send.+ function fromEvent(e) {+ let mods = (e.ctrlKey ? 1 : 0) | (e.shiftKey ? 2 : 0) | (e.altKey ? 4 : 0) | (e.metaKey ? 8 : 0);+ const mod = modByCode.get(e.code);+ if (mod) return { mods: mods | (1 << mod.bit), usage: 0 };+ const k = byCode.get(e.code);+ if (!k) return null;+ return { mods, usage: k.usage };+ }++ const api = { KEYS, MODS, byUsage, comboLabel, fromEvent, modName };+ if (typeof module !== 'undefined' && module.exports) module.exports = api;+ else root.Hid = api;+})(typeof window !== 'undefined' ? window : globalThis);diff --git a/app/renderer/index.html b/app/renderer/index.htmlnew file mode 100644index 0000000..2424a84--- /dev/null+++ b/app/renderer/index.html@@ -0,0 +1,106 @@+<!doctype html>+<html lang="en">+<head>+ <meta charset="utf-8">+ <meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self'">+ <meta name="viewport" content="width=device-width, initial-scale=1">+ <title>Keyword Monitor</title>+ <link rel="stylesheet" href="style.css">+</head>+<body>+ <header>+ <h1>Keyword Monitor</h1>+ <div class="actions">+ <button id="btn-usb">USB serial</button>+ <button id="btn-ble">Bluetooth</button>+ <button id="btn-demo" class="ghost">Demo</button>+ <button id="btn-disconnect" class="ghost" hidden>Disconnect</button>+ </div>+ </header>++ <div id="status" class="status">+ <span class="dot"></span><span id="status-text">Not connected</span>+ </div>++ <main>+ <section class="col">+ <div class="board" aria-label="Keyword and its sides">+ <div class="slot slot-T" data-side="T"><span class="slot-label"></span></div>+ <div class="slot slot-L" data-side="L"><span class="slot-label"></span></div>+ <div class="keyword">Keyword</div>+ <div class="slot slot-R" data-side="R"><span class="slot-label"></span></div>+ </div>+ <p id="demo-hint" class="hint center" hidden>Demo: click a side to attach or remove a Keybit.</p>++ <h2>Keys</h2>+ <ul id="keys" class="keys"></ul>+ <p id="keys-empty" class="hint">No Keybits connected. Attach one to the Keyword's left, right or top edge.</p>+ </section>++ <section class="col side">+ <h2>Profile</h2>+ <div class="profile-row">+ <select id="profile-select" aria-label="Active profile"></select>+ </div>+ <div class="btn-row">+ <button id="p-new" class="ghost small">New</button>+ <button id="p-dup" class="ghost small">Duplicate</button>+ <button id="p-rename" class="ghost small">Rename</button>+ <button id="p-delete" class="ghost small">Delete</button>+ </div>+ <div class="btn-row">+ <button id="p-import" class="ghost small">Import…</button>+ <button id="p-export" class="ghost small">Export…</button>+ <button id="p-apply" class="small">Send to Keyword</button>+ </div>+ <p id="profile-note" class="hint">Profiles save automatically on this computer.</p>++ <h2>Activity</h2>+ <ul id="activity" class="activity"></ul>+ </section>+ </main>++ <details class="log">+ <summary>Raw log</summary>+ <pre id="log"></pre>+ </details>++ <dialog id="chooser">+ <h2 id="chooser-title">Choose a device</h2>+ <ul id="chooser-list"></ul>+ <p id="chooser-empty" class="hint">Searching…</p>+ <div class="dialog-actions"><button id="chooser-cancel" class="ghost">Cancel</button></div>+ </dialog>++ <dialog id="assign">+ <h2>Assign <span id="assign-name"></span></h2>+ <div id="capture" class="capture" tabindex="0">+ <span id="capture-combo">Press a key or shortcut…</span>+ </div>+ <p class="hint">Or build it by hand, for keys your OS keeps for itself:</p>+ <div id="assign-mods" class="mods"></div>+ <select id="assign-key" aria-label="Key"></select>+ <label class="field">Name <input id="assign-label" maxlength="40" placeholder="optional, e.g. Mute mic"></label>+ <div class="dialog-actions">+ <button id="assign-clear" class="ghost">Unassign</button>+ <span class="spacer"></span>+ <button id="assign-cancel" class="ghost">Cancel</button>+ <button id="assign-save">Save</button>+ </div>+ </dialog>++ <dialog id="prompt">+ <h2 id="prompt-title"></h2>+ <input id="prompt-input" maxlength="40">+ <div class="dialog-actions">+ <button id="prompt-cancel" class="ghost">Cancel</button>+ <button id="prompt-ok">OK</button>+ </div>+ </dialog>++ <script src="protocol.js"></script>+ <script src="hid.js"></script>+ <script src="profiles.js"></script>+ <script src="app.js"></script>+</body>+</html>diff --git a/app/renderer/profiles.js b/app/renderer/profiles.jsnew file mode 100644index 0000000..c4de116--- /dev/null+++ b/app/renderer/profiles.js@@ -0,0 +1,55 @@+// Keymap profiles: { id, name, keys: { <UID>: { mods, key, name? } } }.+// The store is { active: <id>, profiles: [...] } and is saved as JSON by main.js.+(function (root) {+ const FORMAT = 'keyword-profile';++ const newId = () => Math.random().toString(36).slice(2, 10);++ function newProfile(name, keys = {}) {+ return { id: newId(), name: name || 'Profile', keys: { ...keys } };+ }++ function cleanKeys(keys) {+ const out = {};+ if (!keys || typeof keys !== 'object') return out;+ for (const [uid, m] of Object.entries(keys)) {+ if (!/^([0-9a-fA-F]{24}|[0-9a-fA-F]{8})$/.test(uid) || !m || typeof m !== 'object') continue;+ const entry = { mods: (Number(m.mods) || 0) & 0xff, key: (Number(m.key) || 0) & 0xff };+ if (typeof m.name === 'string' && m.name.trim()) entry.name = m.name.trim().slice(0, 40);+ out[uid.toUpperCase()] = entry;+ }+ return out;+ }++ // What gets written by Export.+ function exportProfile(p) {+ return JSON.stringify({ format: FORMAT, version: 1, name: p.name, keys: cleanKeys(p.keys) }, null, 2);+ }++ // Parses an exported file. Throws with a readable message if it isn't one.+ function importProfile(text) {+ let data;+ try { data = JSON.parse(text); } catch { throw new Error('Not a JSON file'); }+ if (!data || data.format !== FORMAT) throw new Error('Not a Keyword profile');+ if (data.version !== 1) throw new Error(`Unsupported profile version ${data.version}`);+ return newProfile(typeof data.name === 'string' && data.name.trim() ? data.name.trim() : 'Imported', cleanKeys(data.keys));+ }++ // Repairs a store loaded from disk so the UI can trust it.+ function normalizeStore(store) {+ const profiles = Array.isArray(store?.profiles)+ ? store.profiles.filter((p) => p && typeof p === 'object').map((p) => ({+ id: typeof p.id === 'string' ? p.id : newId(),+ name: typeof p.name === 'string' && p.name ? p.name : 'Profile',+ keys: cleanKeys(p.keys),+ }))+ : [];+ if (!profiles.length) profiles.push(newProfile('Default'));+ const active = profiles.some((p) => p.id === store?.active) ? store.active : profiles[0].id;+ return { active, profiles };+ }++ const api = { newProfile, exportProfile, importProfile, normalizeStore, cleanKeys };+ if (typeof module !== 'undefined' && module.exports) module.exports = api;+ else root.Profiles = api;+})(typeof window !== 'undefined' ? window : globalThis);diff --git a/app/renderer/protocol.js b/app/renderer/protocol.jsnew file mode 100644index 0000000..719786e--- /dev/null+++ b/app/renderer/protocol.js@@ -0,0 +1,106 @@+// Keyword host protocol: newline-terminated ASCII lines, same over USB CDC and BLE.+// See ../README.md for the full description.+(function (root) {+ const SIDES = ['L', 'R', 'T'];++ // Nordic UART Service, used as a plain byte pipe over BLE.+ const NUS = {+ service: '6e400001-b5a3-f393-e0a9-e50e24dcca9e',+ rx: '6e400002-b5a3-f393-e0a9-e50e24dcca9e', // host writes here+ tx: '6e400003-b5a3-f393-e0a9-e50e24dcca9e', // keyword notifies here+ };++ // Splits a byte/char stream into lines. Handles \r\n and partial chunks.+ class LineBuffer {+ constructor(onLine) {+ this.buf = '';+ this.onLine = onLine;+ }+ push(text) {+ this.buf += text;+ let i;+ while ((i = this.buf.indexOf('\n')) >= 0) {+ const line = this.buf.slice(0, i).replace(/\r$/, '').trim();+ this.buf = this.buf.slice(i + 1);+ if (line) this.onLine(line);+ }+ if (this.buf.length > 4096) this.buf = ''; // garbage with no newline+ }+ }++ // Parses "KEY=val KEY=val" into an object.+ function parseFields(parts) {+ const out = {};+ for (const p of parts) {+ const eq = p.indexOf('=');+ if (eq > 0) out[p.slice(0, eq)] = p.slice(eq + 1);+ }+ return out;+ }++ const isUid = (u) => typeof u === 'string' && /^([0-9a-fA-F]{24}|[0-9a-fA-F]{8})$/.test(u);+ const hex2 = (n) => (n & 0xff).toString(16).toUpperCase().padStart(2, '0');++ // Host -> Keyword commands.+ const cmd = {+ hello: () => 'HELLO',+ sides: () => 'SIDES?',+ keys: () => 'KEYS?',+ map: (uid, mods, key) => `MAP uid=${uid} mods=${hex2(mods)} key=${hex2(key)}`,+ mapQuery: (uid) => `MAP? uid=${uid}`,+ unmap: (uid) => `UNMAP uid=${uid}`,+ clear: () => 'CLEAR',+ save: () => 'SAVE',+ };++ // Commands that make the Keyword match a profile exactly.+ function profileCommands(keys) {+ const out = [cmd.clear()];+ for (const [uid, m] of Object.entries(keys)) {+ if (isUid(uid) && (m.mods || m.key)) out.push(cmd.map(uid.toUpperCase(), m.mods || 0, m.key || 0));+ }+ out.push(cmd.save());+ return out;+ }++ // Returns {type, ...} or {type: 'unknown', line}.+ function parseLine(line) {+ const parts = line.trim().split(/\s+/);+ const cmd = parts[0];+ const f = parseFields(parts.slice(1));+ switch (cmd) {+ case 'KEYWORD':+ return { type: 'hello', fw: f.v || '?', proto: Number(f.proto || 0) };+ case 'SIDES': {+ const sides = {};+ for (const s of SIDES) if (s in f) sides[s] = f[s] === '1';+ if (!Object.keys(sides).length) break;+ return { type: 'sides', sides };+ }+ case 'KEY+':+ if (!isUid(f.uid)) break;+ return { type: 'keyAdd', uid: f.uid.toUpperCase(), at: SIDES.includes(f.at) ? f.at : null };+ case 'KEY-':+ if (!isUid(f.uid)) break;+ return { type: 'keyRemove', uid: f.uid.toUpperCase() };+ case 'KEYS':+ if (parts[1] === 'END') return { type: 'keysEnd' };+ break;+ case 'PRESS':+ if (!isUid(f.uid)) break;+ return { type: 'press', uid: f.uid.toUpperCase(), down: f.down === '1' };+ case 'MAP':+ if (!isUid(f.uid)) break;+ return { type: 'map', uid: f.uid.toUpperCase(), mods: parseInt(f.mods || '0', 16) || 0, key: parseInt(f.key || '0', 16) || 0 };+ case 'OK':+ return { type: 'ok', what: parts[1] || '', ...parseFields(parts.slice(2)) };+ case 'ERR':+ return { type: 'error', message: parts.slice(1).join(' ') };+ }+ return { type: 'unknown', line };+ }++ const api = { SIDES, NUS, LineBuffer, parseLine, cmd, profileCommands, isUid };+ if (typeof module !== 'undefined' && module.exports) module.exports = api;+ else root.KeywordProtocol = api;+})(typeof window !== 'undefined' ? window : globalThis);diff --git a/app/renderer/style.css b/app/renderer/style.cssnew file mode 100644index 0000000..e702edb--- /dev/null+++ b/app/renderer/style.css@@ -0,0 +1,165 @@+:root {+ --bg: #f5f6f8;+ --panel: #ffffff;+ --text: #1b1d22;+ --muted: #6b7280;+ --line: #d6d9df;+ --accent: #2f6fde;+ --on: #1f9d63;+ --on-soft: #d9f2e6;+ --warn: #c98a12;+ --off: #9aa1ad;+ --keyword: #2a2f3a;+ --keyword-text: #f0f2f5;+ --press-soft: #e3ecfb;+ --accent-text: #ffffff;+ color-scheme: light;+}+@media (prefers-color-scheme: dark) {+ :root {+ --bg: #14161a;+ --panel: #1d2026;+ --text: #e8eaee;+ --muted: #9099a8;+ --line: #333844;+ --accent: #6c9cf0;+ --on: #3cc287;+ --on-soft: #18392b;+ --warn: #e0a83a;+ --off: #5d6472;+ --keyword: #3a4150;+ --keyword-text: #f0f2f5;+ --press-soft: #1d2c47;+ --accent-text: #0d1220;+ color-scheme: dark;+ }+}++* { box-sizing: border-box; }+body {+ margin: 0;+ font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;+ background: var(--bg);+ color: var(--text);+ display: flex;+ flex-direction: column;+ min-height: 100vh;+}++header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+ flex-wrap: wrap;+ padding: 14px 20px;+ border-bottom: 1px solid var(--line);+ background: var(--panel);+}+h1 { font-size: 16px; margin: 0; font-weight: 600; }+.actions { display: flex; gap: 8px; flex-wrap: wrap; }++button {+ font: inherit;+ padding: 6px 14px;+ border-radius: 6px;+ border: 1px solid var(--accent);+ background: var(--accent);+ color: var(--accent-text);+ cursor: pointer;+}+button.ghost { background: transparent; color: var(--text); border-color: var(--line); }+button:disabled { opacity: 0.5; cursor: default; }++.status { display: flex; align-items: center; gap: 8px; padding: 10px 20px; color: var(--muted); }+.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); }+.status.connected .dot { background: var(--on); }+.status.stale .dot, .status.busy .dot { background: var(--warn); }++main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; padding: 20px; align-items: start; }+@media (max-width: 760px) { main { grid-template-columns: 1fr; } }+.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }+.col.side { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }+h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 8px 0 0; font-weight: 600; }+.center { text-align: center; }+.board { align-self: center; margin: 8px 0 4px; }+button.small { padding: 4px 10px; font-size: 13px; }+.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }+select, input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%; }++.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }+.keys li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; transition: border-color 0.1s, background 0.1s; }+.keys li.offline { opacity: 0.55; }+.keys li.pressed { border-color: var(--accent); background: var(--press-soft); }+.keys li.flash { animation: flash 1.2s ease-out; }+@keyframes flash { from { border-color: var(--on); box-shadow: 0 0 0 3px var(--on-soft); } to { box-shadow: 0 0 0 0 transparent; } }+.keys .name { font-weight: 600; }+.keys .meta { color: var(--muted); font-size: 12px; }+.keys .meta code { font-family: ui-monospace, Menlo, monospace; }+.keys .combo { justify-self: end; font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px; }+.keys .combo.none { color: var(--muted); font-family: inherit; border-style: dashed; }+.keys .btns { grid-column: 2; display: flex; gap: 6px; justify-content: flex-end; }++.activity { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }+.activity li { display: flex; gap: 8px; }+.activity time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }+.activity .add { color: var(--on); }+.activity .remove { color: var(--warn); }++.slot-label { font-size: 12px; text-align: center; padding: 2px; word-break: break-word; }++.capture { border: 2px dashed var(--accent); border-radius: 8px; padding: 18px; text-align: center; font-size: 18px; font-family: ui-monospace, Menlo, monospace; margin-bottom: 8px; outline: none; }+.capture:focus { background: var(--press-soft); }+.mods { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 6px 0 8px; font-size: 13px; }+.mods label { display: flex; gap: 4px; align-items: center; }+.mods input { width: auto; }+.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: 13px; color: var(--muted); }+.spacer { flex: 1; }+.dialog-actions { gap: 8px; }++/* Keyword in the middle, Keybit slots left, right and above. */+.board {+ --u: clamp(56px, 13vw, 96px);+ --gap: 6px;+ display: grid;+ grid-template-columns: var(--u) calc(var(--u) * 2) var(--u);+ grid-template-rows: var(--u) var(--u);+ gap: var(--gap);+}+.keyword {+ grid-column: 2; grid-row: 2;+ background: var(--keyword);+ color: var(--keyword-text);+ border-radius: 8px;+ display: grid; place-items: center;+ font-weight: 600;+}+.slot-T { grid-column: 2; grid-row: 1; width: var(--u); justify-self: center; }+.slot-L { grid-column: 1; grid-row: 2; }+.slot-R { grid-column: 3; grid-row: 2; }+.slot {+ border: 2px dashed var(--line);+ border-radius: 8px;+ display: grid; place-items: center;+ color: transparent;+ transition: background 0.15s, border-color 0.15s;+}+.slot.present { border: 2px solid var(--on); background: var(--on-soft); color: var(--on); font-weight: 600; }+.demo .slot { cursor: pointer; }+.demo .slot:hover { border-color: var(--accent); }+++.hint { color: var(--muted); margin: 0; }++.log { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 20px; }+.log summary { cursor: pointer; color: var(--muted); }+.log pre { max-height: 160px; overflow: auto; margin: 8px 0 0; font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; }++dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); width: min(420px, 90vw); padding: 18px; }+dialog::backdrop { background: rgba(0, 0, 0, 0.4); }+dialog h2 { font-size: 15px; margin: 0 0 10px; }+#chooser-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; }+#chooser-list button { width: 100%; text-align: left; background: transparent; color: var(--text); border: 1px solid var(--line); margin-bottom: 6px; display: flex; flex-direction: column; }+#chooser-list button.likely { border-color: var(--on); }+#chooser-list small { color: var(--muted); }+.dialog-actions { display: flex; justify-content: flex-end; margin-top: 10px; }diff --git a/app/test/hid.test.js b/app/test/hid.test.jsnew file mode 100644index 0000000..6c2d08e--- /dev/null+++ b/app/test/hid.test.js@@ -0,0 +1,27 @@+const test = require('node:test');+const assert = require('node:assert');+const Hid = require('../renderer/hid.js');++test('usages match the HID table', () => {+ const u = (code) => Hid.KEYS.find((k) => k.code === code).usage;+ assert.strictEqual(u('KeyA'), 0x04);+ assert.strictEqual(u('KeyZ'), 0x1d);+ assert.strictEqual(u('Digit1'), 0x1e);+ assert.strictEqual(u('Digit0'), 0x27);+ assert.strictEqual(u('F1'), 0x3a);+ assert.strictEqual(u('F12'), 0x45);+ assert.strictEqual(u('Numpad1'), 0x59);+ assert.strictEqual(u('Numpad9'), 0x61);+ assert.strictEqual(u('F13'), 0x68);+ assert.strictEqual(u('F24'), 0x73);+ assert.strictEqual(new Set(Hid.KEYS.map((k) => k.usage)).size, Hid.KEYS.length);+});++test('fromEvent and labels', () => {+ assert.deepStrictEqual(Hid.fromEvent({ code: 'KeyC', ctrlKey: true, shiftKey: true }), { mods: 3, usage: 6 });+ assert.deepStrictEqual(Hid.fromEvent({ code: 'ShiftRight', shiftKey: true }), { mods: 0x22, usage: 0 });+ assert.strictEqual(Hid.fromEvent({ code: 'Fn' }), null);+ assert.strictEqual(Hid.comboLabel(0x09, 0x2c, true), 'Ctrl+Cmd+Space');+ assert.strictEqual(Hid.comboLabel(0x09, 0x2c, false), 'Ctrl+Win+Space');+ assert.strictEqual(Hid.comboLabel(0x02, 0, false), 'Shift');+});diff --git a/app/test/profiles.test.js b/app/test/profiles.test.jsnew file mode 100644index 0000000..b6aa077--- /dev/null+++ b/app/test/profiles.test.js@@ -0,0 +1,31 @@+const test = require('node:test');+const assert = require('node:assert');+const P = require('../renderer/profiles.js');++test('export then import round-trips', () => {+ const p = P.newProfile('Gaming', { '5f1821c1': { mods: 2, key: 4, name: 'Jump' } });+ const back = P.importProfile(P.exportProfile(p));+ assert.strictEqual(back.name, 'Gaming');+ assert.deepStrictEqual(back.keys, { '5F1821C1': { mods: 2, key: 4, name: 'Jump' } });+ assert.notStrictEqual(back.id, p.id);+});++test('import rejects other files', () => {+ assert.throws(() => P.importProfile('nope'), /JSON/);+ assert.throws(() => P.importProfile('{"a":1}'), /Not a Keyword profile/);+ assert.throws(() => P.importProfile('{"format":"keyword-profile","version":9}'), /version/);+});++test('import drops bad keys', () => {+ const p = P.importProfile(JSON.stringify({ format: 'keyword-profile', version: 1, keys: { xyz: { key: 4 }, '0000000A': { key: 999, mods: 'x' } } }));+ assert.deepStrictEqual(p.keys, { '0000000A': { mods: 0, key: 999 & 0xff } });+ assert.strictEqual(p.name, 'Imported');+});++test('normalizeStore fills in a default', () => {+ const s = P.normalizeStore(null);+ assert.strictEqual(s.profiles.length, 1);+ assert.strictEqual(s.active, s.profiles[0].id);+ const s2 = P.normalizeStore({ active: 'zz', profiles: [{ id: 'a', name: 'A', keys: {} }] });+ assert.strictEqual(s2.active, 'a');+});diff --git a/app/test/protocol.test.js b/app/test/protocol.test.jsnew file mode 100644index 0000000..0bf30aa--- /dev/null+++ b/app/test/protocol.test.js@@ -0,0 +1,59 @@+const test = require('node:test');+const assert = require('node:assert');+const { LineBuffer, parseLine, cmd, profileCommands } = require('../renderer/protocol.js');++test('parses SIDES', () => {+ assert.deepStrictEqual(parseLine('SIDES L=1 R=0 T=0'), {+ type: 'sides',+ sides: { L: true, R: false, T: false },+ });+});++test('SIDES with only some fields', () => {+ assert.deepStrictEqual(parseLine('SIDES R=1').sides, { R: true });+ assert.strictEqual(parseLine('SIDES').type, 'unknown');+});++test('parses HELLO reply', () => {+ assert.deepStrictEqual(parseLine('KEYWORD v=0.1 proto=1'), { type: 'hello', fw: '0.1', proto: 1 });+});++test('accepts 96-bit UIDs', () => {+ const uid = '3B0A4F1C88D2E61F5F1821C1';+ assert.deepStrictEqual(parseLine(`KEY+ uid=${uid.toLowerCase()} at=L`), { type: 'keyAdd', uid, at: 'L' });+ assert.strictEqual(cmd.map(uid, 1, 4), `MAP uid=${uid} mods=01 key=04`);+ assert.strictEqual(parseLine('KEY+ uid=3B0A4F1C88D2 at=L').type, 'unknown');+});++test('parses ERR', () => {+ assert.deepStrictEqual(parseLine('ERR i2c timeout'), { type: 'error', message: 'i2c timeout' });+});++test('line buffer splits chunks and CRLF', () => {+ const lines = [];+ const lb = new LineBuffer((l) => lines.push(l));+ lb.push('SIDES L=1 ');+ lb.push('R=0\r\nKEYW');+ lb.push('ORD v=1 proto=1\n\n');+ assert.deepStrictEqual(lines, ['SIDES L=1 R=0', 'KEYWORD v=1 proto=1']);+});++test('parses key events', () => {+ assert.deepStrictEqual(parseLine('KEY+ uid=5f1821c1 at=R'), { type: 'keyAdd', uid: '5F1821C1', at: 'R' });+ assert.deepStrictEqual(parseLine('KEY+ uid=5F1821C1 at=?'), { type: 'keyAdd', uid: '5F1821C1', at: null });+ assert.deepStrictEqual(parseLine('KEY- uid=5F1821C1'), { type: 'keyRemove', uid: '5F1821C1' });+ assert.deepStrictEqual(parseLine('PRESS uid=5F1821C1 down=1'), { type: 'press', uid: '5F1821C1', down: true });+ assert.deepStrictEqual(parseLine('KEYS END'), { type: 'keysEnd' });+ assert.strictEqual(parseLine('KEY+ uid=xyz').type, 'unknown');+});++test('parses MAP and OK', () => {+ assert.deepStrictEqual(parseLine('MAP uid=5F1821C1 mods=0A key=04'), { type: 'map', uid: '5F1821C1', mods: 10, key: 4 });+ assert.deepStrictEqual(parseLine('OK MAP uid=5F1821C1'), { type: 'ok', what: 'MAP', uid: '5F1821C1' });+});++test('formats commands', () => {+ assert.strictEqual(cmd.map('5F1821C1', 0x0a, 0x04), 'MAP uid=5F1821C1 mods=0A key=04');+ assert.deepStrictEqual(profileCommands({ '5F1821C1': { mods: 1, key: 6 }, '00000001': { mods: 0, key: 0 }, bad: { key: 4 } }),+ ['CLEAR', 'MAP uid=5F1821C1 mods=01 key=06', 'SAVE']);+});