mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2025-10-10 23:22:35 +02:00
* 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>
88 lines
2.9 KiB
C
88 lines
2.9 KiB
C
#include "../../js_modules.h" // IWYU pragma: keep
|
|
#include "js_gui.h"
|
|
#include "../js_event_loop/js_event_loop.h"
|
|
#include <gui/modules/submenu.h>
|
|
|
|
#define QUEUE_LEN 2
|
|
|
|
typedef struct {
|
|
FuriMessageQueue* queue;
|
|
JsEventLoopContract contract;
|
|
} JsSubmenuCtx;
|
|
|
|
static mjs_val_t choose_transformer(struct mjs* mjs, FuriMessageQueue* queue, void* context) {
|
|
UNUSED(context);
|
|
uint32_t index;
|
|
furi_check(furi_message_queue_get(queue, &index, 0) == FuriStatusOk);
|
|
return mjs_mk_number(mjs, (double)index);
|
|
}
|
|
|
|
void choose_callback(void* context, uint32_t index) {
|
|
JsSubmenuCtx* ctx = context;
|
|
furi_check(furi_message_queue_put(ctx->queue, &index, 0) == FuriStatusOk);
|
|
}
|
|
|
|
static bool
|
|
header_assign(struct mjs* mjs, Submenu* submenu, JsViewPropValue value, void* context) {
|
|
UNUSED(mjs);
|
|
UNUSED(context);
|
|
submenu_set_header(submenu, value.string);
|
|
return true;
|
|
}
|
|
|
|
static bool items_assign(struct mjs* mjs, Submenu* submenu, JsViewPropValue value, void* context) {
|
|
UNUSED(mjs);
|
|
submenu_reset(submenu);
|
|
size_t len = mjs_array_length(mjs, value.term);
|
|
for(size_t i = 0; i < len; i++) {
|
|
mjs_val_t item = mjs_array_get(mjs, value.term, i);
|
|
if(!mjs_is_string(item)) return false;
|
|
submenu_add_item(submenu, mjs_get_string(mjs, &item, NULL), i, choose_callback, context);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static JsSubmenuCtx* ctx_make(struct mjs* mjs, Submenu* input, mjs_val_t view_obj) {
|
|
UNUSED(input);
|
|
JsSubmenuCtx* context = malloc(sizeof(JsSubmenuCtx));
|
|
context->queue = furi_message_queue_alloc(QUEUE_LEN, sizeof(uint32_t));
|
|
context->contract = (JsEventLoopContract){
|
|
.magic = JsForeignMagic_JsEventLoopContract,
|
|
.object_type = JsEventLoopObjectTypeQueue,
|
|
.object = context->queue,
|
|
.non_timer =
|
|
{
|
|
.event = FuriEventLoopEventIn,
|
|
.transformer = (JsEventLoopTransformer)choose_transformer,
|
|
},
|
|
};
|
|
mjs_set(mjs, view_obj, "chosen", ~0, mjs_mk_foreign(mjs, &context->contract));
|
|
return context;
|
|
}
|
|
|
|
static void ctx_destroy(Submenu* input, JsSubmenuCtx* context, FuriEventLoop* loop) {
|
|
UNUSED(input);
|
|
furi_event_loop_maybe_unsubscribe(loop, context->queue);
|
|
furi_message_queue_free(context->queue);
|
|
free(context);
|
|
}
|
|
|
|
static const JsViewDescriptor view_descriptor = {
|
|
.alloc = (JsViewAlloc)submenu_alloc,
|
|
.free = (JsViewFree)submenu_free,
|
|
.get_view = (JsViewGetView)submenu_get_view,
|
|
.custom_make = (JsViewCustomMake)ctx_make,
|
|
.custom_destroy = (JsViewCustomDestroy)ctx_destroy,
|
|
.prop_cnt = 2,
|
|
.props = {
|
|
(JsViewPropDescriptor){
|
|
.name = "header",
|
|
.type = JsViewPropTypeString,
|
|
.assign = (JsViewPropAssign)header_assign},
|
|
(JsViewPropDescriptor){
|
|
.name = "items",
|
|
.type = JsViewPropTypeArr,
|
|
.assign = (JsViewPropAssign)items_assign},
|
|
}};
|
|
JS_GUI_VIEW_DEF(submenu, &view_descriptor);
|