1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 17:25:16 +03:00

Remove cordova logic (#4000)

remove cordova logic
This commit is contained in:
Tomas Chmelevskij 2024-07-24 15:28:00 +02:00 committed by GitHub
parent 85ceabf51f
commit 295e088aa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 39 additions and 277 deletions

View file

@ -39,20 +39,12 @@ class EscDshotDirectionComponent
static get _BUTTON_PUSH_DOWN_EVENT_TYPE() static get _BUTTON_PUSH_DOWN_EVENT_TYPE()
{ {
if (GUI.isCordova()) { return "mousedown";
return "touchstart";
} else {
return "mousedown";
}
} }
static get _BUTTON_RELEASE_EVENT_TYPE() static get _BUTTON_RELEASE_EVENT_TYPE()
{ {
if (GUI.isCordova()) { return "mouseup mouseout";
return "touchend";
} else {
return "mouseup mouseout";
}
} }
_readDom() _readDom()

View file

@ -16,17 +16,8 @@ DarkTheme.isDarkThemeEnabled = function (callback) {
if (this.configSetting === 0) { if (this.configSetting === 0) {
callback(true); callback(true);
} else if (this.configSetting === 2) { } else if (this.configSetting === 2) {
if (GUI.isCordova()) { const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) { callback(isEnabled);
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);
}
} else { } else {
callback(false); callback(false);
} }

View file

@ -347,12 +347,6 @@ class GuiControl {
$(`#tabs ul.mode-connected .${tab} a`).trigger('click'); $(`#tabs ul.mode-connected .${tab} a`).trigger('click');
} }
isNWJS() {
return this.Mode === GUI_MODES.NWJS;
}
isCordova() {
return this.Mode === GUI_MODES.Cordova;
}
isOther() { isOther() {
return this.Mode === GUI_MODES.Other; return this.Mode === GUI_MODES.Other;
} }

View file

