From fc192b754389ea2413d52460cad6ad3df1b1f712 Mon Sep 17 00:00:00 2001 From: Florian Scheuner Date: Thu, 12 Oct 2023 23:08:31 +0300 Subject: [PATCH 1/9] fix: show/hide behaviour for windows terminal (#95) Fixes show/hide behaviour when having Windows Terminal instead of Windows Console Host configured as the standard terminal application. See https://github.com/hetrodoo/node-hide-console-window/pull/8
Before https://github.com/flybywiresim/simbridge/assets/50082450/b0ae6a10-5734-430e-a1bd-c8460edf1500 Note the terminal application stays in the task bar, instead some inconsistent minimize/maximize action is executed with the current version of Windows Terminal
After https://github.com/flybywiresim/simbridge/assets/50082450/f5bc6b6c-b63b-470e-8a8a-edb63a03d256 The terminal shows/hides from the task bar as intended.
--- package-lock.json | 30 +++++++++++++++--------------- package.json | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61ae3174..6ffd97ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,13 +6,13 @@ "packages": { "": { "name": "fbw-simbridge", - "version": "0.4.2", + "version": "0.4.4", "license": "GPL-3.0-only", "os": [ "win32" ], "dependencies": { - "@flybywiresim/msfs-nodejs": "^0.2.0", + "@flybywiresim/msfs-nodejs": "^0.3.0", "@nestjs/axios": "^0.0.6", "@nestjs/common": "^8.0.0", "@nestjs/config": "^1.2.0", @@ -34,7 +34,7 @@ "mime-types": "^2.1.34", "multicast-dns": "^7.2.5", "nest-winston": "^1.6.2", - "node-hide-console-window": "^2.1.1", + "node-hide-console-window": "^2.2.0", "open": "^8.4.0", "pdf-to-printer": "^5.2.0", "pdfjs-dist": "^2.13.216", @@ -2347,9 +2347,9 @@ } }, "node_modules/@flybywiresim/msfs-nodejs": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@flybywiresim/msfs-nodejs/-/msfs-nodejs-0.2.0.tgz", - "integrity": "sha512-BWeSsPtO9w2M1zTEaDrCp7Qq2eVhgf5BbrCPDvAXj72TN3ZOUs9Mn9IwV2GPpzYlzbhYJ46IqnFDWF1DjcxsKw==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@flybywiresim/msfs-nodejs/-/msfs-nodejs-0.3.0.tgz", + "integrity": "sha512-cijGPI0IDATb7icfDWC6wu1DoR0G8ehnYDYSKyMCngVBZ7ms7RUwIBWCdslMt8hJdjYSIlAAhF0SppGDL11fXQ==", "dependencies": { "node-addon-api": "^5.0.0" } @@ -12503,9 +12503,9 @@ } }, "node_modules/node-hide-console-window": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/node-hide-console-window/-/node-hide-console-window-2.1.1.tgz", - "integrity": "sha512-6knDFNCPJhgbXF10xJWVJb4COe6pvr4pI6wX4B3g9owErZD7oltrqiZS6wtoAH81dZUZFe6ys+kZDpcsH9nfqw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/node-hide-console-window/-/node-hide-console-window-2.2.0.tgz", + "integrity": "sha512-CNLpd14IJbDQqzl6ryrpc4tjB2modRV+OvKekuu0KvLhqBj7ybmDWTXxHexG6LRrWW55Hfky/ZyZheh0xVXxDg==", "hasInstallScript": true, "os": [ "win32" @@ -19605,9 +19605,9 @@ } }, "@flybywiresim/msfs-nodejs": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@flybywiresim/msfs-nodejs/-/msfs-nodejs-0.2.0.tgz", - "integrity": "sha512-BWeSsPtO9w2M1zTEaDrCp7Qq2eVhgf5BbrCPDvAXj72TN3ZOUs9Mn9IwV2GPpzYlzbhYJ46IqnFDWF1DjcxsKw==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@flybywiresim/msfs-nodejs/-/msfs-nodejs-0.3.0.tgz", + "integrity": "sha512-cijGPI0IDATb7icfDWC6wu1DoR0G8ehnYDYSKyMCngVBZ7ms7RUwIBWCdslMt8hJdjYSIlAAhF0SppGDL11fXQ==", "requires": { "node-addon-api": "^5.0.0" } @@ -27419,9 +27419,9 @@ } }, "node-hide-console-window": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/node-hide-console-window/-/node-hide-console-window-2.1.1.tgz", - "integrity": "sha512-6knDFNCPJhgbXF10xJWVJb4COe6pvr4pI6wX4B3g9owErZD7oltrqiZS6wtoAH81dZUZFe6ys+kZDpcsH9nfqw==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/node-hide-console-window/-/node-hide-console-window-2.2.0.tgz", + "integrity": "sha512-CNLpd14IJbDQqzl6ryrpc4tjB2modRV+OvKekuu0KvLhqBj7ybmDWTXxHexG6LRrWW55Hfky/ZyZheh0xVXxDg==" }, "node-int64": { "version": "0.4.0", diff --git a/package.json b/package.json index ab664a5d..b1b05e91 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "mime-types": "^2.1.34", "multicast-dns": "^7.2.5", "nest-winston": "^1.6.2", - "node-hide-console-window": "^2.1.1", + "node-hide-console-window": "^2.2.0", "open": "^8.4.0", "pdf-to-printer": "^5.2.0", "pdfjs-dist": "^2.13.216", From 2303485efa526a122da6d662d12db6d1ae3c6672 Mon Sep 17 00:00:00 2001 From: denolk Date: Wed, 18 Oct 2023 18:51:41 +0300 Subject: [PATCH 2/9] feat: add keyboard shortcut support for the mcdu remote display in browser mode (#86) docs pr ref: https://github.com/flybywiresim/docs/pull/887 --- this pr introduces keyboard shortcuts to the remote mcdu display on the browser via js keyEvents. Co-authored-by: Alex McBean --- apps/mcdu/src/App.jsx | 16 +++++-- apps/mcdu/src/McduKeyboardEvents.js | 71 +++++++++++++++++++++++++++++ apps/mcdu/src/index.html | 3 ++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 apps/mcdu/src/McduKeyboardEvents.js diff --git a/apps/mcdu/src/App.jsx b/apps/mcdu/src/App.jsx index 7f6eae5e..72047b61 100644 --- a/apps/mcdu/src/App.jsx +++ b/apps/mcdu/src/App.jsx @@ -1,9 +1,10 @@ import './assets/css/App.css'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import useWebSocket, { ReadyState } from 'react-use-websocket'; import { McduScreen } from './components/McduScreen'; import { McduButtons } from './components/McduButtons'; import { WebsocketContext } from './WebsocketContext'; +import { McduKeyboardEvents } from './McduKeyboardEvents'; import darkBg from './assets/images/mcdu-a32nx-dark.png'; import bg from './assets/images/mcdu-a32nx.png'; @@ -43,7 +44,7 @@ const App = () => { // automaticaly upgrate to wss if the page is served over https if (window.location.protocol === 'https:') { socketUrl = socketUrl.replace('ws', 'wss'); - }; + } const [content, setContent] = useState( { @@ -79,6 +80,13 @@ const App = () => { reconnectInterval: 500, }); + const { onKeyboardInput } = new McduKeyboardEvents(sendMessage); + const rootPanelRef = useRef(null); + + useEffect(() => { + rootPanelRef.current.focus(); + }, []); + useEffect(() => { if (readyState === ReadyState.OPEN) { sendMessage('requestUpdate'); @@ -100,7 +108,7 @@ const App = () => { } return ( - <> +
{!fullscreen && ( <>
@@ -151,7 +159,7 @@ const App = () => {
)} - +
); }; diff --git a/apps/mcdu/src/McduKeyboardEvents.js b/apps/mcdu/src/McduKeyboardEvents.js new file mode 100644 index 00000000..9df866ef --- /dev/null +++ b/apps/mcdu/src/McduKeyboardEvents.js @@ -0,0 +1,71 @@ +const McduFunctionalKeys = { + Tab: 'DIR', + Insert: 'PROG', + Home: 'PERF', + PageUp: 'INIT', + Enter: 'DATA', + NumpadEnter: 'DATA', + Delete: 'FPLN', + End: 'RAD', + PageDown: 'FUEL', + Escape: 'MENU', + ShiftLeft: 'AIRPORT', + ArrowLeft: 'PREVPAGE', + ArrowRight: 'NEXTPAGE', + ArrowUp: 'UP', + ArrowDown: 'DOWN', + Backspace: 'CLR', + Space: 'SP', + Minus: 'PLUSMINUS', + NumpadSubtract: 'PLUSMINUS', + NumpadAdd: 'PLUSMINUS', + Period: 'DOT', + NumpadDecimal: 'DOT', + NumpadDivide: 'DIV', + Slash: 'DIV', + NumpadMultiply: 'OVFY', +}; + +export class McduKeyboardEvents { + constructor(socketSender) { + this.socketSender = socketSender; + this.mcduFunctionalKeys = McduFunctionalKeys; + } + + getMcduKey = (keyEvent) => { + // match mcdu L/R row input for F keys + if (keyEvent.code.match(/F\d+/)) { + const fn = parseInt(keyEvent.code.replace('F', '')); + return fn <= 6 ? `L${fn}` : `R${fn - 6}`; + } + + // match a-z + if (keyEvent.code.match(/Key[A-Z]/)) { + return keyEvent.code.replace('Key', '').toLocaleUpperCase(); + } + + // match 0-9 + if (keyEvent.code.match(/(Digit|Numpad)\d/i)) { + return keyEvent.code.replace(/Digit|Numpad/i, ''); + } + + // match mcdu function keys + return this.mcduFunctionalKeys[keyEvent.code]; + } + + onKeyboardInput = (keyEvent) => { + //console.log('event', { key: keyEvent.key, code: keyEvent.code }); + const key = this.getMcduKey(keyEvent); + + if (key) { + keyEvent.preventDefault(); + keyEvent.stopPropagation(); + } else { + return; + } + + //console.log(`mcdu key: ${key}`); + + this.socketSender(`event:left:${key}`); + } +} diff --git a/apps/mcdu/src/index.html b/apps/mcdu/src/index.html index 21c5a17f..bc852a26 100644 --- a/apps/mcdu/src/index.html +++ b/apps/mcdu/src/index.html @@ -14,6 +14,9 @@