Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Web Bluetoth API error #8

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions css/widget.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.custom-widget {
display: grid;
grid-template-columns: 200px 200px 200px;
grid-template-columns: 200px 200px 200px 200px;
grid-gap: 10px;
background-color: #fff;
color: #444;
Expand All @@ -20,4 +20,12 @@
border-radius: 5px;
padding: 20px;
font-size: 100%;
}
}

.error-box {
background-color: #ffffff;
color: #000000;
border-radius: 5px;
padding: 20px;
font-size: 100%;
}
18 changes: 18 additions & 0 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class LegoBoostModel extends DOMWidgetModel {

export class LegoBoostView extends DOMWidgetView {
txt_connected: HTMLDivElement;
txt_bluetooth: HTMLDivElement;

txt_pitch: HTMLDivElement;
txt_roll: HTMLDivElement;
Expand All @@ -249,9 +250,26 @@ export class LegoBoostView extends DOMWidgetView {
meter_distance: HTMLMeterElement;
color_color: HTMLDivElement;

isWebBluetoothSupported : boolean = navigator.bluetooth ? true : false;

render() {
this.el.classList.add('custom-widget');

// checking if Web Bluetooth API is supported
if (!this.isWebBluetoothSupported) {

// bluetooth error box
const bluetooth_box = document.createElement('div');
bluetooth_box.classList.add('error-box');
this.el.appendChild(bluetooth_box);

this.txt_bluetooth = document.createElement('div');
this.txt_bluetooth.textContent = "Your device doesn't support Web Bluetooth API. Try to turn on Experimental Platform Features from Chrome, by accessing the following link and turning it on: chrome://flags/#enable-experimental-web-platform-features";
bluetooth_box.appendChild(this.txt_bluetooth);

console.log( "Your device doesn't support Web Bluetooth API. Try to turn on Experimental Platform Features from Chrome, by accessing the following link and turning it on: chrome://flags/#enable-experimental-web-platform-features");
}

// connection box
const connection_box = document.createElement('div');
connection_box.classList.add('box');
Expand Down