merge missing js backports of backports by Willy-JL

p1
This commit is contained in:
MX 2024-10-16 12:03:31 +03:00
parent 2aff3bca73
commit 63d1890156
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
10 changed files with 93 additions and 12 deletions

View file

@ -337,9 +337,9 @@ static int32_t js_thread(void* arg) {
mjs_set(mjs, global, "toString", ~0, MJS_MK_FN(js_global_to_string));
mjs_set(mjs, global, "ffi_address", ~0, MJS_MK_FN(js_ffi_address));
mjs_set(mjs, global, "require", ~0, MJS_MK_FN(js_require));
mjs_set(mjs, global, "parse_int", ~0, MJS_MK_FN(js_parse_int));
mjs_set(mjs, global, "to_upper_case", ~0, MJS_MK_FN(js_to_upper_case));
mjs_set(mjs, global, "to_lower_case", ~0, MJS_MK_FN(js_to_lower_case));
mjs_set(mjs, global, "parseInt", ~0, MJS_MK_FN(js_parse_int));
mjs_set(mjs, global, "toUpperCase", ~0, MJS_MK_FN(js_to_upper_case));
mjs_set(mjs, global, "toLowerCase", ~0, MJS_MK_FN(js_to_lower_case));
mjs_val_t console_obj = mjs_mk_object(mjs);
mjs_set(mjs, console_obj, "log", ~0, MJS_MK_FN(js_console_log));

View file

@ -104,7 +104,7 @@ static bool setup_parse_params(
mjs_val_t pid_obj = mjs_get(mjs, arg, "pid", ~0);
mjs_val_t mfr_obj = mjs_get(mjs, arg, "mfrName", ~0);
mjs_val_t prod_obj = mjs_get(mjs, arg, "prodName", ~0);
mjs_val_t layout_obj = mjs_get(mjs, arg, "layout_path", ~0);
mjs_val_t layout_obj = mjs_get(mjs, arg, "layoutPath", ~0);
if(mjs_is_number(vid_obj) && mjs_is_number(pid_obj)) {
hid_cfg->vid = mjs_get_int32(mjs, vid_obj);

View file

@ -282,6 +282,11 @@ static void js_subghz_transmit_file(struct mjs* mjs) {
break;
}
if(!subghz_devices_is_frequency_valid(js_subghz->radio_device, frequency)) {
mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Unsupported frequency");
break;
}
if(!flipper_format_read_string(fff_file, "Preset", temp_str)) {
mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Preset");
break;

View file

@ -144,10 +144,10 @@ static void js_vgm_destroy(void* inst) {
}
static const JsModuleDescriptor js_vgm_desc = {
name: "vgm",
create: js_vgm_create,
destroy: js_vgm_destroy,
api_interface: NULL,
"vgm",
js_vgm_create,
js_vgm_destroy,
NULL,
};
static const FlipperAppPluginDescriptor plugin_descriptor = {

View file

@ -866,7 +866,6 @@ static void* js_widget_create(struct mjs* mjs, mjs_val_t* object, JsModules* mod
widget->view_holder = view_holder_alloc();
view_holder_attach_to_gui(widget->view_holder, gui);
view_holder_set_back_callback(widget->view_holder, widget_exit, widget);
view_holder_set_view(widget->view_holder, widget->view);
*object = widget_obj;
return widget;

View file

@ -32,9 +32,12 @@ export type KeyCode = MainKey | ModifierKey | number;
/**
* @brief Initializes the module
*
* Automatically unlocks USB profile, so qFlipper connection will be interrupted.
*
* @param settings USB device settings. Omit to select default parameters
*/
export declare function setup(settings?: { vid: number, pid: number, mfrName?: string, prodName?: string, layout_path: string }): void;
export declare function setup(settings?: { vid: number, pid: number, mfrName?: string, prodName?: string, layoutPath: string }): void;
/**
* @brief Tells whether the virtual USB HID device has successfully connected
@ -83,10 +86,19 @@ 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
*/
export declare function altPrintln(string: string): void;
export declare function altPrint(string: string, delay?: number): void;
/**
* @brief Releases usb, Optional, but allows to interchange with usbdisk
* @brief Prints a string by Alt+Numpad method - works only on Windows!
* Presses "Enter" after printing the string
* @param string The string to print
* @param delay How many milliseconds to wait between key presses
*/
export declare function altPrintln(string: string, delay?: number): void;
/**
* @brief Releases usb, optional, but allows to interchange with usbdisk
*/
export declare function quit(): void;

View file

@ -18,6 +18,34 @@ declare function print(...args: any[]): void;
*/
declare function toString(value: number, base?: number): string;
/**
* @brief Converts a string to a number
* @param text The string to convert to a number
*/
declare function parseInt(text: string): number;
/**
* @brief Transforms a string to upper case
* @param text The string to transforms to upper case
*/
declare function toUpperCase(text: string): string;
/**
* @brief Transforms a string to lower case
* @param text The string to transforms to lower case
*/
declare function toLowerCase(text: string): string;
/**
* @brief Path to the directory containing the current script
*/
declare const __dirpath: string;
/**
* @brief Path to the current script file
*/
declare const __filepath: string;
/**
* @brief Reads a JS value from a file
*

View file

@ -0,0 +1,14 @@
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<Props> {
input: Contract<string>;
}
declare class ByteInputFactory extends ViewFactory<Props, ByteInput> { }
declare const factory: ByteInputFactory;
export = factory;

View file

@ -5,6 +5,8 @@ type Props = {
header: string,
minLength: number,
maxLength: number,
defaultText: string,
defaultTextClear: boolean,
}
declare class TextInput extends View<Props> {
input: Contract<string>;

View file

@ -1,5 +1,8 @@
/**
* @brief Initializes the serial port
*
* Automatically disables Expansion module service to prevent interference.
*
* @param port The port to initialize (`"lpuart"` or `"start"`)
* @param baudRate
*/
@ -42,6 +45,19 @@ export declare function read(length: number, timeout?: number): string | undefin
*/
export declare function readln(timeout?: number): string;
/**
* @brief Read any available amount of data from the serial port
*
* Can be useful to avoid starving your loop with small reads.
*
* @param timeout The number of time, in milliseconds, after which this function
* will give up and return nothing. If unset, the function will
* wait forever.
* @returns The received data interpreted as ASCII, or `undefined` if 0 bytes
* were read.
*/
export declare function readAny(timeout?: number): string | undefined;
/**
* @brief Reads data from the serial port
* @param length The number of bytes to read
@ -75,3 +91,8 @@ export declare function readBytes(length: number, timeout?: number): ArrayBuffer
* patterns matched.
*/
export declare function expect(patterns: string | number[] | string[] | number[][], timeout?: number): number | undefined;
/**
* @brief Deinitializes the serial port, allowing multiple initializations per script run
*/
export declare function end(): void;