From 295e088aa5f1fe4272f701eb0224805143e6bb2e Mon Sep 17 00:00:00 2001 From: Tomas Chmelevskij Date: Wed, 24 Jul 2024 15:28:00 +0200 Subject: [PATCH] Remove cordova logic (#4000) remove cordova logic --- .../EscDshotDirectionComponent.js | 12 +-- src/js/DarkTheme.js | 13 +-- src/js/gui.js | 6 -- src/js/main.js | 67 ++------------ src/js/phones_ui.js | 90 ------------------- src/js/serial_backend.js | 9 -- src/js/tabs/cli.js | 10 --- src/js/tabs/options.js | 23 +---- src/js/tabs/osd.js | 8 -- src/js/tabs/receiver.js | 49 +++++----- src/js/tabs/vtx.js | 16 +--- src/tabs/presets/presets.js | 13 --- 12 files changed, 39 insertions(+), 277 deletions(-) delete mode 100644 src/js/phones_ui.js diff --git a/src/components/EscDshotDirection/EscDshotDirectionComponent.js b/src/components/EscDshotDirection/EscDshotDirectionComponent.js index d87a11c5da..7ca68d3246 100644 --- a/src/components/EscDshotDirection/EscDshotDirectionComponent.js +++ b/src/components/EscDshotDirection/EscDshotDirectionComponent.js @@ -39,20 +39,12 @@ class EscDshotDirectionComponent static get _BUTTON_PUSH_DOWN_EVENT_TYPE() { - if (GUI.isCordova()) { - return "touchstart"; - } else { - return "mousedown"; - } + return "mousedown"; } static get _BUTTON_RELEASE_EVENT_TYPE() { - if (GUI.isCordova()) { - return "touchend"; - } else { - return "mouseup mouseout"; - } + return "mouseup mouseout"; } _readDom() diff --git a/src/js/DarkTheme.js b/src/js/DarkTheme.js index 2e8f1c0c30..a9acebf85c 100644 --- a/src/js/DarkTheme.js +++ b/src/js/DarkTheme.js @@ -16,17 +16,8 @@ DarkTheme.isDarkThemeEnabled = function (callback) { if (this.configSetting === 0) { callback(true); } else if (this.configSetting === 2) { - if (GUI.isCordova()) { - cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) { - callback(success.value); - }, function(error) { - console.log(`cordova-plugin-theme-detection: ${error}`); - callback(false); - }); - } else { - const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; - callback(isEnabled); - } + const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + callback(isEnabled); } else { callback(false); } diff --git a/src/js/gui.js b/src/js/gui.js index 22bda5348e..d0bf56a8d0 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -347,12 +347,6 @@ class GuiControl { $(`#tabs ul.mode-connected .${tab} a`).trigger('click'); } - isNWJS() { - return this.Mode === GUI_MODES.NWJS; - } - isCordova() { - return this.Mode === GUI_MODES.Cordova; - } isOther() { return this.Mode === GUI_MODES.Other; } diff --git a/src/js/main.js b/src/js/main.js index 3c58440c06..6b810f3440 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -14,7 +14,6 @@ import FC from './fc.js'; import CONFIGURATOR from './data_storage.js'; import CliAutoComplete from './CliAutoComplete.js'; import DarkTheme, { setDarkTheme } from './DarkTheme.js'; -import UI_PHONES from './phones_ui.js'; import { isExpertModeEnabled } from './utils/isExportModeEnabled.js'; import { updateTabList } from './utils/updateTabList.js'; import { checkForConfiguratorUpdates } from './utils/checkForConfiguratorUpdates.js'; @@ -28,39 +27,18 @@ if (typeof String.prototype.replaceAll === "undefined") { $(document).ready(function () { - useGlobalNodeFunctions(); - if (typeof cordovaApp === 'undefined') { appReady(); } }); -function useGlobalNodeFunctions() { - // The global functions of Node continue working on background. This is good to continue flashing, - // for example, when the window is minimized - if (GUI.isNWJS()) { - console.log("Replacing timeout/interval functions with Node versions"); - window.setTimeout = global.setTimeout; - window.clearTimeout = global.clearTimeout; - window.setInterval = global.setInterval; - window.clearInterval = global.clearInterval; - } -} - function readConfiguratorVersionMetadata() { - if (GUI.isNWJS() || GUI.isCordova()) { - const manifest = chrome.runtime.getManifest(); - CONFIGURATOR.productName = manifest.productName; - CONFIGURATOR.version = manifest.version; - CONFIGURATOR.gitRevision = manifest.gitRevision; - } else { - // These are injected by vite. If not checking - // for undefined occasionally there is a race - // condition where this fails the nwjs and cordova builds - CONFIGURATOR.productName = typeof __APP_PRODUCTNAME__ !== 'undefined' ? __APP_PRODUCTNAME__ : 'Betaflight Configurator'; - CONFIGURATOR.version = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0'; - CONFIGURATOR.gitRevision = typeof __APP_REVISION__ !== 'undefined' ? __APP_REVISION__ : 'unknown'; - } + // These are injected by vite. If not checking + // for undefined occasionally there is a race + // condition where this fails the nwjs and cordova builds + CONFIGURATOR.productName = typeof __APP_PRODUCTNAME__ !== 'undefined' ? __APP_PRODUCTNAME__ : 'Betaflight Configurator'; + CONFIGURATOR.version = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0'; + CONFIGURATOR.gitRevision = typeof __APP_REVISION__ !== 'undefined' ? __APP_REVISION__ : 'unknown'; } function cleanupLocalStorage() { @@ -148,20 +126,6 @@ function startProcess() { } }); - // break into mobile UI at the same breakpoint as the CSS, not only for Cordova - // use window.matchMedia - const mediaQuery = window.matchMedia('(max-width: 576px)'); - const handleMediaChange = function(e) { - if (e.matches) { - console.log('Using mobile UI'); - UI_PHONES.init(); - } else { - console.log('Using desktop UI'); - } - }; - mediaQuery.addEventListener('change', handleMediaChange); - handleMediaChange(mediaQuery); - const ui_tabs = $('#tabs > ul'); $('a', ui_tabs).click(function () { if ($(this).parent().hasClass('active') === false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active @@ -504,22 +468,9 @@ function startProcess() { setDarkTheme(result.darkTheme); } - if (GUI.isCordova()) { - let darkMode = false; - const checkDarkMode = function() { - cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) { - if (success.value !== darkMode) { - darkMode = success.value; - DarkTheme.autoSet(); - } - }); - }; - setInterval(checkDarkMode, 500); - } else { - window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() { - DarkTheme.autoSet(); - }); - } + window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() { + DarkTheme.autoSet(); + }); } window.isExpertModeEnabled = isExpertModeEnabled; diff --git a/src/js/phones_ui.js b/src/js/phones_ui.js deleted file mode 100644 index bfbe0b350b..0000000000 --- a/src/js/phones_ui.js +++ /dev/null @@ -1,90 +0,0 @@ -import GUI from "./gui"; -import $ from 'jquery'; - -const UI_PHONES = { - background: '#background', - tabContainer: '.tab_container', - tabContentContainer: '#tab-content-container', - headerbar: '.headerbar', - init: function() { - const self = this; - $('#menu_btn').click(function() { - self.openSideMenu(); - }); - $(this.background).click(function() { - self.closeSideMenu(); - }); - $('#tabs a').click(function() { - if ($('.tab_container').hasClass('reveal')) { - self.closeSideMenu(); - } - }); - $('#reveal_btn').click(function() { - self.expandHeader(); - }); - $(`${this.background}, ${this.tabContainer}`).swipe( { - swipeLeft: function() { - self.closeSideMenu(); - }, - }); - $('#side_menu_swipe').swipe( { - swipeRight: function() { - self.openSideMenu(); - }, - }); - }, - initToolbar: function() { - $('.toolbar_expand_btn').click(this.expandToolbar); - }, - openSideMenu: function() { - $(this.background).fadeIn(300); - $(this.tabContainer).addClass('reveal'); - }, - closeSideMenu: function() { - $(this.background).fadeOut(300); - $(this.tabContainer).removeClass('reveal'); - }, - expandHeader: function() { - const self = this; - let expand, headerExpanded, reveal; - if (GUI.connected_to) { - expand = 'expand2'; - headerExpanded = 'header_expanded2'; - reveal = '.header-wrapper'; - } else { - expand = 'expand'; - headerExpanded = 'headerExpanded'; - reveal = '#port-picker'; - } - if ($(self.headerbar).hasClass(expand)) { - $(reveal).removeClass('reveal'); - setTimeout(function() { - $(self.tabContentContainer).removeClass(headerExpanded); - $(self.headerbar).removeClass(expand); - }, 100); - } else { - $(self.tabContentContainer).addClass(headerExpanded); - $(self.headerbar).addClass(expand); - setTimeout(function() { - $(reveal).addClass('reveal'); - }, 100); - } - }, - expandToolbar: function() { - const toolbar = $('.content_toolbar.xs-compressed'); - if (toolbar.length > 0) { - if ($('.content_toolbar.xs-compressed').hasClass('expanded')) { - toolbar.removeClass('expanded'); - } else { - toolbar.addClass('expanded'); - } - } - }, - reset: function() { - $(this.tabContentContainer).removeClass('header_expanded2 header_expanded'); - $('#port-picker, .header-wrapper').removeClass('reveal'); - $(this.headerbar).removeClass('expand2 expand'); - }, -}; - -export default UI_PHONES; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 694a3a0ebb..ca672ec6db 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -11,7 +11,6 @@ import MSPCodes from "./msp/MSPCodes"; import PortUsage from "./port_usage"; import PortHandler from "./port_handler"; import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46 } from "./data_storage"; -import UI_PHONES from "./phones_ui"; import { bit_check } from './bit.js'; import { sensor_status, have_sensor } from "./sensor_helpers"; import { update_dataflash_global } from "./update_dataflash_global"; @@ -163,10 +162,6 @@ function connectDisconnect() { } function finishClose(finishedCallback) { - if (GUI.isCordova()) { - UI_PHONES.reset(); - } - const wasConnected = CONFIGURATOR.connectionValid; tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Disconnected', { time: connectionTimestamp ? Date.now() - connectionTimestamp : undefined}); @@ -574,10 +569,6 @@ function finishOpen() { GUI.allowedTabs = Array.from(GUI.defaultAllowedFCTabsWhenConnected); } - if (GUI.isCordova()) { - UI_PHONES.reset(); - } - onConnect(); GUI.selectDefaultTabWhenConnected(); diff --git a/src/js/tabs/cli.js b/src/js/tabs/cli.js index 666b72b893..205c38e2fa 100644 --- a/src/js/tabs/cli.js +++ b/src/js/tabs/cli.js @@ -7,7 +7,6 @@ import { tracking } from '../Analytics'; import { reinitializeConnection } from "../serial_backend"; import CONFIGURATOR from "../data_storage"; import CliAutoComplete from "../CliAutoComplete"; -import UI_PHONES from "../phones_ui"; import { gui_log } from "../gui_log"; import jBox from "jbox"; import $ from 'jquery'; @@ -334,15 +333,6 @@ cli.adaptPhones = function() { const backdropHeight = $('.note').height() + 22 + 38; $('.backdrop').css('height', `calc(100% - ${backdropHeight}px)`); } - - const mediaQuery = window.matchMedia('(max-width: 576px)'); - const handleMediaChange = function(e) { - if (e.matches) { - UI_PHONES.initToolbar(); - } - }; - mediaQuery.addEventListener('change', handleMediaChange); - handleMediaChange(mediaQuery); }; cli.history = { diff --git a/src/js/tabs/options.js b/src/js/tabs/options.js index d72fc370ca..382e45d8e2 100644 --- a/src/js/tabs/options.js +++ b/src/js/tabs/options.js @@ -160,24 +160,7 @@ options.initUseManualConnection = function() { }; options.initCordovaForceComputerUI = function () { - if (GUI.isCordova() && cordovaUI.canChangeUI) { - const result = getConfig('cordovaForceComputerUI'); - if (result.cordovaForceComputerUI) { - $('div.cordovaForceComputerUI input').prop('checked', true); - } - - $('div.cordovaForceComputerUI input').change(function () { - const checked = $(this).is(':checked'); - - setConfig({'cordovaForceComputerUI': checked}); - - if (typeof cordovaUI.set === 'function') { - cordovaUI.set(); - } - }); - } else { - $('div.cordovaForceComputerUI').hide(); - } + $('div.cordovaForceComputerUI').hide(); }; options.initDarkTheme = function () { @@ -192,10 +175,6 @@ options.initDarkTheme = function () { }; options.initShowDevToolsOnStartup = function () { - if (!(CONFIGURATOR.isDevVersion() && GUI.isNWJS())) { - $('div.showDevToolsOnStartup').hide(); - return; - } const result = getConfig('showDevToolsOnStartup'); $('div.showDevToolsOnStartup input') .prop('checked', !!result.showDevToolsOnStartup) diff --git a/src/js/tabs/osd.js b/src/js/tabs/osd.js index 7445a98cc9..48b2241033 100644 --- a/src/js/tabs/osd.js +++ b/src/js/tabs/osd.js @@ -3044,14 +3044,6 @@ osd.initialize = function(callback) { // Hide custom if not used $('.osdfont-selector option[value=-1]').toggle(osdFontSelectorElement.val() === -1); - // Zoom option for the preview only for mobile devices - if (GUI.isCordova()) { - $('.osd-preview-zoom-group').css({display: 'inherit'}); - $('#osd-preview-zoom-selector').on('change', function() { - $('.tab-osd .osd-preview').toggleClass('osd-preview-zoom', this.checked); - }); - } - // display fields on/off and position const $displayFields = $('#element-fields').empty(); let enabledCount = 0; diff --git a/src/js/tabs/receiver.js b/src/js/tabs/receiver.js index 83130adab1..3769a0b4d2 100644 --- a/src/js/tabs/receiver.js +++ b/src/js/tabs/receiver.js @@ -272,23 +272,20 @@ receiver.initialize = function (callback) { // select current serial RX type serialRxSelectElement.val(FC.RX_CONFIG.serialrx_provider); - // Convert to select2 and order alphabetic - if (!GUI.isCordova()) { - if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { - serialRxSelectElement.sortSelect("NONE").select2(); - } else { - serialRxSelectElement.sortSelect().select2(); - } + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { + serialRxSelectElement.sortSelect("NONE").select2(); + } else { + serialRxSelectElement.sortSelect().select2(); + } - $(document).on('select2:open', 'select.serialRX', () => { - const allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); - $(this).one('mouseup keyup',()=>{ - setTimeout(()=>{ - allFound[allFound.length - 1].focus(); - },0); - }); + $(document).on('select2:open', 'select.serialRX', () => { + const allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); + $(this).one('mouseup keyup',()=>{ + setTimeout(()=>{ + allFound[allFound.length - 1].focus(); + },0); }); - } + }); const spiRxTypes = [ 'NRF24_V202_250K', @@ -334,19 +331,17 @@ receiver.initialize = function (callback) { // select current serial RX type spiRxElement.val(FC.RX_CONFIG.rxSpiProtocol); - if (!GUI.isCordova()) { - // Convert to select2 and order alphabetic - spiRxElement.sortSelect().select2(); - - $(document).on('select2:open', 'select.spiRx', () => { - const allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); - $(this).one('mouseup keyup',()=>{ - setTimeout(()=>{ - allFound[allFound.length - 1].focus(); - },0); - }); + // Convert to select2 and order alphabetic + spiRxElement.sortSelect().select2(); + + $(document).on('select2:open', 'select.spiRx', () => { + const allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); + $(this).one('mouseup keyup',()=>{ + setTimeout(()=>{ + allFound[allFound.length - 1].focus(); + },0); }); - } + }); if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { tab.elrsBindingPhraseEnabled = true; diff --git a/src/js/tabs/vtx.js b/src/js/tabs/vtx.js index c46ad8940e..ae00018875 100644 --- a/src/js/tabs/vtx.js +++ b/src/js/tabs/vtx.js @@ -9,7 +9,6 @@ import FC from '../fc'; import { VtxDeviceTypes } from '../utils/VtxDeviceStatus/VtxDeviceStatus'; import MSP from "../msp"; import MSPCodes from "../msp/MSPCodes"; -import UI_PHONES from "../phones_ui"; import { gui_log } from "../gui_log"; import $ from 'jquery'; import FileSystem from "../FileSystem"; @@ -82,15 +81,6 @@ vtx.initialize = function (callback) { // translate to user-selected language i18n.localizePage(); - const mediaQuery = window.matchMedia('(max-width: 576px)'); - const handleMediaChange = function(e) { - if (e.matches) { - UI_PHONES.initToolbar(); - } - }; - mediaQuery.addEventListener('change', handleMediaChange); - handleMediaChange(mediaQuery); - self.updating = false; GUI.content_ready(callback); } @@ -178,9 +168,9 @@ vtx.initialize = function (callback) { const vtxJsonSchemaUrl = `../../resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`; fetch(vtxJsonSchemaUrl) - .then(response => response.json()) - .catch(error => console.error('Error fetching VTX Schema:', error)) - .then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig)); + .then(response => response.json()) + .catch(error => console.error('Error fetching VTX Schema:', error)) + .then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig)); } // Emulates the MSP read from a vtxConfig object (JSON) diff --git a/src/tabs/presets/presets.js b/src/tabs/presets/presets.js index ecdc79d933..8ee4581788 100644 --- a/src/tabs/presets/presets.js +++ b/src/tabs/presets/presets.js @@ -5,7 +5,6 @@ import { generateFilename } from '../../js/utils/generate_filename'; import { i18n } from '../../js/localization'; import FC from '../../js/fc'; import CONFIGURATOR from '../../js/data_storage'; -import UI_PHONES from '../../js/phones_ui'; import $ from 'jquery'; import FileSystem from '../../js/FileSystem'; @@ -294,7 +293,6 @@ presets.onLoadConfigClick = function() { presets.onHtmlLoad = function(callback) { i18n.localizePage(); - TABS.presets.adaptPhones(); this.readDom(); this.setupMenuButtons(); this.setupBackupWarning(); @@ -663,17 +661,6 @@ presets.isPresetFitSearch = function(preset, searchParams) { return true; }; -presets.adaptPhones = function() { - const mediaQuery = window.matchMedia('(max-width: 576px)'); - const handleMediaChange = function(e) { - if (e.matches) { - UI_PHONES.initToolbar(); - } - }; - mediaQuery.addEventListener('change', handleMediaChange); - handleMediaChange(mediaQuery); -}; - presets.read = function(readInfo) { TABS.presets.cliEngine.readSerial(readInfo); };