Skip to content

Commit

Permalink
PWA notice for unsupported browser (betaflight#4120)
Browse files Browse the repository at this point in the history
* PWA notice for unsupported browser

* Upper case browser names

* Cleanup
  • Loading branch information
haslinghuis authored Aug 8, 2024
1 parent d649a9c commit 74e5a36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 0 additions & 1 deletion locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"message": "You need to refresh the page to get the latest changes. Refreshing it now will reload the page and you will lose any unsaved changes and will abort any operation in progress.<br><br>Do you want to refresh it now? You can also dismiss this message and refresh the page manually later.",
"description": "Text of the window that appears when the app needs to be refreshed to get the latest changes"
},

"pwaOnOffilenReadyTitle": {
"message": "The application is ready to be used offline",
"description": "Title of the window that appears when the app is ready to be installed and used offline"
Expand Down
33 changes: 33 additions & 0 deletions src/js/utils/checkBrowserCompatibilty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export function checkBrowserCompatibility() {
const compatible = "serial" in navigator;

if (!compatible) {
const errorMessage = "Betaflight app requires Chrome, Chromium, Edge or Vivaldi browser.";
const newDiv = document.createElement("div");

$('body')
.empty()
.css({
"height": "100%",
"display": "grid",
"background-image": "url(../images/osd-bg-1.jpg",
"background-size": "cover",
"background-repeat": "no-repeat",
})
.append(newDiv);

$('div')
.append(errorMessage)
.css({
"font-size": "16px",
"background-color": "var(--surface-200)",
"color": "var(--text)",
"padding": "1rem",
"margin": "auto",
"border-radius": "0.75rem",
"border": "2px solid var(--surface-500)",
});

throw new Error("No compatible browser found.");
}
}
4 changes: 4 additions & 0 deletions src/js/webSerial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { webSerialDevices, vendorIdNames } from "./serial_devices";
import { checkBrowserCompatibility } from "./utils/checkBrowserCompatibilty";

async function* streamAsyncIterable(reader, keepReadingFlag) {
try {
Expand All @@ -17,6 +18,9 @@ async function* streamAsyncIterable(reader, keepReadingFlag) {
class WebSerial extends EventTarget {
constructor() {
super();

checkBrowserCompatibility();

this.connected = false;
this.openRequested = false;
this.openCanceled = false;
Expand Down

0 comments on commit 74e5a36

Please sign in to comment.