Skip to content

Commit 0f96cae

Browse files
committed
fix bluetooth support issue for chrome on android.
and usb otg serial support for chrome on android.
1 parent 922adbe commit 0f96cae

File tree

5 files changed

+674
-11
lines changed

5 files changed

+674
-11
lines changed

src/js/DarkTheme.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DarkTheme.apply = function() {
3232
self.applyNormal();
3333
}
3434

35-
if (chrome.app.window !== undefined) {
35+
if (chrome?.app?.window !== undefined) {
3636
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', isEnabled);
3737
}
3838
});

src/js/main.js

+9
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ function startProcess() {
435435
$(this).data('state', state);
436436
});
437437

438+
439+
$("#menu_btn").on('click', function () {
440+
$("#tab-content-container .tab_container").addClass('reveal');
441+
});
442+
443+
$("#tab-content-container .tab_container").on('click', function () {
444+
$("#tab-content-container .tab_container").removeClass('reveal');
445+
});
446+
438447
let result = getConfig('logopen');
439448
if (result.logopen) {
440449
$("#showlog").trigger('click');

src/js/protocols/bluetooth.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const bluetoothDevices = [
2222
class BT extends EventTarget {
2323
constructor() {
2424
super();
25+
this.lastWrite=null;
2526

2627
if (!this.bluetooth && window && window.navigator && window.navigator.bluetooth) {
2728
this.bluetooth = navigator.bluetooth;
@@ -96,10 +97,14 @@ class BT extends EventTarget {
9697
}
9798

9899
async loadDevices() {
99-
const devices = await this.bluetooth.getDevices();
100+
try{
101+
const devices = await this.bluetooth.getDevices();
100102

101-
this.portCounter = 1;
102-
this.devices = devices.map(device => this.createPort(device));
103+
this.portCounter = 1;
104+
this.devices = devices.map(device => this.createPort(device));
105+
}catch(e){
106+
107+
}
103108
}
104109

105110
async requestPermissionDevice() {
@@ -260,8 +265,12 @@ class BT extends EventTarget {
260265
}
261266

262267
this.readCharacteristic.addEventListener('characteristicvaluechanged', this.handleNotification.bind(this));
263-
264-
return await this.readCharacteristic.readValue();
268+
try{
269+
return await this.readCharacteristic.readValue();
270+
}catch(e){
271+
console.error(e);
272+
return;
273+
}
265274
}
266275

267276
handleNotification(event) {
@@ -270,8 +279,9 @@ class BT extends EventTarget {
270279
for (let i = 0; i < event.target.value.byteLength; i++) {
271280
buffer[i] = event.target.value.getUint8(i);
272281
}
273-
274-
this.dispatchEvent(new CustomEvent("receive", { detail: buffer }));
282+
setTimeout(()=>{
283+
this.dispatchEvent(new CustomEvent("receive", { detail: buffer }));
284+
},0);
275285
}
276286

277287
startNotifications() {
@@ -348,8 +358,14 @@ class BT extends EventTarget {
348358
this.bytesSent += data.byteLength;
349359

350360
const dataBuffer = new Uint8Array(data);
351-
352-
await this.writeCharacteristic.writeValue(dataBuffer);
361+
try{
362+
if(this.lastWrite){
363+
await this.lastWrite;
364+
}
365+
}catch(error){
366+
console.error(error);
367+
}
368+
this.lastWrite = this.writeCharacteristic.writeValueWithoutResponse(dataBuffer);
353369

354370
return {
355371
bytesSent: data.byteLength,

src/js/utils/checkBrowserCompatibilty.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
import { serial as serialPolyfill } from './web-serial-polyfill/serial.ts';
2+
13
export function checkBrowserCompatibility() {
24
const compatible = "serial" in navigator;
35

46
if (!compatible) {
5-
const errorMessage = "Betaflight app requires Chrome, Chromium, Edge or Vivaldi browser.";
7+
if('usb' in navigator &&
8+
!('brave' in navigator)
9+
) {
10+
navigator.serial = serialPolyfill;
11+
}
12+
13+
if(navigator.serial || navigator?.bluetooth){
14+
return;
15+
}
16+
17+
const errorMessage = "No serial, usb or bluetooth is available! Betaflight app requires Chrome, Chromium, Edge or Vivaldi browser.";
618
const newDiv = document.createElement("div");
719

820
$('body')

0 commit comments

Comments
 (0)