1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 17:25:16 +03:00
betaflight-configurator/src/js/cordova_startup.js
Mark Haslinghuis f41e135333 Migrate chrome storage API to window.localStorage
Add remove function

Remove callback from set and remove

Rebased

Rebased
2022-04-22 01:08:48 +02:00

65 lines
1.9 KiB
JavaScript

'use strict';
const cordovaUI = {
uiZoom: 1,
canChangeUI: true,
init: async function() {
const self = this;
const screenWidth = $(window).width();
const screenHeight = $(window).height();
let length;
let orientation;
if (screenWidth > screenHeight) {
length = screenWidth;
orientation = 'landscape';
} else {
length = screenHeight;
orientation = 'portrait';
}
if (length < 1024) {
self.uiZoom = length/1024;
}
if (screenWidth > 575 && screenHeight > 575) {
self.canChangeUI = false;
}
const result = ConfigStorage.get('cordovaForceComputerUI');
if (result.cordovaForceComputerUI === undefined) {
if ((orientation === 'landscape' && screenHeight <= 575)
|| (orientation === 'portrait' && screenWidth <= 575)) {
ConfigStorage.set({'cordovaForceComputerUI': false});
} else {
ConfigStorage.set({'cordovaForceComputerUI': true});
}
}
self.set();
},
set: function() {
const self = this;
const result = ConfigStorage.get('cordovaForceComputerUI');
if (result.cordovaForceComputerUI) {
window.screen.orientation.lock('landscape');
$('body').css('zoom', self.uiZoom);
} else {
window.screen.orientation.lock('portrait');
$('body').css('zoom', 1);
}
},
};
const cordovaApp = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
$('.open_firmware_flasher, .tab_firmware_flasher').hide();
cordovaUI.init();
navigator.splashscreen.hide();
cordovaChromeapi.init();
appReady();
},
};
cordovaApp.initialize();