diff --git a/.gitignore b/.gitignore index 875f3c012..0fba08d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ npm-debug.log npm-debug.log inav-configurator.iml /out +/.vite .eslintrc.json /.project /cache/ @@ -16,4 +17,4 @@ inav-configurator.iml *.swp *.bak eeprom.bin -yarn.lock \ No newline at end of file +yarn.lock diff --git a/.vscode/launch.json b/.vscode/launch.json index f8efa898f..9b30c7adf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,8 @@ "args": ["--inspect"], "env": { "NODE_ENV": "development", - "NODE_PATH": "${workspaceFolder}/js/" + "NODE_PATH": "${workspaceFolder}/js/", + "DEV_TOOLS_MODE": "undocked" // left, right, bottom, undocked, detach }, "cwd": "${workspaceFolder}", "console": "integratedTerminal" diff --git a/README.md b/README.md index da656326f..f4b93662a 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,8 @@ sudo mv inav-configurator.desktop /usr/share/applications/ For local development, the **node.js** build system is used. 1. Install node.js -1. From the project folder run `yarn install` and then `npm install` -1. To build the and start the configurator: +1. From the project folder run `npm install` and then `npm install` +1. To build the and start the configurator: - Run `npm start`. To build the App run `npm run make` to build for your platform. @@ -114,7 +114,9 @@ To be able to open Inspector, set environment variable `NODE_ENV` to `developmen ```NODE_ENV=development npm start``` or ```$env:NODE_ENV="development" | npm start``` for Windows PowerShell -Or use vscode and start a debug session `Debug Configurator` (Just hit F5!) +Or use VScode and start a debug session `Debug Configurator` (Just hit F5!) + +To debug the main thread (source files in `js/main`), just set a breakpoint in VScode. ## Different map providers diff --git a/forge.config.js b/forge.config.js index 223287f53..f143c35ec 100644 --- a/forge.config.js +++ b/forge.config.js @@ -1,24 +1,47 @@ -const path = require('path'); -const fs = require('fs'); +import path from 'node:path'; +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; -module.exports = { +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +export default { packagerConfig: { executableName: "inav-configurator", asar: false, icon: 'images/inav', - ignore: [ - "^(\/\.vscode$)", - "^(\/support$)", - ".gitattributes", - ".gitignore", - "3D_model_creation.md", - "LICENSE", - "MAPPROXY.md", - "package-lock.json", - "README.md", - "inav_icon_128.psd", - ] }, + rebuildConfig: {}, + plugins: [ + { + name: '@electron-forge/plugin-vite', + config: { + build: [ + { + entry: 'js/main/main.js', + config: 'vite.main.config.js', + }, + { + entry: 'js/main/preload.js', + config: 'vite.preload.config.js', + }, + { + entry: 'js/libraries/bluetooth-device-chooser/bt-device-chooser-preload.js', + config: 'vite.preload.config.js', + }, + ], + renderer: [ + { + name: 'bt_device_chooser', + config: 'vite.bt-dc-renderer.config.js', + }, + { + name: 'main_window', + config: 'vite.main-renderer.config.js', + }, + ], + }, + }, + ], hooks: { // Uniform artifact file names postMake: async (config, makeResults) => { @@ -31,9 +54,8 @@ module.exports = { console.log('Artifact: ' + newPath); }); }); - } + }, }, - rebuildConfig: {}, makers: [ { name: '@electron-forge/maker-wix', @@ -48,7 +70,7 @@ module.exports = { appUserModelId: "com.inav.configurator", icon: path.join(__dirname, "./assets/windows/inav_installer_icon.ico"), upgradeCode: "13606ff3-b0bc-4dde-8fac-805bc8aed2f8", - ui : { + ui: { enabled: false, chooseDirectory: true, images: { diff --git a/images/flightindicators/altitude_pressure.svg b/images/flightindicators/fi_altitude_pressure.svg similarity index 100% rename from images/flightindicators/altitude_pressure.svg rename to images/flightindicators/fi_altitude_pressure.svg diff --git a/images/flightindicators/altitude_ticks.svg b/images/flightindicators/fi_altitude_ticks.svg similarity index 100% rename from images/flightindicators/altitude_ticks.svg rename to images/flightindicators/fi_altitude_ticks.svg diff --git a/images/flightindicators/fi_box.svg b/images/flightindicators/fi_fi_box.svg similarity index 100% rename from images/flightindicators/fi_box.svg rename to images/flightindicators/fi_fi_box.svg diff --git a/images/flightindicators/fi_circle.svg b/images/flightindicators/fi_fi_circle.svg similarity index 100% rename from images/flightindicators/fi_circle.svg rename to images/flightindicators/fi_fi_circle.svg diff --git a/images/flightindicators/fi_needle.svg b/images/flightindicators/fi_fi_needle.svg similarity index 100% rename from images/flightindicators/fi_needle.svg rename to images/flightindicators/fi_fi_needle.svg diff --git a/images/flightindicators/fi_needle_small.svg b/images/flightindicators/fi_fi_needle_small.svg similarity index 100% rename from images/flightindicators/fi_needle_small.svg rename to images/flightindicators/fi_fi_needle_small.svg diff --git a/images/flightindicators/fi_tc_airplane.svg b/images/flightindicators/fi_fi_tc_airplane.svg similarity index 100% rename from images/flightindicators/fi_tc_airplane.svg rename to images/flightindicators/fi_fi_tc_airplane.svg diff --git a/images/flightindicators/heading_mechanics.svg b/images/flightindicators/fi_heading_mechanics.svg similarity index 100% rename from images/flightindicators/heading_mechanics.svg rename to images/flightindicators/fi_heading_mechanics.svg diff --git a/images/flightindicators/heading_yaw.svg b/images/flightindicators/fi_heading_yaw.svg similarity index 100% rename from images/flightindicators/heading_yaw.svg rename to images/flightindicators/fi_heading_yaw.svg diff --git a/images/flightindicators/horizon_back.svg b/images/flightindicators/fi_horizon_back.svg similarity index 100% rename from images/flightindicators/horizon_back.svg rename to images/flightindicators/fi_horizon_back.svg diff --git a/images/flightindicators/horizon_ball.svg b/images/flightindicators/fi_horizon_ball.svg similarity index 100% rename from images/flightindicators/horizon_ball.svg rename to images/flightindicators/fi_horizon_ball.svg diff --git a/images/flightindicators/horizon_circle.svg b/images/flightindicators/fi_horizon_circle.svg similarity index 100% rename from images/flightindicators/horizon_circle.svg rename to images/flightindicators/fi_horizon_circle.svg diff --git a/images/flightindicators/horizon_mechanics.svg b/images/flightindicators/fi_horizon_mechanics.svg similarity index 100% rename from images/flightindicators/horizon_mechanics.svg rename to images/flightindicators/fi_horizon_mechanics.svg diff --git a/images/flightindicators/speed_mechanics.svg b/images/flightindicators/fi_speed_mechanics.svg similarity index 100% rename from images/flightindicators/speed_mechanics.svg rename to images/flightindicators/fi_speed_mechanics.svg diff --git a/images/flightindicators/turn_coordinator.svg b/images/flightindicators/fi_turn_coordinator.svg similarity index 100% rename from images/flightindicators/turn_coordinator.svg rename to images/flightindicators/fi_turn_coordinator.svg diff --git a/images/flightindicators/vertical_mechanics.svg b/images/flightindicators/fi_vertical_mechanics.svg similarity index 100% rename from images/flightindicators/vertical_mechanics.svg rename to images/flightindicators/fi_vertical_mechanics.svg diff --git a/images/icons/cf_icon_RTH.png b/images/icons/map/cf_icon_RTH.png similarity index 100% rename from images/icons/cf_icon_RTH.png rename to images/icons/map/cf_icon_RTH.png diff --git a/images/icons/cf_icon_arrow.png b/images/icons/map/cf_icon_arrow.png similarity index 100% rename from images/icons/cf_icon_arrow.png rename to images/icons/map/cf_icon_arrow.png diff --git a/images/icons/cf_icon_elevation_white.svg b/images/icons/map/cf_icon_elevation_white.svg similarity index 100% rename from images/icons/cf_icon_elevation_white.svg rename to images/icons/map/cf_icon_elevation_white.svg diff --git a/images/icons/cf_icon_geozone_excl.png b/images/icons/map/cf_icon_geozone_excl.png old mode 100755 new mode 100644 similarity index 100% rename from images/icons/cf_icon_geozone_excl.png rename to images/icons/map/cf_icon_geozone_excl.png diff --git a/images/icons/cf_icon_geozone_incl.png b/images/icons/map/cf_icon_geozone_incl.png old mode 100755 new mode 100644 similarity index 100% rename from images/icons/cf_icon_geozone_incl.png rename to images/icons/map/cf_icon_geozone_incl.png diff --git a/images/icons/cf_icon_geozone_white.svg b/images/icons/map/cf_icon_geozone_white.svg old mode 100755 new mode 100644 similarity index 100% rename from images/icons/cf_icon_geozone_white.svg rename to images/icons/map/cf_icon_geozone_white.svg diff --git a/images/icons/cf_icon_home.png b/images/icons/map/cf_icon_home.png similarity index 100% rename from images/icons/cf_icon_home.png rename to images/icons/map/cf_icon_home.png diff --git a/images/icons/icon_mission_airplane.png b/images/icons/map/cf_icon_mission_airplane.png similarity index 100% rename from images/icons/icon_mission_airplane.png rename to images/icons/map/cf_icon_mission_airplane.png diff --git a/images/icons/map/cf_icon_multimission_white.svg b/images/icons/map/cf_icon_multimission_white.svg new file mode 100644 index 000000000..2ea81e957 --- /dev/null +++ b/images/icons/map/cf_icon_multimission_white.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + diff --git a/images/icons/cf_icon_position.png b/images/icons/map/cf_icon_position.png similarity index 64% rename from images/icons/cf_icon_position.png rename to images/icons/map/cf_icon_position.png index b90f80e1c..55d48622d 100644 Binary files a/images/icons/cf_icon_position.png and b/images/icons/map/cf_icon_position.png differ diff --git a/images/icons/cf_icon_position_LDG.png b/images/icons/map/cf_icon_position_LDG.png similarity index 100% rename from images/icons/cf_icon_position_LDG.png rename to images/icons/map/cf_icon_position_LDG.png diff --git a/images/icons/cf_icon_position_LDG_edit.png b/images/icons/map/cf_icon_position_LDG_edit.png similarity index 100% rename from images/icons/cf_icon_position_LDG_edit.png rename to images/icons/map/cf_icon_position_LDG_edit.png diff --git a/images/icons/cf_icon_position_PH.png b/images/icons/map/cf_icon_position_PH.png similarity index 100% rename from images/icons/cf_icon_position_PH.png rename to images/icons/map/cf_icon_position_PH.png diff --git a/images/icons/cf_icon_position_PH_edit.png b/images/icons/map/cf_icon_position_PH_edit.png similarity index 100% rename from images/icons/cf_icon_position_PH_edit.png rename to images/icons/map/cf_icon_position_PH_edit.png diff --git a/images/icons/cf_icon_position_POI.png b/images/icons/map/cf_icon_position_POI.png similarity index 100% rename from images/icons/cf_icon_position_POI.png rename to images/icons/map/cf_icon_position_POI.png diff --git a/images/icons/cf_icon_position_POI_edit.png b/images/icons/map/cf_icon_position_POI_edit.png similarity index 100% rename from images/icons/cf_icon_position_POI_edit.png rename to images/icons/map/cf_icon_position_POI_edit.png diff --git a/images/icons/cf_icon_position_WP.png b/images/icons/map/cf_icon_position_WP.png similarity index 100% rename from images/icons/cf_icon_position_WP.png rename to images/icons/map/cf_icon_position_WP.png diff --git a/images/icons/cf_icon_position_WP_edit.png b/images/icons/map/cf_icon_position_WP_edit.png similarity index 100% rename from images/icons/cf_icon_position_WP_edit.png rename to images/icons/map/cf_icon_position_WP_edit.png diff --git a/images/icons/cf_icon_position_edit.png b/images/icons/map/cf_icon_position_edit.png similarity index 100% rename from images/icons/cf_icon_position_edit.png rename to images/icons/map/cf_icon_position_edit.png diff --git a/images/icons/cf_icon_position_head.png b/images/icons/map/cf_icon_position_head.png similarity index 100% rename from images/icons/cf_icon_position_head.png rename to images/icons/map/cf_icon_position_head.png diff --git a/images/icons/cf_icon_safehome.png b/images/icons/map/cf_icon_safehome.png similarity index 100% rename from images/icons/cf_icon_safehome.png rename to images/icons/map/cf_icon_safehome.png diff --git a/images/icons/cf_icon_safehome_used.png b/images/icons/map/cf_icon_safehome_used.png similarity index 100% rename from images/icons/cf_icon_safehome_used.png rename to images/icons/map/cf_icon_safehome_used.png diff --git a/images/icons/cf_icon_safehome_white.svg b/images/icons/map/cf_icon_safehome_white.svg similarity index 100% rename from images/icons/cf_icon_safehome_white.svg rename to images/icons/map/cf_icon_safehome_white.svg diff --git a/images/icons/map/cf_settings_white.svg b/images/icons/map/cf_settings_white.svg new file mode 100644 index 000000000..58d66d1dd --- /dev/null +++ b/images/icons/map/cf_settings_white.svg @@ -0,0 +1,22 @@ + + + +CF_Settings_Icon + + + + + + + diff --git a/index.html b/index.html index d7681ca2d..062b6f579 100644 --- a/index.html +++ b/index.html @@ -3,12 +3,6 @@ - - - - - - INAV Configurator @@ -82,7 +76,7 @@

- + @@ -169,9 +163,9 @@

-
-
-
+
+
+
@@ -382,6 +376,7 @@

+ \ No newline at end of file diff --git a/js/CliAutoComplete.js b/js/CliAutoComplete.js index 99139f2fe..82042279c 100644 --- a/js/CliAutoComplete.js +++ b/js/CliAutoComplete.js @@ -5,9 +5,10 @@ * Check out the docs at https://github.com/yuku/jquery-textcomplete/tree/v1/doc */ -const FC = require('./fc') -const CONFIGURATOR = require('./data_storage'); -const timeout = require('./timeouts'); +import 'jquery-textcomplete'; +import FC from './fc'; +import CONFIGURATOR from './data_storage'; +import timeout from './timeouts'; const CliAutoComplete = { configEnabled: false, @@ -558,4 +559,4 @@ CliAutoComplete._initTextcomplete = function() { ]); }; -module.exports = CliAutoComplete; +export default CliAutoComplete; diff --git a/js/appUpdater.js b/js/appUpdater.js index 58eb8af07..4170674ec 100644 --- a/js/appUpdater.js +++ b/js/appUpdater.js @@ -1,10 +1,10 @@ 'use strict'; -const semver = require('semver'); +import semver from 'semver'; -const { GUI } = require('./gui'); -const jBox = require('./libraries/jBox/jBox.min'); -const i18n = require('./localization'); +import { GUI } from './gui'; +import jBox from 'jbox'; +import i18n from './localization'; var appUpdater = appUpdater || {}; @@ -17,18 +17,21 @@ appUpdater.checkRelease = function (currVersion) { let newPrerelase = releaseData.prerelease; if (newPrerelase == false && semver.gt(newVersion, currVersion)) { - GUI.log(newVersion, app.getVersion()); - GUI.log(currVersion); - - GUI.log(i18n.getMessage('newVersionAvailable')); - modalStart = new jBox('Modal', { - width: 400, - height: 200, - animation: false, - closeOnClick: false, - closeOnEsc: true, - content: $('#appUpdateNotification') - }).open(); + + window.electronAPI.appGetVersion().then(currentVersion => { + GUI.log(newVersion, currentVersion); + GUI.log(currVersion); + + GUI.log(i18n.getMessage('newVersionAvailable')); + modalStart = new jBox('Modal', { + width: 400, + height: 200, + animation: false, + closeOnClick: false, + closeOnEsc: true, + content: $('#appUpdateNotification') + }).open(); + }); } }); @@ -40,4 +43,4 @@ appUpdater.checkRelease = function (currVersion) { }); }; -module.exports = appUpdater; +export default appUpdater; diff --git a/js/bitHelper.js b/js/bitHelper.js index bee166d4a..7903c6fce 100644 --- a/js/bitHelper.js +++ b/js/bitHelper.js @@ -31,4 +31,4 @@ var BitHelper = function() { return self; }(); -module.exports = BitHelper; \ No newline at end of file +export default BitHelper; \ No newline at end of file diff --git a/js/boards.js b/js/boards.js index 6ebe805b8..b2ef2b7e5 100644 --- a/js/boards.js +++ b/js/boards.js @@ -60,5 +60,5 @@ BOARD.findDefinition = function (identifier) { return DEFAULT_BOARD_DEFINITION; }; -module.exports = BOARD; +export default BOARD; diff --git a/js/configurator_main.js b/js/configurator_main.js index fa25c9a72..5c0a71087 100644 --- a/js/configurator_main.js +++ b/js/configurator_main.js @@ -1,42 +1,28 @@ -window.$ = window.jQuery = require('jquery'), - require('jquery-ui-dist/jquery-ui'), - require('jquery-textcomplete'), - require('./libraries/jquery.flightindicators'), - require('./libraries/jquery.nouislider.all.min'), - require('./libraries/jquery.ba-throttle-debounce'); - -const { app } = require('@electron/remote'); -const d3 = require('./libraries/d3.min'); -const Store = require('electron-store'); -const store = new Store(); - -const { GUI, TABS } = require('./gui'); -const CONFIGURATOR = require('./data_storage'); -const FC = require('./fc'); -const { globalSettings, UnitType } = require('./globalSettings'); -const { PLATFORM } = require('./model') -const i18n = require('./localization'); -const SerialBackend = require('./serial_backend'); -const MSP = require('./msp'); -const MSPCodes = require('./../js/msp/MSPCodes'); -const mspHelper = require('./msp/MSPHelper'); -const update = require('./globalUpdates'); -const appUpdater = require('./appUpdater'); -const CliAutoComplete = require('./CliAutoComplete'); -const { SITLProcess } = require('./sitl'); -const settingsCache = require('./settingsCache'); - -process.on('uncaughtException', function (error) { - if (process.env.NODE_ENV !== 'development') { - GUI.log(i18n.getMessage('unexpectedError', error.message)); - if (GUI.connected_to || GUI.connecting_to) { - GUI.log(i18n.getMessage('disconnecting')); - $('a.connect').trigger('click'); - } - } else { - throw error; - } -}); +import '../src/css/styles.css' + +import $ from 'jquery'; +import 'jquery-ui-dist/jquery-ui'; +import * as THREE from 'three' + +import { GUI, TABS } from './gui'; +import CONFIGURATOR from './data_storage'; +import FC from './fc'; +import { globalSettings, UnitType } from './globalSettings'; +import { PLATFORM } from './model' +import i18n from './localization'; +import SerialBackend from './serial_backend'; +import MSP from './msp'; +import MSPCodes from './../js/msp/MSPCodes'; +import mspHelper from './msp/MSPHelper'; +import update from './globalUpdates'; +import appUpdater from './appUpdater'; +import CliAutoComplete from './CliAutoComplete'; +import { SITLProcess } from './sitl'; +import settingsCache from './settingsCache'; +import store from './store'; + + +window.$ = $; // Set how the units render on the configurator only $(function() { @@ -78,7 +64,6 @@ $(function() { $('a', activeTab).trigger('click'); } - globalSettings.store = store; globalSettings.unitType = store.get('unit_type', UnitType.none); globalSettings.mapProviderType = store.get('map_provider_type', 'osm'); globalSettings.mapApiKey = store.get('map_api_key', ''); @@ -100,13 +85,14 @@ $(function() { globalSettings.osdUnits = null; } + const version = window.electronAPI.appGetVersion(); // alternative - window.navigator.appVersion.match(/Chrome\/([0-9.]*)/)[1]; GUI.log(i18n.getMessage('getRunningOS') + GUI.operating_system + ', ' + - 'Chrome: ' + process.versions['chrome'] + ', ' + - i18n.getMessage('getConfiguratorVersion') + app.getVersion() + ''); + 'Electron: ' + navigator.userAgent.match(/Electron\/([\d\.]+\d+)/)[1] + ', ' + + i18n.getMessage('getConfiguratorVersion') + version + ''); - $('#status-bar .version').text(app.getVersion()); - $('#logo .version').text(app.getVersion()); + $('#status-bar .version').text(version); + $('#logo .version').text(version); update.firmwareVersion(); if (store.get('logopen', false)) { @@ -114,11 +100,12 @@ $(function() { } if (store.get('update_notify', true)) { - appUpdater.checkRelease(app.getVersion()); + appUpdater.checkRelease(version); } + // log library versions in console to make version tracking easier - console.log('Libraries: jQuery - ' + $.fn.jquery + ', d3 - ' + d3.version + ', three.js - ' + THREE.REVISION); + console.log('Libraries: jQuery - ' + $.fn.jquery + ', three.js - ' + THREE.REVISION); // Tabs var ui_tabs = $('#tabs > ul'); @@ -178,108 +165,79 @@ $(function() { switch (tab) { case 'landing': - require('./../tabs/landing') - TABS.landing.initialize(content_ready); + import('./../tabs/landing').then(() => TABS.landing.initialize(content_ready)); break; case 'firmware_flasher': - require('./../tabs/firmware_flasher') - TABS.firmware_flasher.initialize(content_ready); + import('./../tabs/firmware_flasher').then(() => TABS.firmware_flasher.initialize(content_ready)); break; case 'sitl': - require('./../tabs/sitl') - TABS.sitl.initialize(content_ready); + import('./../tabs/sitl').then(() => TABS.sitl.initialize(content_ready)); break; case 'auxiliary': - require('./../tabs/auxiliary') - TABS.auxiliary.initialize(content_ready); + import('./../tabs/auxiliary').then(() => TABS.auxiliary.initialize(content_ready)); break; case 'adjustments': - require('./../tabs/adjustments') - TABS.adjustments.initialize(content_ready); + import('./../tabs/adjustments').then(() => TABS.adjustments.initialize(content_ready)); break; case 'ports': - require('./../tabs/ports'); - TABS.ports.initialize(content_ready); + import('./../tabs/ports').then(() => TABS.ports.initialize(content_ready)); break; case 'led_strip': - require('./../tabs/led_strip'); - TABS.led_strip.initialize(content_ready); + import('./../tabs/led_strip').then(() => TABS.led_strip.initialize(content_ready)); break; case 'failsafe': - require('./../tabs/failsafe'); - TABS.failsafe.initialize(content_ready); + import('./../tabs/failsafe').then(() => TABS.failsafe.initialize(content_ready)); break; case 'setup': - require('./../tabs/setup'); - TABS.setup.initialize(content_ready); + import('./../tabs/setup').then(() => TABS.setup.initialize(content_ready)); break; case 'calibration': - require('./../tabs/calibration'); - TABS.calibration.initialize(content_ready); + import('./../tabs/calibration').then(() => TABS.calibration.initialize(content_ready)); break; case 'configuration': - require('./../tabs/configuration'); - TABS.configuration.initialize(content_ready); + import('./../tabs/configuration').then(() => TABS.configuration.initialize(content_ready)); break; case 'pid_tuning': - require('./../tabs/pid_tuning'); - TABS.pid_tuning.initialize(content_ready); + import('./../tabs/pid_tuning').then(() => TABS.pid_tuning.initialize(content_ready)); break; case 'receiver': - require('./../tabs/receiver'); - TABS.receiver.initialize(content_ready); + import('./../tabs/receiver').then(() => TABS.receiver.initialize(content_ready)); break; case 'gps': - require('./../tabs/gps'); - TABS.gps.initialize(content_ready); + import('./../tabs/gps').then(() => TABS.gps.initialize(content_ready)); break; case 'magnetometer': - require('./../tabs/magnetometer'); - TABS.magnetometer.initialize(content_ready); + import('./../tabs/magnetometer').then(() => TABS.magnetometer.initialize(content_ready)); break; case 'mission_control': - require('./../tabs/mission_control'); - TABS.mission_control.initialize(content_ready); + import('./../tabs/mission_control').then(() => TABS.mission_control.initialize(content_ready)); break; case 'mixer': - require('./../tabs/mixer'); - TABS.mixer.initialize(content_ready); + import('./../tabs/mixer').then(() => TABS.mixer.initialize(content_ready)); break; case 'outputs': - require('./../tabs/outputs'); - TABS.outputs.initialize(content_ready); + import('./../tabs/outputs').then(() => TABS.outputs.initialize(content_ready)); break; case 'osd': - require('./../tabs/osd'); - TABS.osd.initialize(content_ready); + import('./../tabs/osd').then(() => TABS.osd.initialize(content_ready)); break; case 'sensors': - require('./../tabs/sensors'); - TABS.sensors.initialize(content_ready); + import('./../tabs/sensors').then(() => TABS.sensors.initialize(content_ready)); break; case 'logging': - require('./../tabs/logging'); - TABS.logging.initialize(content_ready); + import('./../tabs/logging').then(() => TABS.logging.initialize(content_ready)); break; case 'onboard_logging': - require('./../tabs/onboard_logging'); - TABS.onboard_logging.initialize(content_ready); + import('./../tabs/onboard_logging').then(() => TABS.onboard_logging.initialize(content_ready)); break; case 'advanced_tuning': - require('./../tabs/advanced_tuning'); - TABS.advanced_tuning.initialize(content_ready); + import('./../tabs/advanced_tuning').then(() => TABS.advanced_tuning.initialize(content_ready)); break; case 'programming': - require('./../tabs/programming'); - TABS.programming.initialize(content_ready); + import('./../tabs/programming').then(() => TABS.programming.initialize(content_ready)); break; case 'cli': - require('./../tabs/cli'); - TABS.cli.initialize(content_ready); - break; - case 'ez_tune': - require('./../tabs/ez_tune'); - TABS.ez_tune.initialize(content_ready); + import('./../tabs/cli').then(() => TABS.cli.initialize(content_ready)); break; default: console.log('Tab not found:' + tab); @@ -290,16 +248,25 @@ $(function() { $('#tabs ul.mode-disconnected li a:first').trigger( "click" ); + + // options $('#options').on('click', function() { var el = $(this); + function closeOptions() { + $('div#options-window').slideUp(250, function () { + el.removeClass('active'); + $(this).empty().remove(); + }); + } + if (!el.hasClass('active')) { el.addClass('active'); el.after('
'); - $('div#options-window').load('./tabs/options.html', function () { - + import('./../tabs/options.html?raw').then(({default: html}) => { + $('div#options-window').html(html); // translate to user-selected language i18n.localize(); @@ -350,7 +317,9 @@ $(function() { $('#languageOption').append("".format(lng, i18n.getMessage("language_" + lng))); }); + $('#languageOption').val(i18n.getCurrentLanguage()); + $('#languageOption').on('change', () => { i18n.changeLanguage($('#languageOption').val()); }); @@ -399,21 +368,17 @@ $(function() { $('#maintenanceFlushSettingsCache').on('click', function () { settingsCache.flush(); }); - function close_and_cleanup(e) { - if (e.type == 'click' && !$.contains($('div#options-window')[0], e.target) || e.type == 'keyup' && e.keyCode == 27) { - $(document).unbind('click keyup', close_and_cleanup); - - $('div#options-window').slideUp(250, function () { - el.removeClass('active'); - $(this).empty().remove(); - }); - } - } - - $(document).bind('click keyup', close_and_cleanup); - $(this).slideDown(250); + $('#optionsClose').on('click', () => { + if ($('#options').hasClass('active')) { + closeOptions(); + } + }) + + $('div#options-window').slideDown(250); }); + } else { + closeOptions(); } }); diff --git a/js/connection/connection.js b/js/connection/connection.js index cffaf41c9..6babf8a72 100644 --- a/js/connection/connection.js +++ b/js/connection/connection.js @@ -1,6 +1,6 @@ 'use strict'; -const { GUI } = require('./../gui'); +import { GUI } from './../gui'; const ConnectionType = { Serial: 0, @@ -263,4 +263,4 @@ class Connection { } } -module.exports = { ConnectionType, Connection}; \ No newline at end of file +export { ConnectionType, Connection}; \ No newline at end of file diff --git a/js/connection/connectionBle.js b/js/connection/connectionBle.js index eb69923ce..14dffbab4 100644 --- a/js/connection/connectionBle.js +++ b/js/connection/connectionBle.js @@ -1,9 +1,9 @@ 'use strict' -const { GUI } = require('./../gui'); +import { GUI } from './../gui'; -const { ConnectionType, Connection } = require('./connection'); -const i18n = require('./../localization'); +import { ConnectionType, Connection } from './connection'; +import i18n from './../localization'; // BLE 20 bytes buffer const BLE_WRITE_BUFFER_LENGTH = 20; @@ -266,4 +266,4 @@ class ConnectionBle extends Connection { } } -module.exports = ConnectionBle; +export default ConnectionBle; diff --git a/js/connection/connectionFactory.js b/js/connection/connectionFactory.js index d68d732ba..0bcc3da22 100644 --- a/js/connection/connectionFactory.js +++ b/js/connection/connectionFactory.js @@ -1,10 +1,10 @@ 'use strict' -const { ConnectionType } = require('./connection'); -const ConnectionBle = require('./connectionBle'); -const ConnectionSerial = require('./connectionSerial'); -const ConnectionTcp = require('./connectionTcp'); -const ConnectionUdp = require('./connectionUdp'); +import { ConnectionType } from './connection'; +import ConnectionBle from './connectionBle'; +import ConnectionSerial from './connectionSerial'; +import ConnectionTcp from './connectionTcp'; +import ConnectionUdp from './connectionUdp'; var connectionFactory = function(type, instance) { if (instance && (instance.type == type || instance.connectionId)){ @@ -29,4 +29,4 @@ var connectionFactory = function(type, instance) { return instance; }; -module.exports = connectionFactory; \ No newline at end of file +export default connectionFactory; \ No newline at end of file diff --git a/js/connection/connectionSerial.js b/js/connection/connectionSerial.js index 13033c8fb..61000e282 100644 --- a/js/connection/connectionSerial.js +++ b/js/connection/connectionSerial.js @@ -1,39 +1,31 @@ 'use strict' -const { GUI } = require('./../gui'); - -const { ConnectionType, Connection } = require('./connection') -const { SerialPort } = require('serialport'); -const { SerialPortStream } = require('@serialport/stream'); -const { autoDetect } = require('@serialport/bindings-cpp') -const binding = autoDetect(); +import { GUI } from './../gui'; +import { ConnectionType, Connection } from './connection'; +import i18n from './../localization'; + +const serialDevices = [ + { vendorId: 1027, productId: 24577 }, // FT232R USB UART + { vendorId: 1155, productId: 12886 }, // STM32 in HID mode + { vendorId: 1155, productId: 14158 }, // 0483:374e STM Electronics STLink Virtual COM Port (NUCLEO boards) + { vendorId: 1155, productId: 22336 }, // STM Electronics Virtual COM Port + { vendorId: 4292, productId: 60000 }, // CP210x + { vendorId: 4292, productId: 60001 }, // CP210x + { vendorId: 4292, productId: 60002 }, // CP210x + { vendorId: 11836, productId: 22336 }, // AT32 VCP + { vendorId: 12619, productId: 22336 }, // APM32 VCP +]; class ConnectionSerial extends Connection { constructor() { super(); - this._serialport = null; this._errorListeners = []; this._onReceiveListeners = []; this._onErrorListener = []; + this.ports = []; super._type = ConnectionType.Serial; - } - - connectImplementation(path, options, callback) { - try { - this._serialport = new SerialPortStream({binding, path: path, baudRate: options.bitrate, autoOpen: true}, () => { - if (callback) { - callback({ - connectionId: ++this._connectionId, - bitrate: options.bitrate - }); - } - }); - } catch (error) { - console.log(error); - callback(false); - } - this._serialport.on('data', buffer => { + window.electronAPI.onSerialData(buffer => { this._onReceiveListeners.forEach(listener => { listener({ connectionId: this._connectionId, @@ -42,42 +34,67 @@ class ConnectionSerial extends Connection { }); }); - this._serialport.on('close', error => { + window.electronAPI.serialClose(() => { + console.log("Serial conenection closed"); this.abort(); }); - this._serialport.on('error', error => { - this.abort(); - console.log("Serial error: " + error); + window.electronAPI.onSerialError(error => { + GUI.log(error); + console.log(error); + this.abort() + this._onReceiveErrorListeners.forEach(listener => { listener(error); }); }); } - disconnectImplementation(callback) { - if (this._serialport && this._serialport.isOpen) { - this._serialport.close(error => { - if (error) { - console.log("Unable to close serial: " + error) + connectImplementation(path, options, callback) { + + window.electronAPI.serialConnect(path, options).then(response => { + if (!response.error) { + GUI.log(i18n.getMessage('connectionConnected', [`${path} @ ${options.bitrate} baud`])); + this._connectionId = response.id; + if (callback) { + callback({ + bitrate: options.bitrate, + connectionId: this._connectionId + }); + } + } else { + console.log("Serial connection error: " + response.msg); + if (callback) { + callback(false); } - }); - } + } + }); + } - if (callback) { - callback(true); - } + disconnectImplementation(callback) { + if (this._connectionId) { + window.electronAPI.serialClose().then(response => { + var ok = true; + if (response.error) { + console.log("Unable to close serial: " + response.msg); + ok = false; + } + if (callback) { + callback(ok); + } + }); + } } - sendImplementation(data, callback) { - if (this._serialport && this._serialport.isOpen) { - this._serialport.write(Buffer.from(data), error => { + sendImplementation(data, callback) { + if (this._connectionId) { + window.electronAPI.serialSend(data).then(response => { var result = 0; - var sent = data.byteLength; - if (error) { + var sent = response.bytesWritten; + if (response.error) { + console.log("Serial write error: " + response.msg); result = 1; sent = 0; - console.log("Serial write error: " + error) } if (callback) { callback({ @@ -103,31 +120,11 @@ class ConnectionSerial extends Connection { removeOnReceiveErrorCallback(callback) { this._onReceiveErrorListeners = this._onReceiveErrorListeners.filter(listener => listener !== callback); - } + } - static async getDevices(callback) { - SerialPort.list().then((ports, error) => { - var devices = []; - if (error) { - GUI.log("Unable to list serial ports."); - } else { - ports.forEach(port => { - if (GUI.operating_system == 'Linux') { - /* Limit to: USB serial, RFCOMM (BT), 6 legacy devices */ - if (port.pnpId || - port.path.match(/rfcomm\d*/) || - port.path.match(/ttyS[0-5]$/)) { - devices.push(port.path); - } - } else { - devices.push(port.path); - } - }); - } - if (callback) - callback(devices); - }); + static async getDevices() { + return window.electronAPI.listSerialDevices(); } } -module.exports = ConnectionSerial; +export default ConnectionSerial; diff --git a/js/connection/connectionTcp.js b/js/connection/connectionTcp.js index f3e93336d..489a8b95e 100644 --- a/js/connection/connectionTcp.js +++ b/js/connection/connectionTcp.js @@ -1,24 +1,43 @@ 'use strict' -const net = require('net') - -const { GUI } = require('./../gui'); -const { ConnectionType, Connection } = require('./connection') -const i18n = require('./../localization'); +import { GUI } from './../gui'; +import { ConnectionType, Connection } from './connection'; +import i18n from './../localization'; const STANDARD_TCP_PORT = 5761; -class ConnectionTcp extends Connection { - +class ConnectionTcp extends Connection { constructor() { super(); - this._socket = null; this._connectionIP = ""; this.connectionPort = 0; this._onReceiveListeners = []; this._onErrorListener = []; super._type = ConnectionType.TCP; + + window.electronAPI.onTcpData(buffer => { + this._onReceiveListeners.forEach(listener => { + listener({ + connectionId: this._connectionId, + data: buffer + }); + }); + }); + + window.electronAPI.onTcpEnd(() => { + console.log("TCP Remote has closed the connection"); + this.abort(); + }); + + window.electronAPI.onTcpError(error => { + GUI.log(error); + console.log(error); + this.abort(); + this._onReceiveErrorListeners.forEach(listener => { + listener(error); + }); + }); } connectImplementation(address, options, callback) { @@ -31,80 +50,58 @@ class ConnectionTcp extends Connection { this._connectionPort = STANDARD_TCP_PORT; } - try { - this._socket = net.connect({ host: this._connectionIP, port: this._connectionPort }, () => { - this._socket.setNoDelay(true); + window.electronAPI.tcpConnect(this._connectionIP, this._connectionPort).then(response => { + if (!response.error) { GUI.log(i18n.getMessage('connectionConnected', ["tcp://" + this._connectionIP + ":" + this._connectionPort])); - + this._connectionId = response.id; if (callback) { callback({ bitrate: 115200, - connectionId: ++this._connectionId + connectionId: this._connectionId }); + } + } else { + console.log("TCP error " + response.errorMsg); + if (callback) { + callback(false); } - - }); - } catch (error) { - console.log(error); - callback(false); - } - - this._socket.on('data', buffer => { - this._onReceiveListeners.forEach(listener => { - listener({ - connectionId: this._connectionId, - data: buffer - }); - }); - }) - - this._socket.on('end', () => { - console.log("TCP Remote has closed the connection"); - if (this._socket) { - this.abort(); } }); - - this._socket.on('error', (error) => { - GUI.log(error); - console.log(error); - - if (this._socket) { - this.abort(); - } - this._onReceiveErrorListeners.forEach(listener => { - listener(error); - }); - }); } disconnectImplementation(callback) { - if (this._socket && !this._socket.destroyed) { - this._socket.end(); + if (this._connectionId) { + window.electronAPI.tcpClose(); } this._connectionIP = ""; this._connectionPort = 0; - this._socket = null; if (callback) { callback(true); } } - sendImplementation(data, callback) {; - if (this._socket && !this._socket.destroyed) { - this._socket.write(Buffer.from(data), () => { + sendImplementation(data, callback) { + if (this._connectionId) { + window.electronAPI.tcpSend(data).then(response => { + var result = 0; + var sent = response.bytesWritten; + if (response.error) { + console.log("Serial write error: " + response.msg); + result = 1; + sent = 0; + } if (callback) { callback({ - bytesSent: data.byteLength, - resultCode: 0 + bytesSent: sent, + resultCode: result }); } - }) + }); } - } + } addOnReceiveCallback(callback){ this._onReceiveErrorListeners.push(callback); @@ -123,4 +120,4 @@ class ConnectionTcp extends Connection { } } -module.exports = ConnectionTcp; +export default ConnectionTcp; diff --git a/js/connection/connectionUdp.js b/js/connection/connectionUdp.js index 946af7692..f38f545fd 100644 --- a/js/connection/connectionUdp.js +++ b/js/connection/connectionUdp.js @@ -1,13 +1,13 @@ 'use strict' -const { ConnectionType, Connection } = require('./connection') -const dgram = require('node:dgram'); -const socket = dgram.createSocket('udp4'); +import { ConnectionType, Connection } from './connection'; -const { GUI } = require('./../gui'); -const i18n = require('./../localization'); +import { GUI } from './../gui'; +import i18n from './../localization'; const STANDARD_UDP_PORT = 5761; + +//const socket = window.electronAPI.dgramCreateSocket('udp4'); class ConnectionUdp extends Connection { constructor() { @@ -18,6 +18,24 @@ class ConnectionUdp extends Connection { this._onReceiveListeners = []; this._onErrorListener = []; super._type = ConnectionType.UDP; + + window.electronAPI.onUdpMessage(message => { + this._onReceiveListeners.forEach(listener => { + listener({ + connectionId: this._connectionId, + data: message + }); + }); + }); + + window.electronAPI.onUdpError(error => { + GUI.log(error); + console.log(error); + this.abort(); + this._onReceiveErrorListeners.forEach(listener => { + listener(error); + }); + }); } connectImplementation(address, options, callback) { @@ -30,80 +48,59 @@ class ConnectionUdp extends Connection { this._connectionPort = STANDARD_UDP_PORT; } - try { - socket.bind(this._connectionPort, () => { + window.electronAPI.udpConnect(this._connectionIP, this._connectionPort).then(response => { + if (!response.error) { GUI.log(i18n.getMessage('connectionConnected', ["udp://" + this._connectionIP + ":" + this._connectionPort])); + this._connectionId = response.id; if (callback) { callback({ bitrate: 115200, - connectionId: ++this._connectionId + connectionId: this._connectionId }); + } + } else { + console.log("UDP error: " + response.msg); + if (callback) { + callback(false); } - - }); - } catch (error) { - console.log(error); - callback(false); - } - - socket.on('message', (msg, _rinfo) => { - this._onReceiveListeners.forEach(listener => { - listener({ - connectionId: ++this._connectionId, - data: msg - }); - }); - }) - - socket.on('error', (error) => { - GUI.log("UDP error: " + error); - console.log("UDP error: " + error); - this.abort(); - this._onReceiveErrorListeners.forEach(listener => { - listener(error); - }); + } }); } disconnectImplementation(callback) { - var ret = true; - try { - socket.disconnect(); - } catch (error) { - console.log("Disconecct error: " + error) - ret = false; - } - - this._connectionIP = ""; - this._connectionPort = 0; - - if (callback) { - callback(ret); - } + if (this._connectionId) { + window.electronAPI.udpClose().then(response => { + var ok = true; + if (response.error) { + console.log("Unable to close UDP: " + response.msg); + ok = false; + } + if (callback) { + callback(ok); + } + }); + } } - sendImplementation(data, callback) {; - - try { - socket.send(Buffer.from(data), this._connectionPort, this._connectionIP, (error) => { - var result = 0; - var sent = data.byteLength; - if (error) { - result = 1; - sent = 0; - console.log("Serial wrire error: " + error) - } - if (callback) { - callback({ - bytesSent: sent, - resultCode: result - }); - } - }); - } catch (error) { - console.log("UDP write error: " + error) + sendImplementation(data, callback) { + if (this._connectionId) { + window.electronAPI.udpSend(data).then(response => { + var result = 0; + var sent = response.bytesWritten; + if (response.error) { + console.log("Serial write error: " + response.msg); + result = 1; + sent = 0; + } + if (callback) { + callback({ + bytesSent: sent, + resultCode: result + }); + } + }); + } } - } addOnReceiveCallback(callback){ this._onReceiveErrorListeners.push(callback); @@ -122,4 +119,4 @@ class ConnectionUdp extends Connection { } } -module.exports = ConnectionUdp; +export default ConnectionUdp; diff --git a/js/data_storage.js b/js/data_storage.js index a31d94e75..dbc1c3d03 100755 --- a/js/data_storage.js +++ b/js/data_storage.js @@ -11,4 +11,4 @@ var CONFIGURATOR = { 'connection': false }; -module.exports = CONFIGURATOR; +export default CONFIGURATOR; diff --git a/js/defaults_dialog.js b/js/defaults_dialog.js index 0c16814c3..7bbad14ab 100644 --- a/js/defaults_dialog.js +++ b/js/defaults_dialog.js @@ -1,20 +1,20 @@ 'use strict'; -const { GUI } = require('./../js/gui'); -const FC = require('./fc'); -const MSP = require('./msp'); -const MSPCodes = require('./../js/msp/MSPCodes'); -const mspHelper = require('./msp/MSPHelper'); -const MSPChainerClass = require('./msp/MSPchainer'); -const features = require('./feature_framework'); -const periodicStatusUpdater = require('./periodicStatusUpdater'); -const { mixer } = require('./model'); -const jBox = require('./libraries/jBox/jBox.min'); -const i18n = require('./localization'); -const defaultsDialogData = require('./defaults_dialog_entries.js'); -const Settings = require('./settings.js'); -const wizardUiBindings = require('./wizard_ui_bindings'); -const wizardSaveFramework = require('./wizard_save_framework'); +import { GUI } from './../js/gui'; +import FC from './fc'; +import MSP from './msp'; +import MSPCodes from './../js/msp/MSPCodes'; +import mspHelper from './msp/MSPHelper'; +import MSPChainerClass from './msp/MSPchainer'; +import features from './feature_framework'; +import periodicStatusUpdater from './periodicStatusUpdater'; +import { mixer } from './model'; +import jBox from 'jbox'; +import i18n from './localization'; +import defaultsDialogData from './defaults_dialog_entries.js'; +import Settings from './settings.js'; +import wizardUiBindings from './wizard_ui_bindings'; +import wizardSaveFramework from './wizard_save_framework'; var savingDefaultsModal; @@ -118,11 +118,11 @@ var defaultsDialog = (function () { $content.unbind(); - $.get("./wizard/" + stepName + ".html", function (data) { + import(`./../wizard/step-${stepName}.html?raw`).then(({default: data}) => { $content.html(""); $(data).appendTo($content); - $.get("./wizard/buttons.html", function (data) { + import('./../wizard/step-buttons.html?raw').then(({default: data}) => { $(data).appendTo($content); $content.on('click', '#wizard-next', function () { @@ -346,4 +346,4 @@ var defaultsDialog = (function () { return publicScope; })(); -module.exports = defaultsDialog; +export default defaultsDialog; diff --git a/js/defaults_dialog_entries.js b/js/defaults_dialog_entries.js index 75ac15e67..88addbad0 100644 --- a/js/defaults_dialog_entries.js +++ b/js/defaults_dialog_entries.js @@ -874,4 +874,4 @@ var defaultsDialogData = [ } ]; -module.exports = defaultsDialogData; \ No newline at end of file +export default defaultsDialogData; \ No newline at end of file diff --git a/js/dialog.js b/js/dialog.js new file mode 100644 index 000000000..4e60a09c9 --- /dev/null +++ b/js/dialog.js @@ -0,0 +1,16 @@ +const dialog = { + showOpenDialog: async function (options) { + return window.electronAPI.showOpenDialog(options); + }, + showSaveDialog: async function (options) { + return window.electronAPI.showSaveDialog(options); + }, + alert: function (message) { + return window.electronAPI.alertDialog(message); + }, + confirm: function (message) { + return window.electronAPI.confirmDialog(message); + } +}; + +export default dialog; \ No newline at end of file diff --git a/js/eventFrequencyAnalyzer.js b/js/eventFrequencyAnalyzer.js index 189bdf898..32c39bb91 100644 --- a/js/eventFrequencyAnalyzer.js +++ b/js/eventFrequencyAnalyzer.js @@ -75,4 +75,4 @@ var eventFrequencyAnalyzer = (function () { return publicScope; })(); -module.exports = eventFrequencyAnalyzer; \ No newline at end of file +export default eventFrequencyAnalyzer; \ No newline at end of file diff --git a/js/fc.js b/js/fc.js index a5aaf55cd..d6287bfda 100644 --- a/js/fc.js +++ b/js/fc.js @@ -1,21 +1,21 @@ 'use strict'; -const ServoMixerRuleCollection = require('./servoMixerRuleCollection'); -const MotorMixerRuleCollection = require('./motorMixerRuleCollection'); -const LogicConditionsCollection = require('./logicConditionsCollection'); -const LogicConditionsStatus = require('./logicConditionsStatus'); -const GlobalVariablesStatus = require('./globalVariablesStatus'); -const ProgrammingPidCollection = require('./programmingPidCollection'); -const ProgrammingPidStatus = require('./programmingPidStatus'); -const WaypointCollection = require('./waypointCollection'); -const OutputMappingCollection = require('./outputMapping'); -const SafehomeCollection = require('./safehomeCollection'); -const FwApproachCollection = require('./fwApproachCollection'); -const GeozoneCollection = require('./geozoneCollection'); -const { PLATFORM } = require('./model') -const VTX = require('./vtx'); -const BitHelper = require('./bitHelper'); -const { FLIGHT_MODES } = require('./flightModes'); +import ServoMixerRuleCollection from './servoMixerRuleCollection'; +import MotorMixerRuleCollection from './motorMixerRuleCollection'; +import LogicConditionsCollection from './logicConditionsCollection'; +import LogicConditionsStatus from './logicConditionsStatus'; +import GlobalVariablesStatus from './globalVariablesStatus'; +import ProgrammingPidCollection from './programmingPidCollection'; +import ProgrammingPidStatus from './programmingPidStatus'; +import WaypointCollection from './waypointCollection'; +import OutputMappingCollection from './outputMapping'; +import SafehomeCollection from './safehomeCollection'; +import FwApproachCollection from './fwApproachCollection'; +import GeozoneCollection from './geozoneCollection'; +import { PLATFORM } from './model'; +import VTX from './vtx'; +import BitHelper from './bitHelper'; +import { FLIGHT_MODES } from './flightModes'; var FC = { @@ -1141,4 +1141,4 @@ var FC = { } }; -module.exports = FC; +export default FC; diff --git a/js/feature_framework.js b/js/feature_framework.js index a477060c6..e449eb941 100644 --- a/js/feature_framework.js +++ b/js/feature_framework.js @@ -21,9 +21,9 @@ helper.features.execute(function () { */ -const mspHelper = require('./msp/MSPHelper'); -const BitHelper = require('./bitHelper'); -const FC = require('./fc'); +import mspHelper from './msp/MSPHelper'; +import BitHelper from './bitHelper'; +import FC from './fc'; var features = (function() { @@ -88,4 +88,4 @@ var features = (function() { return publicScope; })(); -module.exports = features; \ No newline at end of file +export default features; \ No newline at end of file diff --git a/js/flightModes.js b/js/flightModes.js index ae2e0664c..3a489118c 100644 --- a/js/flightModes.js +++ b/js/flightModes.js @@ -303,4 +303,4 @@ var FLIGHT_MODES = [ } ]; -module.exports = {FLIGHT_MODES}; \ No newline at end of file +export { FLIGHT_MODES }; \ No newline at end of file diff --git a/js/fwApproach.js b/js/fwApproach.js index 67bbe8600..898ca0e13 100644 --- a/js/fwApproach.js +++ b/js/fwApproach.js @@ -105,4 +105,4 @@ let FwApproach = function (number, approachAltAsl = 0, landAltAsl = 0, approachD return self; }; -module.exports = { ApproachDirection, FwApproach }; +export { ApproachDirection, FwApproach }; diff --git a/js/fwApproachCollection.js b/js/fwApproachCollection.js index a0ac94e7d..4f61aeb1e 100644 --- a/js/fwApproachCollection.js +++ b/js/fwApproachCollection.js @@ -1,6 +1,6 @@ 'use strict'; -const BitHelper = require('./bitHelper'); +import BitHelper from './bitHelper'; let FwApproachCollection = function () { @@ -93,4 +93,4 @@ let FwApproachCollection = function () { return self; }; -module.exports = FwApproachCollection; +export default FwApproachCollection; diff --git a/js/geozone.js b/js/geozone.js index 8b7ceb44a..358781fba 100644 --- a/js/geozone.js +++ b/js/geozone.js @@ -1,6 +1,5 @@ 'use strict' -const { Shape } = require("three"); const GeozoneType = Object.freeze({ EXCULSIVE: 0, @@ -271,8 +270,5 @@ let Geozone = function (type, shape, minAltitude, maxAltitude, sealevelRef, radi } return self; - - return self; } - -module.exports = { Geozone, GeozoneVertex, GeozoneType, GeozoneShapes, GeozoneFenceAction }; \ No newline at end of file +export { Geozone, GeozoneVertex, GeozoneType, GeozoneShapes, GeozoneFenceAction }; \ No newline at end of file diff --git a/js/geozoneCollection.js b/js/geozoneCollection.js index 77fbe0860..10f4fc2d1 100644 --- a/js/geozoneCollection.js +++ b/js/geozoneCollection.js @@ -1,7 +1,7 @@ 'use strict'; -const BitHelper = require('./bitHelper'); -const { GeozoneShapes } = require('./geozone'); +import BitHelper from './bitHelper'; +import { GeozoneShapes } from './geozone'; let GeozoneCollection = function() { let self = {}, @@ -149,4 +149,4 @@ let GeozoneCollection = function() { return self; }; -module.exports = GeozoneCollection; \ No newline at end of file +export default GeozoneCollection; \ No newline at end of file diff --git a/js/globalSettings.js b/js/globalSettings.js index 730a30af1..0790ed3ec 100644 --- a/js/globalSettings.js +++ b/js/globalSettings.js @@ -32,4 +32,4 @@ var globalSettings = { } }; -module.exports = { globalSettings, UnitType }; \ No newline at end of file +export { globalSettings, UnitType }; \ No newline at end of file diff --git a/js/globalUpdates.js b/js/globalUpdates.js index ca6784312..695e0e0c7 100644 --- a/js/globalUpdates.js +++ b/js/globalUpdates.js @@ -1,9 +1,9 @@ 'use strict' -const CONFIGURATOR = require('./data_storage'); -const FC = require('./fc'); -const { globalSettings } = require('./globalSettings'); -const i18n = require('./localization'); +import CONFIGURATOR from './data_storage'; +import FC from './fc'; +import { globalSettings } from './globalSettings'; +import i18n from './localization'; var update = { @@ -37,5 +37,5 @@ var update = { } }; -module.exports = update; +export default update; diff --git a/js/globalVariablesStatus.js b/js/globalVariablesStatus.js index 1f2f77cb5..05fe9893a 100644 --- a/js/globalVariablesStatus.js +++ b/js/globalVariablesStatus.js @@ -52,4 +52,4 @@ var GlobalVariablesStatus = function () { return self; }; -module.exports = GlobalVariablesStatus; \ No newline at end of file +export default GlobalVariablesStatus; \ No newline at end of file diff --git a/js/groundstation.js b/js/groundstation.js index 88f80d0a2..47cf9260f 100644 --- a/js/groundstation.js +++ b/js/groundstation.js @@ -1,13 +1,24 @@ 'use strict'; -const path = require('path'); -const ol = require('openlayers'); - -const { GUI } = require('./gui'); -const ltmDecoder = require('./ltmDecoder'); -const interval = require('./intervals'); -const { globalSettings } = require('./globalSettings'); -const i18n = require('./localization'); +import Map from 'ol/Map.js'; +import OSM from 'ol/source/OSM.js'; +import TileWMS from 'ol/source/TileWMS' +import BingMaps from 'ol/source/BingMaps' +import TileLayer from 'ol/layer/Tile.js'; +import { fromLonLat } from 'ol/proj'; +import View from 'ol/View.js' +import Style from 'ol/style/Style' +import Icon from 'ol/style/Icon'; +import Point from 'ol/geom/Point.js'; +import Feature from 'ol/format/Feature'; +import VectorSource from 'ol/source/Vector.js'; +import VectorLayer from 'ol/layer/Vector.js'; + +import { GUI } from './gui'; +import ltmDecoder from './ltmDecoder'; +import interval from './intervals'; +import { globalSettings } from './globalSettings'; +import i18n from './localization'; const groundstation = (function () { @@ -68,31 +79,31 @@ const groundstation = (function () { //initialte layers if (globalSettings.mapProviderType == 'bing') { - privateScope.mapLayer = new ol.source.BingMaps({ + privateScope.mapLayer = new BingMaps({ key: globalSettings.mapApiKey, imagerySet: 'AerialWithLabels', maxZoom: 19 }); } else if (globalSettings.mapProviderType == 'mapproxy') { - privateScope.mapLayer = new ol.source.TileWMS({ + privateScope.mapLayer = new TileWMS({ url: globalSettings.proxyURL, params: { 'LAYERS': globalSettings.proxyLayer } }) } else { - privateScope.mapLayer = new ol.source.OSM(); + privateScope.mapLayer = new OSM(); } //initiate view - privateScope.mapView = new ol.View({ - center: ol.proj.fromLonLat([0, 0]), + privateScope.mapView = new View({ + center: fromLonLat([0, 0]), zoom: 3 }); //initiate map handler - privateScope.mapHandler = new ol.Map({ - target: document.getElementById('groundstation-map'), + privateScope.mapHandler = new Map({ + target: 'groundstation-map', layers: [ - new ol.layer.Tile({ + new TileLayer({ source: privateScope.mapLayer }) ], @@ -135,26 +146,26 @@ const groundstation = (function () { if (!privateScope.mapInitiated) { //Place UAV on the map - privateScope.cursorStyle = new ol.style.Style({ - image: new ol.style.Icon(({ + privateScope.cursorStyle = new Style({ + image: new Icon(({ anchor: [0.5, 0.5], opacity: 1, scale: 0.6, src: path.join(__dirname, './../images/icons/icon_mission_airplane.png') })) }); - privateScope.cursorPosition = new ol.geom.Point(ol.proj.fromLonLat([lon, lat])); + privateScope.cursorPosition = new Point(fromLonLat([lon, lat])); - privateScope.cursorFeature = new ol.Feature({ + privateScope.cursorFeature = new Feature({ geometry: privateScope.cursorPosition }); privateScope.cursorFeature.setStyle(privateScope.cursorStyle); - privateScope.cursorVector = new ol.source.Vector({ + privateScope.cursorVector = new VectorSource({ features: [privateScope.cursorFeature] }); - privateScope.cursorLayer = new ol.layer.Vector({ + privateScope.cursorLayer = new VectorLayer({ source: privateScope.cursorVector }); @@ -166,7 +177,7 @@ const groundstation = (function () { } //Update map center - let position = ol.proj.fromLonLat([lon, lat]); + let position = fromLonLat([lon, lat]); privateScope.mapView.setCenter(position); //Update position of cursor @@ -201,4 +212,4 @@ const groundstation = (function () { return publicScope; })(); -module.exports = groundstation; \ No newline at end of file +export default groundstation; \ No newline at end of file diff --git a/js/gui.js b/js/gui.js index 18ad01517..72d55d96e 100644 --- a/js/gui.js +++ b/js/gui.js @@ -1,17 +1,15 @@ 'use strict'; -const { dialog } = require("@electron/remote"); -const CONFIGURATOR = require('./data_storage'); -const Switchery = require('./libraries/switchery/switchery') -const MSP = require('./msp'); -const FC = require('./fc'); -const interval = require('./intervals'); -const { scaleRangeInt } = require('./helpers'); -const i18n = require('./localization'); -const mspDeduplicationQueue = require("./msp/mspDeduplicationQueue"); +import MSP from './msp'; +import FC from './fc'; +import interval from './intervals'; +import { scaleRangeInt } from './helpers'; +import i18n from './localization'; +import mspDeduplicationQueue from "./msp/mspDeduplicationQueue"; var TABS = {}; // filled by individual tab js file + var GUI_control = function () { this.connecting_to = false; this.connected_to = false; @@ -108,38 +106,22 @@ GUI_control.prototype.tab_switch_cleanup = function (callback) { }; GUI_control.prototype.switchery = function() { + $('.togglesmall').each(function(index, elem) { - var switchery = new Switchery(elem, { - size: 'small', - color: '#37a8db', - secondaryColor: '#c4c4c4' - }); - $(elem).on("change", function (evt) { - switchery.setPosition(); - }); + $(elem).wrapAll('