diff --git a/gulpfile.js b/gulpfile.js index 3456a06f..55fe654f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -319,6 +319,8 @@ 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', + 'js/tabs/logging': 'src/js/tabs/logging.js' }, plugins: [ alias({ diff --git a/src/js/ConfigInserter.js b/src/js/ConfigInserter.js index 0a5b38a5..58e812e6 100644 --- a/src/js/ConfigInserter.js +++ b/src/js/ConfigInserter.js @@ -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 diff --git a/src/js/tabs/logging.js b/src/js/tabs/logging.js index d8fe3870..2fcc37ca 100644 --- a/src/js/tabs/logging.js +++ b/src/js/tabs/logging.js @@ -1,7 +1,7 @@ -'use strict'; +import { millitime } from '../utils/common.js'; -TABS.logging = {}; -TABS.logging.initialize = function (callback) { +const logging = {}; +logging.initialize = function (callback) { if (GUI.active_tab != 'logging') { GUI.active_tab = 'logging'; @@ -319,6 +319,9 @@ TABS.logging.initialize = function (callback) { } }; -TABS.logging.cleanup = function (callback) { +logging.cleanup = function (callback) { if (callback) callback(); }; + +// TODO: only for transition to modules, drop this eventually +window.TABS.logging = logging; diff --git a/src/js/utils/common.js b/src/js/utils/common.js index 96168256..006a0991 100644 --- a/src/js/utils/common.js +++ b/src/js/utils/common.js @@ -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); } } + +// TODO: these are temp binding while transition to module happens +window.microtime = microtime; +window.degToRad = degToRad; +window.bytesToSize = bytesToSize; +window.checkChromeRuntimeError = checkChromeRuntimeError; +window.generateVirtualApiVersions = generateVirtualApiVersions; diff --git a/src/js/workers/hex_parser.js b/src/js/workers/hex_parser.js index c8ccb4b3..0f946260 100644 --- a/src/js/workers/hex_parser.js +++ b/src/js/workers/hex_parser.js @@ -93,10 +93,6 @@ function read_hex_file(data) { } } -function microtime() { - return new Date().getTime() / 1000; -} - onmessage = function(event) { const timeParsingStart = microtime(); // track time diff --git a/src/main.html b/src/main.html index 4ed04ea7..14969b08 100644 --- a/src/main.html +++ b/src/main.html @@ -47,6 +47,8 @@ + + @@ -70,7 +72,6 @@ - @@ -127,7 +128,8 @@ - + +