Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/DarkTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DarkTheme.apply = function() {
self.applyNormal();
}

if (chrome.app.window !== undefined) {
if (chrome?.app?.window !== undefined) {
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', isEnabled);
}
});
Expand Down
9 changes: 9 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ function startProcess() {
$(this).data('state', state);
});


$("#menu_btn").on('click', function () {
$("#tab-content-container .tab_container").addClass('reveal');
});

$("#tab-content-container .tab_container").on('click', function () {
$("#tab-content-container .tab_container").removeClass('reveal');
});

let result = getConfig('logopen');
if (result.logopen) {
$("#showlog").trigger('click');
Expand Down
34 changes: 25 additions & 9 deletions src/js/protocols/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const bluetoothDevices = [
class BT extends EventTarget {
constructor() {
super();
this.lastWrite = null;

if (!this.bluetooth && window && window.navigator && window.navigator.bluetooth) {
this.bluetooth = navigator.bluetooth;
Expand Down Expand Up @@ -96,10 +97,14 @@ class BT extends EventTarget {
}

async loadDevices() {
const devices = await this.getDevices();
try {
const devices = await this.bluetooth.getDevices();

this.portCounter = 1;
this.devices = devices.map(device => this.createPort(device));
} catch(e) {

this.portCounter = 1;
this.devices = devices.map(device => this.createPort(device));
}
}

async requestPermissionDevice() {
Expand Down Expand Up @@ -260,8 +265,12 @@ class BT extends EventTarget {
}

this.readCharacteristic.addEventListener('characteristicvaluechanged', this.handleNotification.bind(this));

return await this.readCharacteristic.readValue();
try {
return await this.readCharacteristic.readValue();
} catch(e) {
console.error(e);
return;
}
}

handleNotification(event) {
Expand All @@ -270,8 +279,9 @@ class BT extends EventTarget {
for (let i = 0; i < event.target.value.byteLength; i++) {
buffer[i] = event.target.value.getUint8(i);
}

this.dispatchEvent(new CustomEvent("receive", { detail: buffer }));
setTimeout(()=>{
this.dispatchEvent(new CustomEvent("receive", { detail: buffer }));
},0);
}

startNotifications() {
Expand Down Expand Up @@ -348,8 +358,14 @@ class BT extends EventTarget {
this.bytesSent += data.byteLength;

const dataBuffer = new Uint8Array(data);

await this.writeCharacteristic.writeValue(dataBuffer);
try {
if (this.lastWrite){
await this.lastWrite;
}
} catch(error) {
console.error(error);
}
this.lastWrite = this.writeCharacteristic.writeValueWithoutResponse(dataBuffer);

return {
bytesSent: data.byteLength,
Expand Down
15 changes: 14 additions & 1 deletion src/js/utils/checkBrowserCompatibilty.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { serial as serialPolyfill } from './web-serial-polyfill/serial.ts';

export function isChromium() {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
if (!navigator.userAgentData) {
Expand All @@ -13,7 +15,18 @@ export function isChromium() {
}

export function checkBrowserCompatibility() {
const compatible = "serial" in navigator;
let compatible = "serial" in navigator;
if (!compatible) {
if('usb' in navigator &&
!('brave' in navigator)
) {
navigator.serial = serialPolyfill;
}

if(navigator?.serial || navigator?.bluetooth){
compatible = true;
}
}

if (isChromium() && compatible) {
return true;
Expand Down
Loading