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,21 +39,13 @@ class EscDshotDirectionComponent
static get _BUTTON_PUSH_DOWN_EVENT_TYPE()
{
if (GUI.isCordova()) {
return "touchstart";
} else {
return "mousedown";
}
}
static get _BUTTON_RELEASE_EVENT_TYPE()
{
if (GUI.isCordova()) {
return "touchend";
} else {
return "mouseup mouseout";
}
}
_readDom()
{

View file

@ -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);
}
} else {
callback(false);
}

View file

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

View file

@ -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';
}
}
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.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 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();

View file

@ -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 = {

View file

@ -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();
}
};
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)

View file

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

View file

@ -272,8 +272,6 @@ 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 {
@ -288,7 +286,6 @@ receiver.initialize = function (callback) {
},0);
});
});
}
const spiRxTypes = [
'NRF24_V202_250K',
@ -334,7 +331,6 @@ 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();
@ -346,7 +342,6 @@ receiver.initialize = function (callback) {
},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;

View file

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

View file

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