Skip to content

Commit

Permalink
Fix load of VTX Json scheme under PWA
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed Apr 12, 2024
1 parent d350d62 commit a8222dc
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 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,34 @@ 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();
}

// 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 if (isWeb()) {
import(`/resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`)
.catch(error => console.error('Error fetching VTX Schema:', error))
.then(schemaJson => validateAgainstSchema(schemaJson, vtxConfig));

} else {
const urlVtxSchema = chrome.runtime.getURL(`resources/jsonschema/vtxconfig_schema-${vtxConfig.version}.json`);
fetch(urlVtxSchema)
.then(response => response.json())
.catch(error => console.error('Error fetching VTX Schema:', error))
.then(schemaJson => {
.then(schemaJson => 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();
},
);
}

}

// Emulates the MSP read from a vtxConfig object (JSON)
Expand Down

0 comments on commit a8222dc

Please sign in to comment.