mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
merge js stuff
by Willy-JL
This commit is contained in:
@@ -90,6 +90,14 @@ App(
|
||||
sources=["modules/js_gui/dialog.c"],
|
||||
)
|
||||
|
||||
App(
|
||||
appid="js_gui__file_picker",
|
||||
apptype=FlipperAppType.PLUGIN,
|
||||
entry_point="js_gui_file_picker_ep",
|
||||
requires=["js_app"],
|
||||
sources=["modules/js_gui/file_picker.c"],
|
||||
)
|
||||
|
||||
App(
|
||||
appid="js_notification",
|
||||
apptype=FlipperAppType.PLUGIN,
|
||||
|
||||
@@ -198,7 +198,7 @@ static void js_require(struct mjs* mjs) {
|
||||
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));
|
||||
double num = mjs_get_int(mjs, mjs_arg(mjs, 0));
|
||||
double num = mjs_get_double(mjs, mjs_arg(mjs, 0));
|
||||
char tmp_str[] = "-2147483648";
|
||||
itoa(num, tmp_str, base);
|
||||
mjs_val_t ret = mjs_mk_string(mjs, tmp_str, ~0, true);
|
||||
|
||||
47
applications/system/js_app/modules/js_gui/file_picker.c
Normal file
47
applications/system/js_app/modules/js_gui/file_picker.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "../../js_modules.h"
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <assets_icons.h>
|
||||
|
||||
static void js_gui_file_picker_pick_file(struct mjs* mjs) {
|
||||
const char *base_path, *extension;
|
||||
JS_FETCH_ARGS_OR_RETURN(mjs, JS_EXACTLY, JS_ARG_STR(&base_path), JS_ARG_STR(&extension));
|
||||
|
||||
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
const DialogsFileBrowserOptions browser_options = {
|
||||
.extension = extension,
|
||||
.icon = &I_file_10px,
|
||||
.base_path = base_path,
|
||||
};
|
||||
FuriString* path = furi_string_alloc_set(base_path);
|
||||
if(dialog_file_browser_show(dialogs, path, path, &browser_options)) {
|
||||
mjs_return(mjs, mjs_mk_string(mjs, furi_string_get_cstr(path), ~0, true));
|
||||
} else {
|
||||
mjs_return(mjs, MJS_UNDEFINED);
|
||||
}
|
||||
furi_string_free(path);
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
}
|
||||
|
||||
static void* js_gui_file_picker_create(struct mjs* mjs, mjs_val_t* object, JsModules* modules) {
|
||||
UNUSED(modules);
|
||||
*object = mjs_mk_object(mjs);
|
||||
mjs_set(mjs, *object, "pickFile", ~0, MJS_MK_FN(js_gui_file_picker_pick_file));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const JsModuleDescriptor js_gui_file_picker_desc = {
|
||||
"gui__file_picker",
|
||||
js_gui_file_picker_create,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const FlipperAppPluginDescriptor plugin_descriptor = {
|
||||
.appid = PLUGIN_APP_ID,
|
||||
.ep_api_version = PLUGIN_API_VERSION,
|
||||
.entry_point = &js_gui_file_picker_desc,
|
||||
};
|
||||
|
||||
const FlipperAppPluginDescriptor* js_gui_file_picker_ep(void) {
|
||||
return &plugin_descriptor;
|
||||
}
|
||||
6
applications/system/js_app/types/gui/file_picker.d.ts
vendored
Normal file
6
applications/system/js_app/types/gui/file_picker.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @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`, `*`)
|
||||
*/
|
||||
export declare function pickFile(basePath: string, extension: string): string | undefined;
|
||||
Reference in New Issue
Block a user