From 186a2a8ba93e5c63ff483fb123c9be5e284549de Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Sat, 24 Aug 2019 16:58:21 +0200 Subject: [PATCH] chore: Improve build --- forge.config.js | 12 +++++++ src/constants.ts | 1 + src/less/root.less | 7 ++-- src/less/start.less | 9 +++++ src/main/menu.ts | 5 +++ src/main/windows.ts | 4 ++- src/renderer/card-start.tsx | 14 +++----- src/renderer/emulator.tsx | 70 +++++++++++++++++++++---------------- static/index.html | 10 ------ tools/parcel-build.js | 2 +- 10 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 src/less/start.less diff --git a/forge.config.js b/forge.config.js index 4b81e00..8e51e26 100644 --- a/forge.config.js +++ b/forge.config.js @@ -17,6 +17,18 @@ module.exports = { osxSign: { identity: 'Developer ID Application: Felix Rieseberg (LT94ZKYDCJ)' }, + ignore: [ + /\/assets(\/?)/, + /\/docs(\/?)/, + /\/tools(\/?)/, + /\/src\/.*\.ts/, + /package-lock\.json/, + /README\.md/, + /tsconfig\.json/, + /Dockerfile/, + /issue_template\.md/, + /HELP\.md/, + ] }, makers: [ { diff --git a/src/constants.ts b/src/constants.ts index 75e63ea..8859339 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -22,6 +22,7 @@ export const IPC_COMMANDS = { MACHINE_STOP: 'MACHINE_STOP', MACHINE_RESET: 'MACHINE_RESET', MACHINE_ALT_F4: 'MACHINE_ALT_F4', + MACHINE_ESC: 'MACHINE_ESC', MACHINE_ALT_ENTER: 'MACHINE_ALT_ENTER', MACHINE_CTRL_ALT_DEL: 'MACHINE_CTRL_ALT_DEL', // Machine events diff --git a/src/less/root.less b/src/less/root.less index 1fc57fb..7a5e482 100644 --- a/src/less/root.less +++ b/src/less/root.less @@ -2,6 +2,7 @@ @import "./emulator.less"; @import "./info.less"; @import "./settings.less"; +@import "./start.less"; /* GENERAL RESETS */ @@ -51,7 +52,6 @@ section { .nav-link > img, .btn > img { height: 24px; - margin-top: -3px; margin-right: 4px; } @@ -66,8 +66,7 @@ section { nav .nav-link, nav .nav-logo { - height: 33px; - line-height: 1.5; + height: 37px; display: flex; } @@ -85,7 +84,7 @@ section { .btn { height: 40px; - padding-top: 6px; + padding-top: 3px; } .btn:focus { diff --git a/src/less/start.less b/src/less/start.less new file mode 100644 index 0000000..88e3c33 --- /dev/null +++ b/src/less/start.less @@ -0,0 +1,9 @@ +#section-start { + display: flex; + flex-direction: column; + + > small { + margin-top: 25px; + font-size: .8rem; + } +} diff --git a/src/main/menu.ts b/src/main/menu.ts index ca86c62..e1addd3 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -140,6 +140,11 @@ async function createMenu({ isRunning } = { isRunning: false }) { click: () => send(IPC_COMMANDS.MACHINE_ALT_ENTER), enabled: isRunning }, + { + label: "Send Esc", + click: () => send(IPC_COMMANDS.MACHINE_ESC), + enabled: isRunning + }, { type: "separator" }, diff --git a/src/main/windows.ts b/src/main/windows.ts index 641a5e7..0d89f31 100644 --- a/src/main/windows.ts +++ b/src/main/windows.ts @@ -11,7 +11,9 @@ export function getOrCreateWindow(): BrowserWindow { height: 768, useContentSize: true, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + sandbox: false, + webviewTag: false } }); diff --git a/src/renderer/card-start.tsx b/src/renderer/card-start.tsx index fdcce69..546147c 100644 --- a/src/renderer/card-start.tsx +++ b/src/renderer/card-start.tsx @@ -7,18 +7,12 @@ export interface CardStartProps { export class CardStart extends React.Component { public render() { return ( -
-
+
+
+ + Hit ESC to lock or unlock your mouse
); } diff --git a/src/renderer/emulator.tsx b/src/renderer/emulator.tsx index 46780bd..8efc3e1 100644 --- a/src/renderer/emulator.tsx +++ b/src/renderer/emulator.tsx @@ -69,6 +69,8 @@ export class Emulator extends React.Component<{}, EmulatorState> { } else { this.lockMouse(); } + + evt.stopPropagation(); } }; @@ -117,44 +119,31 @@ export class Emulator extends React.Component<{}, EmulatorState> { */ public setupIpcListeners() { ipcRenderer.on(IPC_COMMANDS.MACHINE_CTRL_ALT_DEL, () => { - if (this.state.emulator && this.state.isRunning) { - this.state.emulator.keyboard_send_scancodes([ - 0x1d, // ctrl - 0x38, // alt - 0x53, // delete - - // break codes - 0x1d | 0x80, - 0x38 | 0x80, - 0x53 | 0x80 - ]); - } + this.sendKeys([ + 0x1d, // ctrl + 0x38, // alt + 0x53 // delete + ]); }); ipcRenderer.on(IPC_COMMANDS.MACHINE_ALT_F4, () => { - if (this.state.emulator && this.state.isRunning) { - this.state.emulator.keyboard_send_scancodes([ - 0x38, // alt - 0x3e, // f4 - - // break codes - 0x38 | 0x80, - 0x3e | 0x80 - ]); - } + this.sendKeys([ + 0x38, // alt + 0x3e // f4 + ]); }); ipcRenderer.on(IPC_COMMANDS.MACHINE_ALT_ENTER, () => { - if (this.state.emulator && this.state.isRunning) { - this.state.emulator.keyboard_send_scancodes([ - 0x38, // alt - 0, // enter + this.sendKeys([ + 0x38, // alt + 0 // enter + ]); + }); - // break codes - 0x38 | 0x80, - 0 | 0x80 - ]); - } + ipcRenderer.on(IPC_COMMANDS.MACHINE_ESC, () => { + this.sendKeys([ + 0x18 // alt + ]); }); ipcRenderer.on(IPC_COMMANDS.MACHINE_STOP, this.stopEmulator); @@ -467,4 +456,23 @@ export class Emulator extends React.Component<{}, EmulatorState> { this.setState({ scale: target }); } } + + /** + * Send keys to the emulator (including the key-up), + * if it's running + * + * @param {Array} codes + */ + private sendKeys(codes: Array) { + if (this.state.emulator && this.state.isRunning) { + const scancodes = codes; + + // Push break codes (key-up) + for (const scancode of scancodes) { + scancodes.push(scancode | 0x80); + } + + this.state.emulator.keyboard_send_scancodes(scancodes); + } + } } diff --git a/static/index.html b/static/index.html index 336f952..cb7b4a5 100644 --- a/static/index.html +++ b/static/index.html @@ -12,15 +12,5 @@
- - - - - - - - - - \ No newline at end of file diff --git a/tools/parcel-build.js b/tools/parcel-build.js index b3bac78..985bda2 100644 --- a/tools/parcel-build.js +++ b/tools/parcel-build.js @@ -25,7 +25,7 @@ async function compileParcel (options = {}) { // key: './ssl/k.key' // path to custom key // }, logLevel: 3, // 3 = log everything, 2 = log warnings & errors, 1 = log errors - hmr: true, // Enable or disable HMR while watching + hmr: false, // Enable or disable HMR while watching hmrPort: 0, // The port the HMR socket runs on, defaults to a random free port (0 in node.js resolves to a random free port) sourceMaps: true, // Enable or disable sourcemaps, defaults to enabled (minified builds currently always create sourcemaps) hmrHostname: '', // A hostname for hot module reload, default to ''