diff --git a/applications/system/js_app/js_thread.c b/applications/system/js_app/js_thread.c
index d552b7ce3..600c2676e 100644
--- a/applications/system/js_app/js_thread.c
+++ b/applications/system/js_app/js_thread.c
@@ -246,10 +246,29 @@ 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);
diff --git a/applications/system/js_app/modules/js_gui/text_input.c b/applications/system/js_app/modules/js_gui/text_input.c
index 38dabb488..72dc90658 100644
--- a/applications/system/js_app/modules/js_gui/text_input.c
+++ b/applications/system/js_app/modules/js_gui/text_input.c
@@ -85,7 +85,7 @@ static bool default_text_assign(
context->buffer = realloc(context->buffer, context->buffer_size); //-V701
}
// Also trim excess previous data with strlcpy()
- strlcpy(context->buffer, value.string, context->buffer_size);
+ strlcpy(context->buffer, value.string, context->buffer_size); //-V575
text_input_set_result_callback(
input,
(TextInputCallback)input_callback,
diff --git a/applications/system/js_app/packages/fz-sdk/badusb/index.d.ts b/applications/system/js_app/packages/fz-sdk/badusb/index.d.ts
index 4d06e2b6a..3eca288c2 100644
--- a/applications/system/js_app/packages/fz-sdk/badusb/index.d.ts
+++ b/applications/system/js_app/packages/fz-sdk/badusb/index.d.ts
@@ -100,6 +100,7 @@ export declare function println(string: string, delay?: number): void;
* @brief Prints a string by Alt+Numpad method - works only on Windows!
* @param string The string to print
* @param delay How many milliseconds to wait between key presses
+ * @version Added in JS SDK 0.1
*/
export declare function altPrint(string: string, delay?: number): void;
@@ -108,10 +109,12 @@ export declare function altPrint(string: string, delay?: number): void;
* Presses "Enter" after printing the string
* @param string The string to print
* @param delay How many milliseconds to wait between key presses
+ * @version Added in JS SDK 0.1
*/
export declare function altPrintln(string: string, delay?: number): void;
/**
* @brief Releases usb, optional, but allows to switch usb profile
+ * @version Added in JS SDK 0.1
*/
export declare function quit(): void;
diff --git a/applications/system/js_app/packages/fz-sdk/global.d.ts b/applications/system/js_app/packages/fz-sdk/global.d.ts
index 0c40f0c48..953afc30d 100644
--- a/applications/system/js_app/packages/fz-sdk/global.d.ts
+++ b/applications/system/js_app/packages/fz-sdk/global.d.ts
@@ -149,14 +149,6 @@ declare function delay(ms: number): void;
*/
declare function print(...args: any[]): void;
-/**
- * @brief Converts a number to a string
- * @param value The number to convert to a string
- * @param base Integer base (`2`...`16`), default: 10
- * @version Added in JS SDK 0.1
- */
-declare function toString(value: number, base?: number): string;
-
/**
* @brief Reads a JS value from a file
*
@@ -327,13 +319,44 @@ declare class String {
* @version Added in JS SDK 0.1
*/
at(index: number): number;
+ /**
+ * @brief Return index of first occurrence of substr within the string or `-1` if not found
+ * @param substr The string to search for
+ * @param fromIndex The index to start searching from
+ * @version Added in JS SDK 0.1
+ */
+ indexOf(substr: string, fromIndex?: number): number;
+ /**
+ * @brief Return a substring between two indices
+ * @param start The index to start substring at
+ * @param end The index to end substring at
+ * @version Added in JS SDK 0.1
+ */
+ slice(start: number, end?: number): string;
+ /**
+ * @brief Return this string transformed to upper case
+ * @version Added in JS SDK 0.1
+ */
+ toUpperCase(): string;
+ /**
+ * @brief Return this string transformed to lower case
+ * @version Added in JS SDK 0.1
+ */
+ toLowerCase(): string;
}
declare class Boolean { }
declare class Function { }
-declare class Number { }
+declare class Number {
+ /**
+ * @brief Converts this number to a string
+ * @param base Integer base (`2`...`16`), default: 10
+ * @version Added in JS SDK 0.1
+ */
+ toString(base?: number): string;
+}
declare class Object { }
diff --git a/applications/system/js_app/packages/fz-sdk/gui/byte_input.d.ts b/applications/system/js_app/packages/fz-sdk/gui/byte_input.d.ts
new file mode 100644
index 000000000..5556e7fbb
--- /dev/null
+++ b/applications/system/js_app/packages/fz-sdk/gui/byte_input.d.ts
@@ -0,0 +1,41 @@
+/**
+ * Displays a byte input keyboard.
+ *
+ *
+ *
+ * ```js
+ * let eventLoop = require("event_loop");
+ * let gui = require("gui");
+ * let byteInputView = require("gui/byte_input");
+ * ```
+ *
+ * This module depends on the `gui` module, which in turn depends on the
+ * `event_loop` module, so they _must_ be imported in this order. It is also
+ * recommended to conceptualize these modules first before using this one.
+ *
+ * # Example
+ * For an example refer to the `gui.js` example script.
+ *
+ * # View props
+ * - `header`: Text displayed at the top of the screen
+ * - `length`: Length of data to edit
+ * - `defaultData`: Data to show by default
+ *
+ * @version Added in JS SDK 0.1
+ * @module
+ */
+
+import type { View, ViewFactory } from ".";
+import type { Contract } from "../event_loop";
+
+type Props = {
+ header: string,
+ length: number,
+ defaultData: Uint8Array | ArrayBuffer,
+}
+declare class ByteInput extends View {
+ input: Contract;
+}
+declare class ByteInputFactory extends ViewFactory { }
+declare const factory: ByteInputFactory;
+export = factory;
diff --git a/applications/system/js_app/packages/fz-sdk/gui/file_picker.d.ts b/applications/system/js_app/packages/fz-sdk/gui/file_picker.d.ts
new file mode 100644
index 000000000..9447f89a9
--- /dev/null
+++ b/applications/system/js_app/packages/fz-sdk/gui/file_picker.d.ts
@@ -0,0 +1,7 @@
+/**
+ * @brief Displays a file picker and returns the selected file, or undefined if cancelled
+ * @param basePath The path to start at
+ * @param extension The file extension(s) to show (like `.sub`, `.iso|.img`, `*`)
+ * @version Added in JS SDK 0.1
+ */
+export declare function pickFile(basePath: string, extension: string): string | undefined;
diff --git a/applications/system/js_app/packages/fz-sdk/gui/text_input.d.ts b/applications/system/js_app/packages/fz-sdk/gui/text_input.d.ts
index 2c890df57..5d64b038b 100644
--- a/applications/system/js_app/packages/fz-sdk/gui/text_input.d.ts
+++ b/applications/system/js_app/packages/fz-sdk/gui/text_input.d.ts
@@ -1,5 +1,5 @@
/**
- * Displays a keyboard.
+ * Displays a text input keyboard.
*
*
*
@@ -20,6 +20,8 @@
* - `header`: Text displayed at the top of the screen
* - `minLength`: Minimum allowed text length
* - `maxLength`: Maximum allowed text length
+ * - `defaultText`: Text to show by default
+ * - `defaultTextClear`: Whether to clear the default text on next character typed
*
* @version Added in JS SDK 0.1
* @module
@@ -32,6 +34,8 @@ type Props = {
header: string,
minLength: number,
maxLength: number,
+ defaultText: string,
+ defaultTextClear: boolean,
}
declare class TextInput extends View {
input: Contract;
diff --git a/applications/system/js_app/packages/fz-sdk/math/index.d.ts b/applications/system/js_app/packages/fz-sdk/math/index.d.ts
index ff84cdcb0..67c805db5 100644
--- a/applications/system/js_app/packages/fz-sdk/math/index.d.ts
+++ b/applications/system/js_app/packages/fz-sdk/math/index.d.ts
@@ -4,6 +4,8 @@
* @module
*/
+/** @version Added in JS SDK 0.1 */
+export function isEqual(a: number, b: number, tolerance: number): boolean;
/** @version Added in JS SDK 0.1 */
export function abs(n: number): number;
/** @version Added in JS SDK 0.1 */
@@ -33,6 +35,8 @@ export function exp(n: number): number;
/** @version Added in JS SDK 0.1 */
export function floor(n: number): number;
/** @version Added in JS SDK 0.1 */
+export function log(n: number): number;
+/** @version Added in JS SDK 0.1 */
export function max(n: number, m: number): number;
/** @version Added in JS SDK 0.1 */
export function min(n: number, m: number): number;
@@ -51,4 +55,6 @@ export function trunc(n: number): number;
/** @version Added in JS SDK 0.1 */
declare const PI: number;
/** @version Added in JS SDK 0.1 */
+declare const E: number;
+/** @version Added in JS SDK 0.1 */
declare const EPSILON: number;
diff --git a/applications/system/js_app/packages/fz-sdk/serial/index.d.ts b/applications/system/js_app/packages/fz-sdk/serial/index.d.ts
index 9e2b9c080..3c249352e 100644
--- a/applications/system/js_app/packages/fz-sdk/serial/index.d.ts
+++ b/applications/system/js_app/packages/fz-sdk/serial/index.d.ts
@@ -65,6 +65,7 @@ export declare function readln(timeout?: number): string;
* wait forever.
* @returns The received data interpreted as ASCII, or `undefined` if 0 bytes
* were read.
+ * @version Added in JS SDK 0.1
*/
export declare function readAny(timeout?: number): string | undefined;
@@ -106,5 +107,6 @@ export declare function expect(patterns: string | number[] | string[] | number[]
/**
* @brief Deinitializes the serial port, allowing multiple initializations per script run
+ * @version Added in JS SDK 0.1
*/
export declare function end(): void;