Skip to content

Commit ed7c69a

Browse files
authored
Merge pull request #391 from circuitpython/beta
Merge Bug fixes from Beta
2 parents 296e059 + 19a2fbb commit ed7c69a

File tree

11 files changed

+484
-875
lines changed

11 files changed

+484
-875
lines changed

js/common/ble-file-transfer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import {FileTransferClient as BLEFileTransferClient} from '@adafruit/ble-file-transfer-js';
2+
//import {FileTransferClient as BLEFileTransferClient} from '../../../ble-file-transfer-js/adafruit-ble-file-transfer.js';
23

34
// Wrapper for BLEFileTransferClient to add additional functionality
45
class FileTransferClient extends BLEFileTransferClient {
56
constructor(bleDevice, bufferSize) {
67
super(bleDevice, bufferSize);
78
}
89

10+
async readOnly() {
11+
let readonly = false;
12+
return false;
13+
// Check if the device is read only
14+
console.log("Checking if device is read only");
15+
// Attempt to write a 0-byte temp file and remove it
16+
const testPath = '/._ble_readonly_check';
17+
try {
18+
await this.writeFile(testPath, 0, new Uint8Array(0));
19+
await this.deleteFile(testPath);
20+
} catch (e) {
21+
readonly = true;
22+
}
23+
return readonly;
24+
}
25+
926
async versionInfo() {
1027
// Possibly open /boot_out.txt and read the version info
1128
let versionInfo = {};

js/common/dialogs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class GenericModal {
195195
this._closeModal();
196196
}
197197

198+
isOpen() {
199+
return this._currentModal !== null;
200+
}
201+
198202
isVisible() {
199203
var style = window.getComputedStyle(this._currentModal);
200204
return style.display !== 'none';

js/common/file_dialog.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,12 @@ class FileDialog extends GenericModal {
444444
}
445445

446446
for (let filename of filenames) {
447-
// Delete the item
448-
await this._showBusy(this._fileHelper.delete(filename));
447+
await this._showBusy(this._fileHelper.delete(this._currentPath + filename));
449448
}
450449

451450
// Refresh the file list
452451
await this._openFolder();
453-
};
452+
}
454453

455454
async _handleUploadButton() {
456455
if (this._readOnlyMode) return;
@@ -670,12 +669,16 @@ class FileDialog extends GenericModal {
670669
}
671670

672671
// Rename the file, by moving in the same folder
673-
await this._showBusy(
674-
this._fileHelper.move(
675-
this._currentPath + oldName,
676-
this._currentPath + newName
677-
)
678-
);
672+
try {
673+
await this._showBusy(
674+
this._fileHelper.move(
675+
this._currentPath + oldName,
676+
this._currentPath + newName
677+
)
678+
);
679+
} catch (error) {
680+
console.error(error);
681+
}
679682

680683
// Refresh the file list
681684
await this._openFolder();

js/common/fsapi-file-transfer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,18 @@ class FileTransferClient {
289289
const [parentFolder, itemName] = this._splitPath(path);
290290
const parentFolderHandle = await this._getSubfolderHandle(parentFolder);
291291

292-
await parentFolderHandle.removeEntry(itemName);
292+
try {
293+
await parentFolderHandle.removeEntry(itemName, {recursive: true});
294+
} catch (error) {
295+
// If this was a folder with items inside, a NotFoundError is thrown due to a bug in the browser
296+
if (error.name == 'NotFoundError') {
297+
// Recursive items should be removed at this point,
298+
// so attempt again without recursive
299+
await parentFolderHandle.removeEntry(itemName);
300+
} else {
301+
throw error;
302+
}
303+
}
293304

294305
return true;
295306
}

js/layout.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,24 @@ function refitTerminal() {
135135
let viewportHeight = window.innerHeight;
136136
let terminalHeight = viewportHeight - headerHeight - footerBarHeight - serialBarHeight;
137137
let terminalWidth = document.getElementById('serial-page').offsetWidth;
138-
let screen = document.querySelector('.xterm-screen');
139-
if (screen) {
138+
let xterm_screen = document.querySelector('.xterm-screen');
139+
if (xterm_screen) {
140140
let cols = Math.floor(terminalWidth / TERMINAL_COL_WIDTH);
141141
let rows = Math.floor(terminalHeight / TERMINAL_ROW_HEIGHT);
142+
console.log(rows, cols, terminalHeight, terminalWidth, TERMINAL_ROW_HEIGHT, TERMINAL_COL_WIDTH);
142143
if (cols < MINIMUM_COLS) {
143144
cols = MINIMUM_COLS;
144145
}
145146
if (rows < MINIMUM_ROWS) {
146147
rows = MINIMUM_ROWS;
147148
}
148-
screen.style.width = (cols * TERMINAL_COL_WIDTH) + 'px';
149-
screen.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
149+
xterm_screen.style.width = (cols * TERMINAL_COL_WIDTH) + 'px';
150+
xterm_screen.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
151+
let xterm_rows = document.querySelector('.xterm-rows');
152+
if (xterm_rows) {
153+
xterm_rows.style.height = (rows * TERMINAL_ROW_HEIGHT) + 'px';
154+
}
155+
state.terminal.resize(cols, rows);
150156
}
151157
});
152158
});

js/workflows/ble.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {CONNTYPE} from '../constants.js';
77
import {Workflow} from './workflow.js';
88
import {GenericModal, DeviceInfoModal} from '../common/dialogs.js';
99
import {sleep} from '../common/utilities.js';
10-
import {bluetooth} from 'webbluetooth';
1110

