Skip to content

Commit

Permalink
Remove cordova logic (#4000)
Browse files Browse the repository at this point in the history
remove cordova logic
  • Loading branch information
chmelevskij authored Jul 24, 2024
1 parent 85ceabf commit 295e088
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 277 deletions.
12 changes: 2 additions & 10 deletions src/components/EscDshotDirection/EscDshotDirectionComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 2 additions & 11 deletions src/js/DarkTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions src/js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
67 changes: 9 additions & 58 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
90 changes: 0 additions & 90 deletions src/js/phones_ui.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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});

Expand Down Expand Up @@ -574,10 +569,6 @@ function finishOpen() {
GUI.allowedTabs = Array.from(GUI.defaultAllowedFCTabsWhenConnected);
}

if (GUI.isCordova()) {
UI_PHONES.reset();
}

onConnect();

GUI.selectDefaultTabWhenConnected();
Expand Down
10 changes: 0 additions & 10 deletions src/js/tabs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand Down
23 changes: 1 addition & 22 deletions src/js/tabs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions src/js/tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 295e088

Please sign in to comment.