1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

JS: Backport³ and more additions & fixes (#3961)

* JS: Fix file select for fbt launch js_app
* JS: badusb: Add numpad keys
  Co-authored-by: oldip <oldip@users.noreply.github.com>
* JS: badusb: Layout support
* JS: badusb: altPrint() and altPrintln()
  Co-authored-by: oldip <oldip@users.noreply.github.com>
* JS: badusb: quit()
* JS: serial: readAny()
* JS: serial: end()
* JS: serial: Auto disable expansion service
* JS: storage: Add example script
* JS: gui: text_input: Fix NULL ptr when no prop given
* JS: gui: text_input: Default text props
  Co-authored-by: xMasterX <xMasterX@users.noreply.github.com>
* JS: gui: byte_input
  Co-authored-by: xMasterX <xMasterX@users.noreply.github.com>
* JS: gui: file_picker
* JS: gui: viewDispatcher.currentView
* JS: gui: view.hasProperty()
* JS: gui: Add some missing typedefs comments
* JS: globals: Fix toString() with negative numbers
* JS: globals: parseInt()
  Co-authored-by: Spooks4576 <Spooks4576@users.noreply.github.com>
* JS: globals: toUpperCase() and toLowerCase()
  Co-authored-by: Spooks4576 <Spooks4576@users.noreply.github.com>
* JS: globals: Add some missing typedefs
* JS: Add example for string functions
  Co-authored-by: Spooks4576 <Spooks4576@users.noreply.github.com>
* JS: globals: __dirpath and __filepath
  Co-authored-by: jamisonderek <jamisonderek@users.noreply.github.com>
* JS: globals: load() typedef missing scope param
* JS: Add interactive REPL script example
* JS: Add missing icon for file picker
* JS: Rename to __filename and __dirname
* JS: Move toUpperCase() and toLowerCase() to string class
* JS: parseInt() refactor
* JS: Typedef base param for parseInt()
* Revert "JS: gui: view.hasProperty()"
  This reverts commit 1967ec06d4f2e9cafc4e18384ad370f7a7c44468.
* JS: Move toString() to Number class
* JS: Fix duplicate plugin files
  in plugins, `requires` is used to determine which app to distribute the .fal under `apps_data/appid/plugins`
* JS: math: Missing typedefs, use camelCase
* JS: badusb: layoutPath is optional in typedef
* Fix ASS scoping
* Rename mjs term prop type value
* Change load() description
* Enlarge buffers in default prop assign
* More checks for default data/text size
* Make PVS happy
* Fix icon symbol
* Update types for JS SDK
* toString() was moved to number class

Co-authored-by: oldip <oldip@users.noreply.github.com>
Co-authored-by: xMasterX <xMasterX@users.noreply.github.com>
Co-authored-by: Spooks4576 <Spooks4576@users.noreply.github.com>
Co-authored-by: jamisonderek <jamisonderek@users.noreply.github.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
WillyJL
2024-10-31 05:22:05 +00:00
committed by GitHub
parent 1907f23e5f
commit c807ffc324
35 changed files with 1049 additions and 74 deletions

View File

@@ -1,5 +1,7 @@
#include <common/cs_dbg.h>
#include <toolbox/path.h>
#include <toolbox/stream/file_stream.h>
#include <toolbox/strint.h>
#include <loader/firmware_api/firmware_api.h>
#include <flipper_application/api_hashtable/api_hashtable.h>
#include <flipper_application/plugins/composite_resolver.h>
@@ -194,6 +196,27 @@ static void js_require(struct mjs* mjs) {
mjs_return(mjs, req_object);
}
static void js_parse_int(struct mjs* mjs) {
const char* str;
JS_FETCH_ARGS_OR_RETURN(mjs, JS_AT_LEAST, JS_ARG_STR(&str));
int32_t base = 10;
if(mjs_nargs(mjs) >= 2) {
mjs_val_t base_arg = mjs_arg(mjs, 1);
if(!mjs_is_number(base_arg)) {
mjs_prepend_errorf(mjs, MJS_BAD_ARGS_ERROR, "Base must be a number");
mjs_return(mjs, MJS_UNDEFINED);
}
base = mjs_get_int(mjs, base_arg);
}
int32_t num;
if(strint_to_int32(str, NULL, &num, base) != StrintParseNoError) {
num = 0;
}
mjs_return(mjs, mjs_mk_number(mjs, num));
}
static void js_global_to_string(struct mjs* mjs) {
int base = 10;
if(mjs_nargs(mjs) > 1) base = mjs_get_int(mjs, mjs_arg(mjs, 1));
@@ -233,10 +256,30 @@ static int32_t js_thread(void* arg) {
mjs_val_t global = mjs_get_global(mjs);
mjs_val_t console_obj = mjs_mk_object(mjs);
if(worker->path) {
FuriString* dirpath = furi_string_alloc();
path_extract_dirname(furi_string_get_cstr(worker->path), dirpath);
mjs_set(
mjs,
global,
"__filename",
~0,
mjs_mk_string(
mjs, furi_string_get_cstr(worker->path), furi_string_size(worker->path), true));
mjs_set(
mjs,
global,
"__dirname",
~0,
mjs_mk_string(mjs, furi_string_get_cstr(dirpath), furi_string_size(dirpath), true));
furi_string_free(dirpath);
}
JS_ASSIGN_MULTI(mjs, global) {
JS_FIELD("print", MJS_MK_FN(js_print));
JS_FIELD("delay", MJS_MK_FN(js_delay));
JS_FIELD("toString", MJS_MK_FN(js_global_to_string));
JS_FIELD("parseInt", MJS_MK_FN(js_parse_int));
JS_FIELD("ffi_address", MJS_MK_FN(js_ffi_address));
JS_FIELD("require", MJS_MK_FN(js_require));
JS_FIELD("console", console_obj);