1211
const bleNusServiceUUID = 'adaf0001-4369-7263-7569-74507974686e';
1312
const bleNusCharRXUUID = 'adaf0002-4369-7263-7569-74507974686e';
@@ -72,8 +71,7 @@ class BLEWorkflow extends Workflow {
7271
}
7372
try {
7473
this.clearConnectStatus();
75-
const devices = await bluetooth.getDevices();
76-
console.log(devices);
74+
const devices = await navigator.bluetooth.getDevices();
7775
this.connectionStep(devices.length > 0 ? 2 : 1);
7876
} catch (error) {
7977
console.error(error);
@@ -119,7 +117,7 @@ class BLEWorkflow extends Workflow {
119117
if (!this.connectionStatus()) {
120118
try {
121119
console.log('Getting existing permitted Bluetooth devices...');
122-
const devices = await bluetooth.getDevices();
120+
const devices = await navigator.bluetooth.getDevices();
123121

124122
console.log('> Found ' + devices.length + ' Bluetooth device(s).');
125123
// These devices may not be powered on or in range, so scan for
@@ -137,7 +135,7 @@ class BLEWorkflow extends Workflow {
137135

138136
// Bring up a dialog to request a device
139137
async requestDevice() {
140-
return bluetooth.requestDevice({
138+
return navigator.bluetooth.requestDevice({
141139
filters: [{services: [0xfebb]},], // <- Prefer filters to save energy & show relevant devices.
142140
optionalServices: [0xfebb, bleNusServiceUUID]
143141
});
@@ -171,11 +169,11 @@ class BLEWorkflow extends Workflow {
171169
device.removeEventListener('advertisementreceived', onAdvertisementReceived.bind(this));
172170
device.addEventListener('advertisementreceived', onAdvertisementReceived.bind(this));
173171

174-
this.debugLog("connecting to " + device.name);
172+
this.debugLog("Attempting to connect to " + device.name + "...");
175173
try {
176174
this.clearConnectStatus();
177175
console.log('Watching advertisements from "' + device.name + '"...');
178-
console.log('If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device');
176+
console.log('If no advertisements are received, make sure the device is powered on and in range. You can also try resetting the device.');
179177
await device.watchAdvertisements({signal: abortController.signal});
180178
}
181179
catch (error) {
@@ -194,22 +192,24 @@ class BLEWorkflow extends Workflow {
194192
await this.connectToBluetoothDevice(device);
195193
}
196194

195+
async onConnected(e) {
196+
this.debugLog("Connected to " + this.bleDevice.name);
197+
await super.onConnected(e);
198+
}
199+
197200
async switchToDevice(device) {
198-
console.log(device);
199201
this.bleDevice = device;
200202
this.bleDevice.removeEventListener("gattserverdisconnected", this.onDisconnected.bind(this));
201203
this.bleDevice.addEventListener("gattserverdisconnected", this.onDisconnected.bind(this));
202-
//this.bleServer = this.bleDevice.gatt;
203204
console.log("connected", this.bleServer);
204-
let services;
205205

206-
console.log(device.gatt.connected);
207-
//try {
206+
try {
207+
let services;
208208
services = await this.bleServer.getPrimaryServices();
209-
/*} catch (e) {
209+
console.log(services);
210+
} catch (e) {
210211
console.log(e, e.stack);
211-
}*/
212-
console.log(services);
212+
}
213213

214214
console.log('Initializing File Transfer Client...');
215215
this.initFileClient(new FileTransferClient(this.bleDevice, 65536));
@@ -253,7 +253,7 @@ class BLEWorkflow extends Workflow {
253253
}
254254
// Is this a new connection?
255255
if (!this.bleDevice) {
256-
let devices = await bluetooth.getDevices();
256+
let devices = await navigator.bluetooth.getDevices();
257257
for (const device of devices) {
258258
await this.connectToBluetoothDevice(device);
259259
}

js/workflows/usb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class USBWorkflow extends Workflow {
4747
async onConnected(e) {
4848
this.connectDialog.close();
4949
await this.loadEditor();
50+
this.debugLog("connected");
5051
super.onConnected(e);
5152
}
5253

js/workflows/web.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class WebWorkflow extends Workflow {
5959
}
6060

6161
async onConnected(e) {
62+
this.debugLog("connected");
6263
await super.onConnected(e);
6364
//this.connIntervalId = setInterval(this._checkConnection.bind(this), PING_INTERVAL_MS);
6465
}

js/workflows/workflow.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Workflow {
103103
}
104104

105105
async onDisconnected(e, reconnect = true) {
106+
console.log("onDisconnected called in workflow");
106107
this.debugLog("disconnected");
107108
this.updateConnected(CONNSTATE.disconnected);
108109
// Update Common UI Elements
@@ -115,7 +116,6 @@ class Workflow {
115116
}
116117

117118
async onConnected(e) {
118-
this.debugLog("connected");
119119
console.log("Connected!");
120120
this.updateConnected(CONNSTATE.connected);
121121
if (this.connectDialog) {
@@ -314,6 +314,11 @@ class Workflow {
314314

315315
// Handle the different button states for various connection steps
316316
connectionStep(step) {
317+
// Check if a dialog exists
318+
if (!this.connectDialog.isOpen()) {
319+
return;
320+
}
321+
317322
if (step < 0) step = 0;
318323
if (step > this.buttonStates.length - 1) step = this.buttonStates.length - 1;
319324

@@ -340,6 +345,11 @@ class Workflow {
340345
}
341346

342347
clearConnectStatus(modal) {
348+
// Check if a dialog exists
349+
if (!this.connectDialog.isOpen()) {
350+
return;
351+
}
352+
343353
try {
344354
const modal = this.connectDialog.getModal();
345355
modal.querySelector('.connect-status').hidden = true;

0 commit comments

Comments
 (0)