@ -14,7 +14,6 @@ import FC from './fc.js';
import CONFIGURATOR from './data_storage.js'; import CONFIGURATOR from './data_storage.js';
import CliAutoComplete from './CliAutoComplete.js'; import CliAutoComplete from './CliAutoComplete.js';
import DarkTheme, { setDarkTheme } from './DarkTheme.js'; import DarkTheme, { setDarkTheme } from './DarkTheme.js';
import UI_PHONES from './phones_ui.js';
import { isExpertModeEnabled } from './utils/isExportModeEnabled.js'; import { isExpertModeEnabled } from './utils/isExportModeEnabled.js';
import { updateTabList } from './utils/updateTabList.js'; import { updateTabList } from './utils/updateTabList.js';
import { checkForConfiguratorUpdates } from './utils/checkForConfiguratorUpdates.js'; import { checkForConfiguratorUpdates } from './utils/checkForConfiguratorUpdates.js';
@ -28,39 +27,18 @@ if (typeof String.prototype.replaceAll === "undefined") {
$(document).ready(function () { $(document).ready(function () {
useGlobalNodeFunctions();
if (typeof cordovaApp === 'undefined') { if (typeof cordovaApp === 'undefined') {
appReady(); 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() { function readConfiguratorVersionMetadata() {
if (GUI.isNWJS() || GUI.isCordova()) { // These are injected by vite. If not checking
const manifest = chrome.runtime.getManifest(); // for undefined occasionally there is a race
CONFIGURATOR.productName = manifest.productName; // condition where this fails the nwjs and cordova builds
CONFIGURATOR.version = manifest.version; CONFIGURATOR.productName = typeof __APP_PRODUCTNAME__ !== 'undefined' ? __APP_PRODUCTNAME__ : 'Betaflight Configurator';
CONFIGURATOR.gitRevision = manifest.gitRevision; CONFIGURATOR.version = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0';
} else { 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() { 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'); const ui_tabs = $('#tabs > ul');
$('a', ui_tabs).click(function () { $('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 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); setDarkTheme(result.darkTheme);
} }
if (GUI.isCordova()) { window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
let darkMode = false; DarkTheme.autoSet();
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.isExpertModeEnabled = isExpertModeEnabled; window.isExpertModeEnabled = isExpertModeEnabled;

View file

@ -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;

View file

@ -11,7 +11,6 @@ import MSPCodes from "./msp/MSPCodes";
import PortUsage from "./port_usage"; import PortUsage from "./port_usage";
import PortHandler from "./port_handler"; import PortHandler from "./port_handler";
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46 } from "./data_storage"; 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 { bit_check } from './bit.js';
import { sensor_status, have_sensor } from "./sensor_helpers"; import { sensor_status, have_sensor } from "./sensor_helpers";
import { update_dataflash_global } from "./update_dataflash_global"; import { update_dataflash_global } from "./update_dataflash_global";
@ -163,10 +162,6 @@ function connectDisconnect() {
} }
function finishClose(finishedCallback) { function finishClose(finishedCallback) {
if (GUI.isCordova()) {
UI_PHONES.reset();
}
const wasConnected = CONFIGURATOR.connectionValid; const wasConnected = CONFIGURATOR.connectionValid;
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'Disconnected', { time: connectionTimestamp ? Date.now() - connectionTimestamp : undefined}); 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); GUI.allowedTabs = Array.from(GUI.defaultAllowedFCTabsWhenConnected);
} }
if (GUI.isCordova()) {
UI_PHONES.reset();
}
onConnect(); onConnect();
GUI.selectDefaultTabWhenConnected(); GUI.selectDefaultTabWhenConnected();

View file

@ -7,7 +7,6 @@ import { tracking } from '../Analytics';
import { reinitializeConnection } from "../serial_backend"; import { reinitializeConnection } from "../serial_backend";
import CONFIGURATOR from "../data_storage"; import CONFIGURATOR from "../data_storage";
import CliAutoComplete from "../CliAutoComplete"; import CliAutoComplete from "../CliAutoComplete";
import UI_PHONES from "../phones_ui";
import { gui_log } from "../gui_log"; import { gui_log } from "../gui_log";
import jBox from "jbox"; import jBox from "jbox";
import $ from 'jquery'; import $ from 'jquery';
@ -334,15 +333,6 @@ cli.adaptPhones = function() {
const backdropHeight = $('.note').height() + 22 + 38; const backdropHeight = $('.note').height() + 22 + 38;
$('.backdrop').css('height', `calc(100% - ${backdropHeight}px)`); $('.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 = { cli.history = {

View file

@ -160,24 +160,7 @@ options.initUseManualConnection = function() {
}; };
options.initCordovaForceComputerUI = function () { options.initCordovaForceComputerUI = function () {
if (GUI.isCordova() && cordovaUI.canChangeUI) { $('div.cordovaForceComputerUI').hide();
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();
}
}; };
options.initDarkTheme = function () { options.initDarkTheme = function () {
@ -192,10 +175,6 @@ options.initDarkTheme = function () {
}; };
options.initShowDevToolsOnStartup = function () { options.initShowDevToolsOnStartup = function () {
if (!(CONFIGURATOR.isDevVersion() && GUI.isNWJS())) {
$('div.showDevToolsOnStartup').hide();
return;
}
const result = getConfig('showDevToolsOnStartup'); const result = getConfig('showDevToolsOnStartup');
$('div.showDevToolsOnStartup input') $('div.showDevToolsOnStartup input')
.prop('checked', !!result.showDevToolsOnStartup) .prop('checked', !!result.showDevToolsOnStartup)

View file

@ -3044,14 +3044,6 @@ osd.initialize = function(callback) {
// Hide custom if not used // Hide custom if not used
$('.osdfont-selector option[value=-1]').toggle(osdFontSelectorElement.val() === -1); $('.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 // display fields on/off and position
const $displayFields = $('#element-fields').empty(); const $displayFields = $('#element-fields').empty();
let enabledCount = 0; let enabledCount = 0;

View file

@ -272,24 +272,21 @@ receiver.initialize = function (callback) {
// select current serial RX type // select current serial RX type
serialRxSelectElement.val(FC.RX_CONFIG.serialrx_provider); serialRxSelectElement.val(FC.RX_CONFIG.serialrx_provider);
// Convert to select2 and order alphabetic if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
if (!GUI.isCordova()) { serialRxSelectElement.sortSelect("NONE").select2();
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { } else {
serialRxSelectElement.sortSelect("NONE").select2(); serialRxSelectElement.sortSelect().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 = [ const spiRxTypes = [
'NRF24_V202_250K', 'NRF24_V202_250K',
'NRF24_V202_1M', 'NRF24_V202_1M',
@ -334,19 +331,17 @@ receiver.initialize = function (callback) {
// select current serial RX type // select current serial RX type
spiRxElement.val(FC.RX_CONFIG.rxSpiProtocol); spiRxElement.val(FC.RX_CONFIG.rxSpiProtocol);
if (!GUI.isCordova()) { // Convert to select2 and order alphabetic
// Convert to select2 and order alphabetic spiRxElement.sortSelect().select2();
spiRxElement.sortSelect().select2();
$(document).on('select2:open', 'select.spiRx', () => { $(document).on('select2:open', 'select.spiRx', () => {
const allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); const allFound = document.querySelectorAll('.select2-container--open .select2-search__field');
$(this).one('mouseup keyup',()=>{ $(this).one('mouseup keyup',()=>{
setTimeout(()=>{ setTimeout(()=>{
allFound[allFound.length - 1].focus(); allFound[allFound.length - 1].focus();
},0); },0);
});
}); });
} });
if (FC.FEATURE_CONFIG.features.isEnabled('RX_SPI') && FC.RX_CONFIG.rxSpiProtocol == 19 && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) { 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; tab.elrsBindingPhraseEnabled = true;

View file

@ -9,7 +9,6 @@ import FC from '../fc';
import { VtxDeviceTypes } from '../utils/VtxDeviceStatus/VtxDeviceStatus'; import { VtxDeviceTypes } from '../utils/VtxDeviceStatus/VtxDeviceStatus';
import MSP from "../msp"; import MSP from "../msp";
import MSPCodes from "../msp/MSPCodes"; import MSPCodes from "../msp/MSPCodes";
import UI_PHONES from "../phones_ui";
import { gui_log } from "../gui_log"; import { gui_log } from "../gui_log";
import $ from 'jquery'; import $ from 'jquery';
import FileSystem from "../FileSystem"; import FileSystem from "../FileSystem";
@ -82,15 +81,6 @@ vtx.initialize = function (callback) {
// translate to user-selected language // translate to user-selected language
i18n.localizePage(); 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; self.updating = false;
GUI.content_ready(callback); GUI.content_ready(callback);
} }
@ -178,9 +168,9 @@ vtx.initialize = function (callback) {
const vtxJsonSchemaUrl = `../../resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`; const vtxJsonSchemaUrl = `../../resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`;
fetch(vtxJsonSchemaUrl) fetch(vtxJsonSchemaUrl)
.then(response => response.json()) .then(response => response.json())
.catch(error => console.error('Error fetching VTX Schema:', error)) .catch(error => console.error('Error fetching VTX Schema:', error))
.then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig)); .then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig));
} }
// Emulates the MSP read from a vtxConfig object (JSON) // Emulates the MSP read from a vtxConfig object (JSON)

View file

@ -5,7 +5,6 @@ import { generateFilename } from '../../js/utils/generate_filename';
import { i18n } from '../../js/localization'; import { i18n } from '../../js/localization';
import FC from '../../js/fc'; import FC from '../../js/fc';
import CONFIGURATOR from '../../js/data_storage'; import CONFIGURATOR from '../../js/data_storage';
import UI_PHONES from '../../js/phones_ui';
import $ from 'jquery'; import $ from 'jquery';
import FileSystem from '../../js/FileSystem'; import FileSystem from '../../js/FileSystem';
@ -294,7 +293,6 @@ presets.onLoadConfigClick = function() {
presets.onHtmlLoad = function(callback) { presets.onHtmlLoad = function(callback) {
i18n.localizePage(); i18n.localizePage();
TABS.presets.adaptPhones();
this.readDom(); this.readDom();
this.setupMenuButtons(); this.setupMenuButtons();
this.setupBackupWarning(); this.setupBackupWarning();
@ -663,17 +661,6 @@ presets.isPresetFitSearch = function(preset, searchParams) {
return true; 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) { presets.read = function(readInfo) {
TABS.presets.cliEngine.readSerial(readInfo); TABS.presets.cliEngine.readSerial(readInfo);
}; };