Skip to content

Commit

Permalink
Fix VTX table read from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed Apr 13, 2024
1 parent 8786553 commit 0fa12c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/js/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Clipboard._configureClipboardAsWeb = function() {
this.readText = function(onSuccess, onError) {

navigator.clipboard.readText().then(
() => onSuccess?.(text),
(text) => onSuccess?.(text),
onError,
);
};
Expand Down
33 changes: 17 additions & 16 deletions src/js/tabs/vtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { API_VERSION_1_42, API_VERSION_1_44 } from '../data_storage';
import UI_PHONES from "../phones_ui";
import { gui_log } from "../gui_log";
import { checkChromeRuntimeError } from "../utils/common";
import { isWeb } from "../utils/isWeb";
import $ from 'jquery';

const vtx = {
Expand Down Expand Up @@ -171,30 +172,30 @@ vtx.initialize = function (callback) {
callback_error();
}

// Load schema
const urlVtxSchema = chrome.runtime.getURL(`resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`);
function validateAgainstSchema(schemaJson, vtxConfig) {
let valid = false;
if (schemaJson !== undefined) {
// Validate
valid = (TABS.vtx.env.validate(schemaJson, vtxConfig) === undefined);
}

console.log("Validation against schema result:", valid);
valid ? callback_valid() : callback_error();
}

const vtxJsonSchemaUrl = `../../resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`;

// Load schema depending on the system
if (GUI.isCordova()) {
// FIXME On android : Fetch API cannot load : URL scheme "file" is not supported
callback_valid();
} else {
fetch(urlVtxSchema)
let vtxJsonSchemaUrl2Fetch = isWeb() ? vtxJsonSchemaUrl : chrome.runtime.getURL(vtxJsonSchemaUrl);
fetch(vtxJsonSchemaUrl2Fetch)
.then(response => response.json())
.catch(error => console.error('Error fetching VTX Schema:', error))
.then(schemaJson => {

let valid = false;
if (schemaJson !== undefined) {
// Validate
valid = (TABS.vtx.env.validate(schemaJson, vtxConfig) === undefined);
}

console.log("Validation against schema result:", valid);
valid ? callback_valid() : callback_error();
},
);
.then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig));
}

}

// Emulates the MSP read from a vtxConfig object (JSON)
Expand Down
4 changes: 2 additions & 2 deletions src/resources/jsonschema/vtxconfig_schema-1.0.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"$id": "http://betaflight.com/vtxconfig_schema-1.0.json",
"type": "object",
"title": "The Root Schema",
"title": "Betaflight VTX Table JSON Schema",
"required": [
"description",
"version",
Expand Down
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default defineConfig({
serveLocalesPlugin(),
copy({
targets: [
{ src: ["locales", "resources", "src/tabs", "src/images"], dest: "src/dist" },
{ src: ["locales", "resources", "src/tabs", "src/images", "src/resources"], dest: "src/dist" },
],
hook: "writeBundle",
}),
Expand Down

0 comments on commit 0fa12c3

Please sign in to comment.