1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 08:15:22 +03:00

Fix and add check for chrome.runtime.lastError

This commit is contained in:
Mark Haslinghuis 2020-12-18 22:10:25 +01:00
parent 0f8a2911d9
commit 431aa6bac8
13 changed files with 83 additions and 121 deletions

44
src/js/utils/common.js Normal file
View file

@ -0,0 +1,44 @@
'use strict';
function microtime() {
return new Date().getTime() / 1000;
}
function millitime() {
return new Date().getTime();
}
const DEGREE_TO_RADIAN_RATIO = Math.PI / 180;
function degToRad(degrees) {
return degrees * DEGREE_TO_RADIAN_RATIO;
}
function bytesToSize(bytes) {
let outputBytes;
if (bytes < 1024) {
outputBytes = `${bytes} Bytes`;
} else if (bytes < 1048576) {
outputBytes = `${(bytes / 1024).toFixed(3)} KB`;
} else if (bytes < 1073741824) {
outputBytes = `${(bytes / 1048576).toFixed(3)} MB`;
} else {
outputBytes = `${(bytes / 1073741824).toFixed(3)} GB`;
}
return outputBytes;
}
/*
* checkChromeRuntimeError() has to be called after each chrome API call
*/
function checkChromeRuntimeError() {
if (chrome.runtime.lastError) {
console.error(`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${(new Error).stack}`);
return true;
}
return false;
}