1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-16 12:55:13 +03:00
This commit is contained in:
Andi Kanzler 2024-02-11 14:30:43 -03:00
parent 53aebde936
commit 017a6553ff
8 changed files with 66 additions and 207 deletions

View file

@ -13,7 +13,6 @@
<script type="text/javascript" src="./js/libraries/three/three.min.js"></script>
<script type="text/javascript" src="./js/libraries/three/GLTFLoader.js"></script>
<script type="text/javascript" src="./js/libraries/three/OrbitControls.js"></script>
<script type="text/javascript" src="./js/libraries/nw-dialog.js"></script>
<script type="text/javascript" src="./js/libraries/bundle_xml2js.js"></script>
<script type="text/javascript" src="./js/libraries/Projector.js"></script>
<script type="text/javascript" src="./js/libraries/CanvasRenderer.js"></script>

View file

@ -95,8 +95,9 @@ class ConnectionBle extends Connection {
});
return navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: ids
//acceptAllDevices: true,
//optionalServices: ids
filters: [{ services: ['generic_attribute'] }],
}).then(device => {
console.log("Found BLE device: " + device.name);
this._device = device;

View file

@ -3,7 +3,7 @@
var CONFIGURATOR = {
// all versions are specified and compared using semantic versioning http://semver.org/
'minfirmwareVersionAccepted': '7.0.0',
'maxFirmwareVersionAccepted': '8.0.0', // Condition is < (lt) so we accept all in 7.x branch
'maxFirmwareVersionAccepted': '9.0.0', // Condition is < (lt) so we accept all in 8.x branch
'connectionValid': false,
'connectionValidCliOnly': false,
'cliActive': false,

View file

@ -253,7 +253,7 @@ var FC = {
packetCount: 0
};
DSB_VEHICLES = {
ADSB_VEHICLES = {
vehiclesCount: 0,
callsignLength: 0,
vehicles: []

View file

@ -1,125 +0,0 @@
'use strict';
var nwdialog = {
_context: (typeof global === 'undefined' || typeof global.DOMDocument === 'undefined') ? document : global.DOMDocument,
setContext: function(context) {
this._context = context;
},
openFileDialog: function(filter, multiple, workdir, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'open-file-dialog';
node.style = 'display: none';
if (typeof filter === 'function') {
fn = filter;
} else if (typeof filter === 'string') {
node.setAttribute('accept', filter);
} else if (typeof filter === 'boolean' && filter === true) {
node.setAttribute('multiple', '');
} else if (this.isArray(filter)) {
node.setAttribute('accept', filter.join(','));
}
if (typeof multiple === 'function') {
fn = multiple;
} else if (typeof multiple === 'string') {
node.setAttribute('nwworkingdir', multiple);
} else if (typeof multiple === 'boolean' && multiple === true) {
node.setAttribute('multiple', '');
}
if (typeof workdir === 'function') {
fn = workdir;
} else if (typeof workdir === 'string') {
node.setAttribute('nwworkingdir', workdir);
}
this._context.body.appendChild(node);
node.addEventListener('change', function(e) {
fn(node.value);
node.remove();
});
node.click();
},
saveFileDialog: function(name, accept, directory, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'save-file-dialog';
node.style = 'display: none';
node.setAttribute('nwsaveas', '');
if (typeof name === 'function') {
fn = name;
} else if (typeof name === 'string') {
node.setAttribute('nwsaveas', name);
}
if (typeof accept === 'function') {
fn = accept;
} else if (typeof accept === 'string') {
node.setAttribute('accept', accept);
} else if (this.isArray(accept)) {
node.setAttribute('accept', accept.join(','));
}
if (typeof directory === 'function') {
fn = directory;
} else if (typeof directory === 'string') {
node.setAttribute('nwworkingdir', directory);
}
this._context.body.appendChild(node);
node.addEventListener('change', function() {
fn(node.value);
node.remove();
});
node.click();
},
folderBrowserDialog: function(workdir, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'folder-browser-dialog';
node.style = 'display: none';
node.nwdirectory= true;
if (typeof workdir === 'function') {
fn = workdir
} else if (typeof workdir === 'string') {
node.setAttribute('nwworkingdir', workdir);
}
this._context.body.appendChild(node);
node.addEventListener('change', function() {
fn(node.value);
node.remove();
});
node.click();
},
isArray: function(value) {
return Object.prototype.toString.call(value) === '[object Array]';
}
}
if (typeof nw !== 'undefined') {
if (typeof exports == 'undefined') {
nw.Dialog = nwdialog;
window.dialog = nwdialog;
} else {
module.exports = nwdialog;
}
}

View file

@ -2,7 +2,7 @@ window.$ = window.jQuery = require('jquery'),
require('jquery-ui-dist/jquery-ui');
const { SerialPort } = require('serialport');
const path = require('path');
const { app } = require('@electron/remote');
const { app, dialog } = require('@electron/remote');
const ol = require('openlayers');
const Store = require('electron-store');
const store = new Store();

View file

@ -34,7 +34,7 @@
"serialport": "^12.0.0",
"inflection": "1.12.0",
"fs": "0.0.1-security",
"jquery": "2.1.4",
"jquery": "3.7.1",
"jquery-ui-dist": "1.12.1",
"marked": "^11.2.0",
"minimist": "^1.2.0",

View file

@ -69,49 +69,8 @@ function copyToClipboard(text) {
console.warn(ex);
}
function nwCopy(text) {
try {
let clipboard = require('nw.gui').Clipboard.get();
clipboard.set(text, "text");
onCopySuccessful();
} catch (ex) {
onCopyFailed(ex);
}
}
function webCopy(text) {
navigator.clipboard.writeText(text)
.then(onCopySuccessful, onCopyFailed);
}
let copyFunc;
try {
let nwGui = require('nw.gui');
copyFunc = nwCopy;
} catch (e) {
copyFunc = webCopy;
}
copyFunc(text);
}
function sendLinesWithDelay(outputArray) {
return (delay, line, index) => {
return new Promise((resolve) => {
helper.timeout.add('CLI_send_slowly', () => {
let processingDelay = TABS.cli.lineDelayMs;
if (line.toLowerCase().startsWith('profile')) {
processingDelay = TABS.cli.profileSwitchDelayMs;
}
const isLastCommand = outputArray.length === index + 1;
if (isLastCommand && TABS.cli.cliBuffer) {
line = getCliCommand(line, TABS.cli.cliBuffer);
}
TABS.cli.sendLine(line, () => {
resolve(processingDelay);
});
}, delay);
});
};
}
TABS.cli.initialize = function (callback) {
@ -136,16 +95,35 @@ TABS.cli.initialize = function (callback) {
return !(nwGui == null && !navigator.clipboard)
})();
function executeCommands(out_string) {
self.history.add(out_string.trim());
var outputArray = out_string.split("\n");
Promise.reduce(outputArray, sendLinesWithDelay(outputArray), 0);
return outputArray.reduce((p, line, index) =>
p.then((delay) =>
new Promise((resolve) => {
helper.timeout.add('CLI_send_slowly', () => {
let processingDelay = TABS.cli.lineDelayMs;
if (line.toLowerCase().startsWith('profile')) {
processingDelay = TABS.cli.profileSwitchDelayMs;
}
const isLastCommand = outputArray.length === index + 1;
if (isLastCommand && TABS.cli.cliBuffer) {
line = getCliCommand(line, TABS.cli.cliBuffer);
}
TABS.cli.sendLine(line, () => {
resolve(processingDelay);
});
}, delay);
})
), Promise.resolve(0),
);
}
GUI.load(path.join(__dirname, "tabs/cli.html"), function () {
// translate to user-selected language
localization.localize();;
localization.localize();
$('.cliDocsBtn').attr('href', globalSettings.docsTreeLocation + 'Settings.md');
@ -154,24 +132,21 @@ TABS.cli.initialize = function (callback) {
var textarea = $('.tab-cli textarea[name="commands"]');
$('.tab-cli .save').click(function() {
var prefix = 'cli';
var suffix = 'txt';
var filename = generateFilename(prefix, suffix);
var accepts = [{
description: suffix.toUpperCase() + ' files', extensions: [suffix],
}];
nwdialog.setContext(document);
nwdialog.saveFileDialog(filename, accepts, '', function(result) {
if (!result) {
var options = {
filters: [
{ name: 'CLI', extensions: ['cli'] } ,
{ name: 'TXT', extensions: ['txt'] }
],
};
dialog.showSaveDialog(options).then(result => {
if (result.canceled) {
GUI.log(localization.getMessage('cliSaveToFileAborted'));
return;
}
const fs = require('fs');
fs.writeFile(result, self.outputHistory, (err) => {
const fs = require('fs');
fs.writeFile(result.filePath , self.outputHistory, (err) => {
if (err) {
GUI.log(localization.getMessage('ErrorWritingFile'));
return console.error(err);
@ -179,6 +154,8 @@ TABS.cli.initialize = function (callback) {
GUI.log(localization.getMessage('FileSaved'));
});
}).catch (err => {
console.log(err);
});
});
@ -213,10 +190,15 @@ TABS.cli.initialize = function (callback) {
$('.tab-cli .copy').hide();
}
$('.tab-cli .load').click(function() {
nwdialog.setContext(document);
nwdialog.openFileDialog(".txt", false, '', function(result) {
if (!result) {
$('.tab-cli .load').on('click', () => {
var options = {
filters: [
{ name: 'CLI/TXT', extensions: ['cli', 'txt'] },
{ name: 'ALL', extensions: ['*'] }
],
};
dialog.showOpenDialog(options).then( result => {
if (result.canceled) {
console.log('No file selected');
return;
}
@ -247,9 +229,9 @@ TABS.cli.initialize = function (callback) {
self.GUI.snippetPreviewWindow.open();
}
if (result.filePaths.length == 1) {
const fs = require('fs');
fs.readFile(result, (err, data) => {
fs.readFile(result.filePaths[0], (err, data) => {
if (err) {
GUI.log(localization.getMessage('ErrorReadingFile'));
return console.error(err);
@ -257,6 +239,9 @@ TABS.cli.initialize = function (callback) {
previewCommands(data);
});
}
}).catch (err => {
console.log(err);
});
});
@ -289,8 +274,7 @@ TABS.cli.initialize = function (callback) {
self.outputHistory = "";
$('.tab-cli .window .wrapper').empty();
} else {
var outputArray = out_string.split("\n");
Promise.reduce(outputArray, sendLinesWithDelay(outputArray), 0);
executeCommands(out_string);
}
textarea.val('');