Skip to content

Latest commit

 

History

History
72 lines (58 loc) · 2.2 KB

EXTENSIONS.md

File metadata and controls

72 lines (58 loc) · 2.2 KB

Trndi Extensions

This list is currently incomplete! Trndi supports extensions, written in JavaScript.

You can declare functions inside Trndi and expose them to JS, or "listen" for functions in Trndi.

Trndi supports promises and async code! See the guide for information on how to install them.

Basics

alert("Alert-test!");

Shows a pop-up

This triggers JsDoAlert() in trndi.ext.jsbase.inc

console.log("log-test")

Creates a log popup.

This triggers JSConsoleLog() in trndi.ext.functions.pp }

Advanced

uxProp

Modifies the Trndi UX

Promises

bgDump

Directly inputs a query to the backend, to get recent readings. (min: int, max: int)

This triggers TJSFuncs.bgDump() in trndi.ext.jsfuncs.pp }

asyncGet

Fetches a URL and returns the data. (url: string)

This triggers TJSFuncs.asyncGet() in trndi.ext.jsfuncs.pp }

querySvc

Allows for a direct, unfiltered, query to the backend service

Callbacks

uxCallback

Triggers when a uxProp has completed.

Returns array: [component, value:string]

Demo

NOTE: There is full ES2023 language support.

Trndi creates the TrndiExtension object.

// Get a file and display the result in the GUI
asyncGet("https://sample-files.com/downloads/documents/txt/simple.txt")
  .then(result => console.log(result))
  .catch(error => console.log(`Error: ${error}`));

// Display a GUI update
 function uxCallback(a,b){
 alert(`Changed: ${a} with ${b}`);
}

// Change element colors
function color(){
  // Change a UX property of the main form
  uxProp('ldiff', 'font-color', '#000000');
  uxProp('ldiff', 'font', 'Comic Sans');
}

color();

Run something

This is a theoretical command, I havent tested it:

runCMD("app", `-v;--url;"smtps://smtp.gmail.com:465";--mail-from;[email protected]";--mail-rcpt;"[email protected]";--mail-data;"Email";--user;"[email protected]:APP-PASSWORD"`, ";").then(result => console.log(result))
  .catch(error => console.log(`Error: ${error}`));

As you see spaces are replaced with ";" to allow spaces inside params. The last parameter actually defines where to split the paraneters. you can use `${X}" to pass data, if calling from a callback eg