Skip to content

Commit 68e4df7

Browse files
authored
Merge pull request #187 from makermelissa/main
Lots of bug fixes
2 parents 66172f9 + dddd0b9 commit 68e4df7

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

js/common/dialogs.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {sleep, isIp, switchDevice} from './utilities.js';
2+
import * as focusTrap from 'focus-trap';
23

34
const SELECTOR_CLOSE_BUTTON = ".popup-modal__close";
45
const SELECTOR_BLACKOUT = "#blackout";
@@ -16,6 +17,7 @@ class GenericModal {
1617
this.closeModal = this._closeModal.bind(this);
1718
this._elements = {};
1819
this._modalLayerId;
20+
this._trap = null;
1921
}
2022

2123
_addDialogElement(elementId, domElement, eventName = null, eventHandler = null) {
@@ -99,6 +101,13 @@ class GenericModal {
99101
this._modalLayerId = modalLayers.length;
100102
modal.style.zIndex = BLACKOUT_ZINDEX + 1 + (this._modalLayerId * 2);
101103

104+
if (!this._trap){
105+
this._trap = focusTrap.createFocusTrap(modal, {
106+
initialFocus: () => modal,
107+
allowOutsideClick: true,
108+
});
109+
}
110+
102111
if (modalLayers.length >= 2) {
103112
// Then we will make it so the clickblock layer appears
104113
const clickBlock = document.querySelector(SELECTOR_CLICKBLOCK);
@@ -168,6 +177,10 @@ class GenericModal {
168177
}
169178

170179
if (this._currentModal) {
180+
if (this._trap) {
181+
this._trap.deactivate();
182+
this._trap = null;
183+
}
171184
this._removeTopModalLayer();
172185
this._removeAllDialogElements();
173186
this._currentModal.classList.remove('is--visible');
@@ -206,6 +219,9 @@ class GenericModal {
206219
this._reject = reject;
207220
});
208221

222+
if (this._trap) {
223+
this._trap.activate();
224+
}
209225
return p;
210226
}
211227
}

js/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ function refitTerminal() {
9191

9292
// Fix the viewport height for mobile devices by setting
9393
// the --vh css variable to 1% of the window inner height
94-
function fixViewportHeight() {
94+
function fixViewportHeight(e) {
9595
let vh = window.innerHeight * 0.01;
9696
document.documentElement.style.setProperty('--vh', `${vh}px`);
97-
refitTerminal();
97+
updatePageLayout();
9898
}
9999
fixViewportHeight();
100100
window.addEventListener("resize", fixViewportHeight);

js/script.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ workflows[CONNTYPE.Web] = new WebWorkflow();
2929

3030
let workflow = null;
3131
let unchanged = 0;
32+
let connectionPromise = null;
3233

3334
const btnRestart = document.querySelector('.btn-restart');
3435
const btnClear = document.querySelector('.btn-clear');
@@ -253,8 +254,10 @@ function setFilename(path) {
253254
}
254255

255256
async function chooseConnection() {
257+
// Don't allow more than one dialog
258+
if (connectionPromise) return;
256259
// Get the promise first
257-
let p = connectionType.open();
260+
connectionPromise = connectionType.open();
258261

259262
// Disable any buttons in validBackends, but not in workflows
260263
let modal = connectionType.getModal();
@@ -266,7 +269,8 @@ async function chooseConnection() {
266269
};
267270

268271
// Wait for the user to click a button
269-
let connType = await p;
272+
let connType = await connectionPromise;
273+
connectionPromise = null
270274
if (isValidBackend(connType)) {
271275
return getBackendWorkflow(connType);
272276
}
@@ -507,7 +511,7 @@ editor = new EditorView({
507511
parent: document.querySelector('#editor')
508512
});
509513

510-
function setupXterm() {
514+
async function setupXterm() {
511515
state.terminal = new Terminal({
512516
theme: {
513517
background: '#333',
@@ -522,8 +526,10 @@ function setupXterm() {
522526
state.terminal.loadAddon(new WebLinksAddon());
523527

524528
state.terminal.open(document.getElementById('terminal'));
525-
state.terminal.onData((data) => {
526-
workflow.serialTransmit(data);
529+
state.terminal.onData((data) => async function(e) {
530+
if (await checkConnected()) {
531+
workflow.serialTransmit(data);
532+
}
527533
});
528534
}
529535

@@ -547,7 +553,7 @@ function loadParameterizedContent() {
547553
}
548554

549555
document.addEventListener('DOMContentLoaded', async (event) => {
550-
setupXterm();
556+
await setupXterm();
551557
btnConnect.forEach((element) => {
552558
element.addEventListener('click', async function(e) {
553559
e.preventDefault();

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
"dependencies": {
1616
"@codemirror/lang-python": "^6.1.6",
1717
"@fortawesome/fontawesome-free": "^6.5.2",
18-
"idb-keyval": "^6.2.1",
19-
"jszip": "^3.10.1",
18+
"ble-file-transfer-js": "adafruit/ble-file-transfer-js#1.0.2",
19+
"circuitpython-repl-js": "adafruit/circuitpython-repl-js#1.2.3",
2020
"codemirror": "^6.0.1",
2121
"file-saver": "^2.0.5",
22+
"focus-trap": "^7.5.4",
23+
"idb-keyval": "^6.2.1",
24+
"jszip": "^3.10.1",
2225
"xterm": "^5.3.0",
2326
"xterm-addon-fit": "^0.8.0",
24-
"xterm-addon-web-links": "^0.9.0",
25-
"ble-file-transfer-js": "adafruit/ble-file-transfer-js#1.0.2",
26-
"circuitpython-repl-js": "adafruit/circuitpython-repl-js#1.2.3"
27+
"xterm-addon-web-links": "^0.9.0"
2728
}
2829
}

0 commit comments

Comments
 (0)