feat: use modules for common utils
parent
d5d0146af7
commit
ef68bb170f
|
@ -319,6 +319,7 @@ function dist_rollup() {
|
|||
// I will be picked up by rollup and bundled accordingly.
|
||||
'components/init': 'src/components/init.js',
|
||||
'js/main_cordova': 'src/js/main_cordova.js',
|
||||
'js/utils/common': 'src/js/utils/common.js'
|
||||
},
|
||||
plugins: [
|
||||
alias({
|
||||
|
|
|
@ -86,10 +86,6 @@ function generateData(firmware, input, startAddress) {
|
|||
firmware.bytes_total += input.length;
|
||||
}
|
||||
|
||||
function microtime() {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
|
||||
ConfigInserter.prototype.insertConfig = function (firmware, input) {
|
||||
const timeParsingStart = microtime(); // track time
|
||||
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
'use strict';
|
||||
import semver from "semver";
|
||||
|
||||
function microtime() {
|
||||
export function microtime() {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
|
||||
function millitime() {
|
||||
export function millitime() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
const DEGREE_TO_RADIAN_RATIO = Math.PI / 180;
|
||||
|
||||
function degToRad(degrees) {
|
||||
export function degToRad(degrees) {
|
||||
return degrees * DEGREE_TO_RADIAN_RATIO;
|
||||
}
|
||||
|
||||
function bytesToSize(bytes) {
|
||||
|
||||
export function bytesToSize(bytes) {
|
||||
let outputBytes;
|
||||
|
||||
if (bytes < 1024) {
|
||||
|
@ -35,27 +34,33 @@ function bytesToSize(bytes) {
|
|||
* checkChromeRuntimeError() has to be called after each chrome API call
|
||||
*/
|
||||
|
||||
function checkChromeRuntimeError() {
|
||||
export function checkChromeRuntimeError() {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${(new Error).stack}`);
|
||||
console.error(
|
||||
`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${
|
||||
new Error().stack
|
||||
}`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const majorFirmwareVersions = {
|
||||
'1.43': '4.2.*',
|
||||
'1.42': '4.1.*',
|
||||
'1.41': '4.0.*',
|
||||
'1.40': '3.5.*',
|
||||
'1.39': '3.4.*',
|
||||
'1.37': '3.3.0',
|
||||
'1.36': '3.2.*',
|
||||
'1.31': '3.1.0',
|
||||
"1.43": "4.2.*",
|
||||
"1.42": "4.1.*",
|
||||
"1.41": "4.0.*",
|
||||
"1.40": "3.5.*",
|
||||
"1.39": "3.4.*",
|
||||
"1.37": "3.3.0",
|
||||
"1.36": "3.2.*",
|
||||
"1.31": "3.1.0"
|
||||
};
|
||||
|
||||
function generateVirtualApiVersions() {
|
||||
const firmwareVersionDropdown = document.getElementById('firmware-version-dropdown');
|
||||
export function generateVirtualApiVersions() {
|
||||
const firmwareVersionDropdown = document.getElementById(
|
||||
"firmware-version-dropdown"
|
||||
);
|
||||
const max = semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED);
|
||||
|
||||
for (let i = max; i > 0; i--) {
|
||||
|
@ -73,3 +78,10 @@ function generateVirtualApiVersions() {
|
|||
firmwareVersionDropdown.appendChild(option);
|
||||
}
|
||||
}
|
||||
|
||||
window.microtime = microtime;
|
||||
window.millitime = millitime;
|
||||
window.degToRad = degToRad;
|
||||
window.bytesToSize = bytesToSize;
|
||||
window.checkChromeRuntimeError = checkChromeRuntimeError;
|
||||
window.generateVirtualApiVersions = generateVirtualApiVersions;
|
||||
|
|
|
@ -93,10 +93,6 @@ function read_hex_file(data) {
|
|||
}
|
||||
}
|
||||
|
||||
function microtime() {
|
||||
return new Date().getTime() / 1000;
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
const timeParsingStart = microtime(); // track time
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
<link type="text/css" rel="stylesheet" href="./css/dark-theme.css" media="all" disabled/>
|
||||
|
||||
<script type="module" src="./components/init.js"></script>
|
||||
<!-- TODO: probably won't need this here once everything is imported -->
|
||||
<script type="module" src="./js/utils/common.js"></script>
|
||||
<!-- CORDOVA_INCLUDE js/cordova_chromeapi.js -->
|
||||
<!-- CORDOVA_INCLUDE js/cordova_startup.js -->
|
||||
<script type="text/javascript" src="./node_modules/lru_map/lru.js"></script>
|
||||
|
@ -70,7 +72,6 @@
|
|||
<script type="text/javascript" src="./js/libraries/jquery.ba-throttle-debounce.min.js"></script>
|
||||
<script type="text/javascript" src="./node_modules/inflection/inflection.min.js"></script>
|
||||
<script type="text/javascript" src="./js/libraries/analytics.js"></script>
|
||||
<script type="text/javascript" src="./js/utils/common.js"></script>
|
||||
<script type="text/javascript" src="./js/utils/css.js"></script>
|
||||
<script type="text/javascript" src="./js/utils/window_watchers.js"></script>
|
||||
<script type="text/javascript" src="./js/utils/CommonUtils.js"></script>
|
||||
|
|
Loading…
Reference in New Issue