A truly modular keyboard
C
app: start through open on macOS so Bluetooth doesn't crash it
Nathanf861dd3027fb
diff --git a/app/README.md b/app/README.mdindex 9e8a463..040b257 100644--- a/app/README.md+++ b/app/README.md@@ -16,6 +16,8 @@ npm installnpm start```+On macOS, `npm start` launches Electron through `open`. macOS would otherwise blame the terminal for the Bluetooth scan and kill the app when you press **Bluetooth**. The app's output still shows in the terminal. Set `KEYWORD_DIRECT_START=1` to run Electron directly, for example under a debugger.+**Demo** works without hardware and pretends to be a Keyword with every optional feature (battery, hold, macros, reflashing):- Click a side of the Keyword to attach or remove a Keybit.diff --git a/app/package.json b/app/package.jsonindex 80656b3..dcaf83b 100644--- a/app/package.json+++ b/app/package.json@@ -6,7 +6,7 @@"main": "main.js","private": true,"scripts": {- "start": "electron .",+ "start": "node scripts/start.js","test": "node --test","dist": "electron-builder"},@@ -18,16 +18,32 @@"appId": "com.keybytes.keyword-monitor","productName": "Keyword Monitor","publish": null,- "files": ["main.js", "preload.js", "renderer/**", "package.json"],+ "files": [+ "main.js",+ "preload.js",+ "renderer/**",+ "package.json"+ ],"mac": {"category": "public.app-category.utilities",- "target": ["dmg"],+ "target": [+ "dmg"+ ],"extendInfo": {"NSBluetoothAlwaysUsageDescription": "Keyword Monitor connects to your Keyword keyboard over Bluetooth.","NSBluetoothPeripheralUsageDescription": "Keyword Monitor connects to your Keyword keyboard over Bluetooth."}},- "win": { "target": ["nsis"] },- "linux": { "target": ["AppImage"], "category": "Utility" }+ "win": {+ "target": [+ "nsis"+ ]+ },+ "linux": {+ "target": [+ "AppImage"+ ],+ "category": "Utility"+ }}}diff --git a/app/scripts/start.js b/app/scripts/start.jsnew file mode 100644index 0000000..718ca2f--- /dev/null+++ b/app/scripts/start.js@@ -0,0 +1,26 @@+// Starts the app for development.+//+// On macOS, an Electron started straight from a terminal is treated as part of the terminal+// app for privacy checks. The first Bluetooth scan is then charged to Terminal / iTerm /+// VS Code, which has no Bluetooth usage string, and macOS kills the app on the spot.+// Starting it through LaunchServices (`open`) makes Electron.app itself responsible, and+// its Info.plist does declare Bluetooth use.+const { spawn, execSync } = require('child_process');+const path = require('path');++const appDir = path.join(__dirname, '..');+const electron = require('electron'); // path to the binary+const args = process.argv.slice(2);++if (process.platform !== 'darwin' || process.env.KEYWORD_DIRECT_START) {+ const child = spawn(electron, [appDir, ...args], { stdio: 'inherit' });+ child.on('exit', (code) => process.exit(code ?? 0));+} else {+ const bundle = path.resolve(path.dirname(electron), '..', '..'); // …/Electron.app+ // Send the app's output back to this terminal, since `open` would otherwise drop it.+ let tty = null;+ try { tty = execSync('tty', { stdio: ['inherit', 'pipe', 'ignore'] }).toString().trim(); } catch {}+ const io = tty && tty.startsWith('/dev/') ? ['--stdout', tty, '--stderr', tty] : [];+ const child = spawn('open', ['-W', '-n', ...io, bundle, '--args', appDir, ...args], { stdio: 'inherit' });+ child.on('exit', (code) => process.exit(code ?? 0));+}