diff --git a/src/resources/jsonschema/vtxconfig_schema-1.0.json b/resources/jsonschema/vtxconfig_schema-1.0.json similarity index 97% rename from src/resources/jsonschema/vtxconfig_schema-1.0.json rename to resources/jsonschema/vtxconfig_schema-1.0.json index 35c03e61e0..c39cbeab25 100644 --- a/src/resources/jsonschema/vtxconfig_schema-1.0.json +++ b/resources/jsonschema/vtxconfig_schema-1.0.json @@ -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", diff --git a/src/js/Clipboard.js b/src/js/Clipboard.js index 16b5a6671f..7e6723151b 100644 --- a/src/js/Clipboard.js +++ b/src/js/Clipboard.js @@ -1,4 +1,5 @@ import GUI from './gui.js'; +import { isWeb } from "./utils/isWeb"; /** * Encapsulates the Clipboard logic, depending on web or nw @@ -75,6 +76,31 @@ Clipboard._configureClipboardAsCordova = function() { }; +Clipboard._configureClipboardAsWeb = function() { + + console.log('Web Clipboard available'); + + this.available = true; + this.readAvailable = true; + this.writeAvailable = true; + + this.writeText = function(text, onSuccess, onError) { + + navigator.clipboard.writeText(text).then( + () => onSuccess?.(text), + onError, + ); + }; + + this.readText = function(onSuccess, onError) { + + navigator.clipboard.readText().then( + (text) => onSuccess?.(text), + onError, + ); + }; +}; + Clipboard._configureClipboardAsOther = function() { console.warn('NO Clipboard available'); @@ -96,6 +122,8 @@ if (GUI.isNWJS()){ Clipboard._configureClipboardAsNwJs(GUI.nwGui); } else if (GUI.isCordova()) { Clipboard._configureClipboardAsCordova(); +} else if (isWeb()) { + Clipboard._configureClipboardAsWeb(); } else { Clipboard._configureClipboardAsOther(); } diff --git a/src/js/tabs/vtx.js b/src/js/tabs/vtx.js index 585de96ffe..02a046897f 100644 --- a/src/js/tabs/vtx.js +++ b/src/js/tabs/vtx.js @@ -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 = { @@ -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)