diff --git a/applications/system/js_app/modules/js_gui/byte_input.c b/applications/system/js_app/modules/js_gui/byte_input.c index 2e4096b28..5c8844d22 100644 --- a/applications/system/js_app/modules/js_gui/byte_input.c +++ b/applications/system/js_app/modules/js_gui/byte_input.c @@ -40,6 +40,13 @@ static bool UNUSED(input); context->buffer_size = (size_t)(value.number); context->buffer = realloc(context->buffer, context->buffer_size); //-V701 + byte_input_set_result_callback( + input, + (ByteInputCallback)input_callback, + NULL, + context, + context->buffer, + context->buffer_size); return true; } @@ -50,11 +57,12 @@ static bool default_data_assign( JsByteKbContext* context) { UNUSED(mjs); - if(mjs_is_data_view(value.array)) { - value.array = mjs_dataview_get_buf(mjs, value.array); + mjs_val_t array_buf = value.array; + if(mjs_is_data_view(array_buf)) { + array_buf = mjs_dataview_get_buf(mjs, array_buf); } size_t default_data_len = 0; - char* default_data = mjs_array_buf_get_ptr(mjs, value.array, &default_data_len); + char* default_data = mjs_array_buf_get_ptr(mjs, array_buf, &default_data_len); memcpy( context->buffer, (uint8_t*)default_data, @@ -71,7 +79,6 @@ static bool default_data_assign( } static JsByteKbContext* ctx_make(struct mjs* mjs, ByteInput* input, mjs_val_t view_obj) { - UNUSED(input); JsByteKbContext* context = malloc(sizeof(JsByteKbContext)); *context = (JsByteKbContext){ .buffer_size = DEFAULT_BUF_SZ, @@ -90,8 +97,13 @@ static JsByteKbContext* ctx_make(struct mjs* mjs, ByteInput* input, mjs_val_t vi .transformer_context = context, }, }; - UNUSED(mjs); - UNUSED(view_obj); + byte_input_set_result_callback( + input, + (ByteInputCallback)input_callback, + NULL, + context, + context->buffer, + context->buffer_size); mjs_set(mjs, view_obj, "input", ~0, mjs_mk_foreign(mjs, &context->contract)); return context; } diff --git a/applications/system/js_app/modules/js_gui/js_gui.c b/applications/system/js_app/modules/js_gui/js_gui.c index 011f404e9..4bd4ccc31 100644 --- a/applications/system/js_app/modules/js_gui/js_gui.c +++ b/applications/system/js_app/modules/js_gui/js_gui.c @@ -101,8 +101,10 @@ static void js_gui_vd_switch_to(struct mjs* mjs) { mjs_val_t view; JS_FETCH_ARGS_OR_RETURN(mjs, JS_EXACTLY, JS_ARG_OBJ(&view)); JsGuiViewData* view_data = JS_GET_INST(mjs, view); - JsGui* module = JS_GET_CONTEXT(mjs); + mjs_val_t vd_obj = mjs_get_this(mjs); + JsGui* module = JS_GET_INST(mjs, vd_obj); view_dispatcher_switch_to_view(module->dispatcher, (uint32_t)view_data->id); + mjs_set(mjs, vd_obj, "currentView", ~0, view); } static void* js_gui_create(struct mjs* mjs, mjs_val_t* object, JsModules* modules) { @@ -154,6 +156,7 @@ static void* js_gui_create(struct mjs* mjs, mjs_val_t* object, JsModules* module JS_FIELD("switchTo", MJS_MK_FN(js_gui_vd_switch_to)); JS_FIELD("custom", mjs_mk_foreign(mjs, &module->custom_contract)); JS_FIELD("navigation", mjs_mk_foreign(mjs, &module->navigation_contract)); + JS_FIELD("currentView", MJS_NULL); } // create API object 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 a43147e43..f68978e2d 100644 --- a/applications/system/js_app/modules/js_gui/text_input.c +++ b/applications/system/js_app/modules/js_gui/text_input.c @@ -9,6 +9,7 @@ typedef struct { char* buffer; size_t buffer_size; FuriString* header; + bool default_text_clear; FuriSemaphore* input_semaphore; JsEventLoopContract contract; } JsKbdContext; @@ -51,6 +52,13 @@ static bool max_len_assign( UNUSED(input); context->buffer_size = (size_t)(value.number + 1); context->buffer = realloc(context->buffer, context->buffer_size); //-V701 + text_input_set_result_callback( + input, + (TextInputCallback)input_callback, + context, + context->buffer, + context->buffer_size, + context->default_text_clear); return true; } @@ -64,6 +72,13 @@ static bool default_text_assign( if(value.string) { strlcpy(context->buffer, value.string, context->buffer_size); + text_input_set_result_callback( + input, + (TextInputCallback)input_callback, + context, + context->buffer, + context->buffer_size, + context->default_text_clear); } return true; } @@ -75,23 +90,24 @@ static bool default_text_clear_assign( JsKbdContext* context) { UNUSED(mjs); + context->default_text_clear = value.boolean; text_input_set_result_callback( input, (TextInputCallback)input_callback, context, context->buffer, context->buffer_size, - value.boolean); + context->default_text_clear); return true; } static JsKbdContext* ctx_make(struct mjs* mjs, TextInput* input, mjs_val_t view_obj) { - UNUSED(input); JsKbdContext* context = malloc(sizeof(JsKbdContext)); *context = (JsKbdContext){ .buffer_size = DEFAULT_BUF_SZ, .buffer = malloc(DEFAULT_BUF_SZ), .header = furi_string_alloc(), + .default_text_clear = false, .input_semaphore = furi_semaphore_alloc(1, 0), }; context->contract = (JsEventLoopContract){ @@ -105,8 +121,13 @@ static JsKbdContext* ctx_make(struct mjs* mjs, TextInput* input, mjs_val_t view_ .transformer_context = context, }, }; - UNUSED(mjs); - UNUSED(view_obj); + text_input_set_result_callback( + input, + (TextInputCallback)input_callback, + context, + context->buffer, + context->buffer_size, + context->default_text_clear); mjs_set(mjs, view_obj, "input", ~0, mjs_mk_foreign(mjs, &context->contract)); return context; } diff --git a/applications/system/js_app/types/gui/index.d.ts b/applications/system/js_app/types/gui/index.d.ts index 3f95ab780..85f191059 100644 --- a/applications/system/js_app/types/gui/index.d.ts +++ b/applications/system/js_app/types/gui/index.d.ts @@ -20,6 +20,10 @@ declare class ViewDispatcher { * Event source for navigation events (back key presses) */ navigation: Contract; + /** + * View object currently shown + */ + currentView: View; /** * Sends a number to the custom event handler * @param event number to send