2022-05-27 14:19:21 +03:00
|
|
|
#include "file_browser_worker.h"
|
2023-02-07 19:33:05 +03:00
|
|
|
|
|
|
|
#include <storage/filesystem_api_defines.h>
|
|
|
|
#include <storage/storage.h>
|
|
|
|
|
|
|
|
#include <toolbox/path.h>
|
2022-07-20 13:56:33 +03:00
|
|
|
#include <core/check.h>
|
|
|
|
#include <core/common_defines.h>
|
2023-02-07 19:33:05 +03:00
|
|
|
#include <furi.h>
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
#include <m-array.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#define TAG "BrowserWorker"
|
|
|
|
|
|
|
|
#define ASSETS_DIR "assets"
|
2022-07-26 15:21:51 +03:00
|
|
|
#define BROWSER_ROOT STORAGE_ANY_PATH_PREFIX
|
2022-05-27 14:19:21 +03:00
|
|
|
#define FILE_NAME_LEN_MAX 256
|
|
|
|
#define LONG_LOAD_THRESHOLD 100
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
WorkerEvtStop = (1 << 0),
|
|
|
|
WorkerEvtLoad = (1 << 1),
|
|
|
|
WorkerEvtFolderEnter = (1 << 2),
|
|
|
|
WorkerEvtFolderExit = (1 << 3),
|
2022-06-09 10:09:52 +03:00
|
|
|
WorkerEvtFolderRefresh = (1 << 4),
|
|
|
|
WorkerEvtConfigChange = (1 << 5),
|
2022-05-27 14:19:21 +03:00
|
|
|
} WorkerEvtFlags;
|
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
#define WORKER_FLAGS_ALL \
|
|
|
|
(WorkerEvtStop | WorkerEvtLoad | WorkerEvtFolderEnter | WorkerEvtFolderExit | \
|
|
|
|
WorkerEvtFolderRefresh | WorkerEvtConfigChange)
|
2022-05-27 14:19:21 +03:00
|
|
|
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
ARRAY_DEF(IdxLastArray, int32_t)
|
|
|
|
ARRAY_DEF(ExtFilterArray, FuriString*, FURI_STRING_OPLIST)
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
struct BrowserWorker {
|
|
|
|
FuriThread* thread;
|
|
|
|
|
2022-11-28 21:59:24 +03:00
|
|
|
FuriString* path_start;
|
|
|
|
FuriString* path_current;
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* path_next;
|
2022-05-27 14:19:21 +03:00
|
|
|
int32_t item_sel_idx;
|
|
|
|
uint32_t load_offset;
|
|
|
|
uint32_t load_count;
|
|
|
|
bool skip_assets;
|
2022-12-07 13:52:44 +03:00
|
|
|
bool hide_dot_files;
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_t idx_last;
|
|
|
|
ExtFilterArray_t ext_filter;
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
void* cb_ctx;
|
|
|
|
BrowserWorkerFolderOpenCallback folder_cb;
|
|
|
|
BrowserWorkerListLoadCallback list_load_cb;
|
|
|
|
BrowserWorkerListItemCallback list_item_cb;
|
|
|
|
BrowserWorkerLongLoadCallback long_load_cb;
|
|
|
|
};
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
static bool browser_path_is_file(FuriString* path) {
|
2022-05-27 14:19:21 +03:00
|
|
|
bool state = false;
|
|
|
|
FileInfo file_info;
|
2022-07-26 15:21:51 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-10-05 18:15:23 +03:00
|
|
|
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
2023-03-01 20:57:27 +03:00
|
|
|
if(!file_info_is_dir(&file_info)) {
|
2022-05-27 14:19:21 +03:00
|
|
|
state = true;
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
static bool browser_path_trim(FuriString* path) {
|
2022-05-27 14:19:21 +03:00
|
|
|
bool is_root = false;
|
2022-10-05 18:15:23 +03:00
|
|
|
size_t filename_start = furi_string_search_rchar(path, '/');
|
|
|
|
furi_string_left(path, filename_start);
|
|
|
|
if((furi_string_empty(path)) || (filename_start == FURI_STRING_FAILURE)) {
|
|
|
|
furi_string_set(path, BROWSER_ROOT);
|
2022-05-27 14:19:21 +03:00
|
|
|
is_root = true;
|
|
|
|
}
|
|
|
|
return is_root;
|
|
|
|
}
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
static void browser_parse_ext_filter(ExtFilterArray_t ext_filter, const char* filter_str) {
|
2024-02-13 16:05:04 +03:00
|
|
|
ExtFilterArray_reset(ext_filter);
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
if(!filter_str) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = strlen(filter_str);
|
|
|
|
if(len == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t str_offset = 0;
|
|
|
|
FuriString* ext_temp = furi_string_alloc();
|
|
|
|
while(1) {
|
|
|
|
size_t ext_len = strcspn(&filter_str[str_offset], "|");
|
|
|
|
|
|
|
|
furi_string_set_strn(ext_temp, &filter_str[str_offset], ext_len);
|
|
|
|
ExtFilterArray_push_back(ext_filter, ext_temp);
|
|
|
|
|
|
|
|
str_offset += ext_len + 1;
|
|
|
|
if(str_offset >= len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
furi_string_free(ext_temp);
|
|
|
|
}
|
2022-05-27 14:19:21 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
static bool browser_filter_by_name(BrowserWorker* browser, FuriString* name, bool is_folder) {
|
2022-12-07 13:52:44 +03:00
|
|
|
// Skip dot files if enabled
|
|
|
|
if(browser->hide_dot_files) {
|
|
|
|
if(furi_string_start_with_str(name, ".")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
if(is_folder) {
|
|
|
|
// Skip assets folders (if enabled)
|
|
|
|
if(browser->skip_assets) {
|
2023-02-11 21:59:22 +03:00
|
|
|
return ((furi_string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true));
|
2022-05-27 14:19:21 +03:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Filter files by extension
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
if(ExtFilterArray_size(browser->ext_filter) == 0) {
|
2022-05-27 14:19:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
|
|
|
|
ExtFilterArray_it_t it;
|
|
|
|
for(ExtFilterArray_it(it, browser->ext_filter); !ExtFilterArray_end_p(it);
|
|
|
|
ExtFilterArray_next(it)) {
|
|
|
|
FuriString* ext = *ExtFilterArray_cref(it);
|
|
|
|
if((furi_string_empty(ext)) || (furi_string_cmp_str(ext, "*") == 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(furi_string_end_with(name, ext)) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
static bool browser_folder_check_and_switch(FuriString* path) {
|
2022-05-27 14:19:21 +03:00
|
|
|
FileInfo file_info;
|
2022-07-26 15:21:51 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
bool is_root = false;
|
2022-08-18 19:54:17 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(furi_string_search_rchar(path, '/') == 0) {
|
2022-08-18 19:54:17 +03:00
|
|
|
is_root = true;
|
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
while(1) {
|
|
|
|
// Check if folder is existing and navigate back if not
|
2022-10-05 18:15:23 +03:00
|
|
|
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
2023-03-01 20:57:27 +03:00
|
|
|
if(file_info_is_dir(&file_info)) {
|
2022-05-27 14:19:21 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_root) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
is_root = browser_path_trim(path);
|
|
|
|
}
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
return is_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool browser_folder_init(
|
|
|
|
BrowserWorker* browser,
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* path,
|
|
|
|
FuriString* filename,
|
2022-05-27 14:19:21 +03:00
|
|
|
uint32_t* item_cnt,
|
|
|
|
int32_t* file_idx) {
|
|
|
|
bool state = false;
|
|
|
|
FileInfo file_info;
|
|
|
|
uint32_t total_files_cnt = 0;
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
File* directory = storage_file_alloc(storage);
|
|
|
|
|
|
|
|
char name_temp[FILE_NAME_LEN_MAX];
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* name_str;
|
|
|
|
name_str = furi_string_alloc();
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
*item_cnt = 0;
|
|
|
|
*file_idx = -1;
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
if(storage_dir_open(directory, furi_string_get_cstr(path))) {
|
2022-05-27 14:19:21 +03:00
|
|
|
state = true;
|
|
|
|
while(1) {
|
|
|
|
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if((storage_file_get_error(directory) == FSE_OK) && (name_temp[0] != '\0')) {
|
|
|
|
total_files_cnt++;
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_set(name_str, name_temp);
|
2023-03-01 20:57:27 +03:00
|
|
|
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
2022-10-05 18:15:23 +03:00
|
|
|
if(!furi_string_empty(filename)) {
|
|
|
|
if(furi_string_cmp(name_str, filename) == 0) {
|
2022-05-27 14:19:21 +03:00
|
|
|
*file_idx = *item_cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*item_cnt)++;
|
|
|
|
}
|
|
|
|
if(total_files_cnt == LONG_LOAD_THRESHOLD) {
|
|
|
|
// There are too many files in folder and counting them will take some time - send callback to app
|
|
|
|
if(browser->long_load_cb) {
|
|
|
|
browser->long_load_cb(browser->cb_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(name_str);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
storage_dir_close(directory);
|
|
|
|
storage_file_free(directory);
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-02-13 00:41:50 +03:00
|
|
|
// Load files list by chunks, like it was originally, not compatible with sorting, sorting needs to be disabled to use this
|
2023-02-12 23:55:39 +03:00
|
|
|
static bool browser_folder_load_chunked(
|
|
|
|
BrowserWorker* browser,
|
|
|
|
FuriString* path,
|
|
|
|
uint32_t offset,
|
|
|
|
uint32_t count) {
|
|
|
|
FileInfo file_info;
|
|
|
|
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
File* directory = storage_file_alloc(storage);
|
|
|
|
|
|
|
|
char name_temp[FILE_NAME_LEN_MAX];
|
|
|
|
FuriString* name_str;
|
|
|
|
name_str = furi_string_alloc();
|
|
|
|
|
|
|
|
uint32_t items_cnt = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
items_cnt = 0;
|
|
|
|
while(items_cnt < offset) {
|
|
|
|
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(storage_file_get_error(directory) == FSE_OK) {
|
|
|
|
furi_string_set(name_str, name_temp);
|
2023-03-01 20:57:27 +03:00
|
|
|
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
2023-02-12 23:55:39 +03:00
|
|
|
items_cnt++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(items_cnt != offset) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(browser->list_load_cb) {
|
|
|
|
browser->list_load_cb(browser->cb_ctx, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
items_cnt = 0;
|
|
|
|
while(items_cnt < count) {
|
|
|
|
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(storage_file_get_error(directory) == FSE_OK) {
|
|
|
|
furi_string_set(name_str, name_temp);
|
2023-03-01 20:57:27 +03:00
|
|
|
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
2023-02-12 23:55:39 +03:00
|
|
|
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
|
|
|
if(browser->list_item_cb) {
|
|
|
|
browser->list_item_cb(
|
|
|
|
browser->cb_ctx,
|
|
|
|
name_str,
|
|
|
|
items_cnt,
|
2023-03-02 21:18:35 +03:00
|
|
|
file_info_is_dir(&file_info),
|
2023-02-12 23:55:39 +03:00
|
|
|
false);
|
|
|
|
}
|
|
|
|
items_cnt++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(browser->list_item_cb) {
|
|
|
|
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
|
|
|
|
}
|
|
|
|
} while(0);
|
|
|
|
|
|
|
|
furi_string_free(name_str);
|
|
|
|
|
|
|
|
storage_dir_close(directory);
|
|
|
|
storage_file_free(directory);
|
|
|
|
|
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
|
|
return (items_cnt == count);
|
|
|
|
}
|
|
|
|
|
2023-02-13 00:41:50 +03:00
|
|
|
// Load all files at once, may cause memory overflow so need to limit that to about 400 files
|
|
|
|
static bool browser_folder_load_full(BrowserWorker* browser, FuriString* path) {
|
2022-05-27 14:19:21 +03:00
|
|
|
FileInfo file_info;
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
File* directory = storage_file_alloc(storage);
|
|
|
|
|
|
|
|
char name_temp[FILE_NAME_LEN_MAX];
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* name_str;
|
|
|
|
name_str = furi_string_alloc();
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
uint32_t items_cnt = 0;
|
|
|
|
|
2023-02-11 17:49:00 +03:00
|
|
|
bool ret = false;
|
2022-05-27 14:19:21 +03:00
|
|
|
do {
|
2022-10-05 18:15:23 +03:00
|
|
|
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
|
2022-05-27 14:19:21 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(browser->list_load_cb) {
|
2023-02-11 17:49:00 +03:00
|
|
|
browser->list_load_cb(browser->cb_ctx, 0);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
2023-02-11 17:49:00 +03:00
|
|
|
while(storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX) &&
|
|
|
|
storage_file_get_error(directory) == FSE_OK) {
|
|
|
|
furi_string_set(name_str, name_temp);
|
2023-03-02 21:36:33 +03:00
|
|
|
if(browser_filter_by_name(browser, name_str, file_info_is_dir(&file_info))) {
|
2023-02-11 17:49:00 +03:00
|
|
|
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
|
|
|
if(browser->list_item_cb) {
|
|
|
|
browser->list_item_cb(
|
2023-03-02 21:36:33 +03:00
|
|
|
browser->cb_ctx, name_str, items_cnt, file_info_is_dir(&file_info), false);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
2023-02-11 17:49:00 +03:00
|
|
|
items_cnt++;
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(browser->list_item_cb) {
|
2023-02-12 14:15:11 +03:00
|
|
|
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
2023-02-11 17:49:00 +03:00
|
|
|
ret = true;
|
2022-05-27 14:19:21 +03:00
|
|
|
} while(0);
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(name_str);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
storage_dir_close(directory);
|
|
|
|
storage_file_free(directory);
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
2023-02-11 17:49:00 +03:00
|
|
|
return ret;
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t browser_worker(void* context) {
|
|
|
|
BrowserWorker* browser = (BrowserWorker*)context;
|
|
|
|
furi_assert(browser);
|
|
|
|
FURI_LOG_D(TAG, "Start");
|
|
|
|
|
|
|
|
uint32_t items_cnt = 0;
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* path;
|
|
|
|
path = furi_string_alloc_set(BROWSER_ROOT);
|
2022-05-27 14:19:21 +03:00
|
|
|
browser->item_sel_idx = -1;
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* filename;
|
|
|
|
filename = furi_string_alloc();
|
2022-05-27 14:19:21 +03:00
|
|
|
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
while(1) {
|
2022-07-20 13:56:33 +03:00
|
|
|
uint32_t flags =
|
|
|
|
furi_thread_flags_wait(WORKER_FLAGS_ALL, FuriFlagWaitAny, FuriWaitForever);
|
|
|
|
furi_assert((flags & FuriFlagError) == 0);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
if(flags & WorkerEvtConfigChange) {
|
|
|
|
// If start path is a path to the file - try finding index of this file in a folder
|
|
|
|
if(browser_path_is_file(browser->path_next)) {
|
|
|
|
path_extract_filename(browser->path_next, filename, false);
|
|
|
|
}
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_reset(browser->idx_last);
|
2022-06-09 10:09:52 +03:00
|
|
|
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
|
2022-06-09 10:09:52 +03:00
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
if(flags & WorkerEvtFolderEnter) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_set(path, browser->path_next);
|
2022-05-27 14:19:21 +03:00
|
|
|
bool is_root = browser_folder_check_and_switch(path);
|
|
|
|
|
|
|
|
// Push previous selected item index to history array
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_push_back(browser->idx_last, browser->item_sel_idx);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
int32_t file_idx = 0;
|
|
|
|
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
|
2022-11-28 21:59:24 +03:00
|
|
|
furi_string_set(browser->path_current, path);
|
2022-05-27 14:19:21 +03:00
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
2022-10-07 16:35:15 +03:00
|
|
|
"Enter folder: %s items: %lu idx: %ld",
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_get_cstr(path),
|
2022-05-27 14:19:21 +03:00
|
|
|
items_cnt,
|
|
|
|
file_idx);
|
|
|
|
if(browser->folder_cb) {
|
|
|
|
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
|
|
|
|
}
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_reset(filename);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(flags & WorkerEvtFolderExit) {
|
|
|
|
browser_path_trim(path);
|
|
|
|
bool is_root = browser_folder_check_and_switch(path);
|
|
|
|
|
|
|
|
int32_t file_idx = 0;
|
|
|
|
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
if(IdxLastArray_size(browser->idx_last) > 0) {
|
2022-05-27 14:19:21 +03:00
|
|
|
// Pop previous selected item index from history array
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_pop_back(&file_idx, browser->idx_last);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
2022-11-28 21:59:24 +03:00
|
|
|
furi_string_set(browser->path_current, path);
|
2022-05-27 14:19:21 +03:00
|
|
|
FURI_LOG_D(
|
2022-10-05 18:15:23 +03:00
|
|
|
TAG,
|
2022-10-07 16:35:15 +03:00
|
|
|
"Exit to: %s items: %lu idx: %ld",
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_get_cstr(path),
|
|
|
|
items_cnt,
|
|
|
|
file_idx);
|
2022-05-27 14:19:21 +03:00
|
|
|
if(browser->folder_cb) {
|
|
|
|
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
if(flags & WorkerEvtFolderRefresh) {
|
|
|
|
bool is_root = browser_folder_check_and_switch(path);
|
|
|
|
|
|
|
|
int32_t file_idx = 0;
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_reset(filename);
|
2022-06-09 10:09:52 +03:00
|
|
|
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
|
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
2022-10-07 16:35:15 +03:00
|
|
|
"Refresh folder: %s items: %lu idx: %ld",
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_get_cstr(path),
|
2022-06-09 10:09:52 +03:00
|
|
|
items_cnt,
|
|
|
|
browser->item_sel_idx);
|
|
|
|
if(browser->folder_cb) {
|
|
|
|
browser->folder_cb(browser->cb_ctx, items_cnt, browser->item_sel_idx, is_root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
if(flags & WorkerEvtLoad) {
|
2022-10-07 16:35:15 +03:00
|
|
|
FURI_LOG_D(
|
|
|
|
TAG, "Load offset: %lu cnt: %lu", browser->load_offset, browser->load_count);
|
2023-02-13 08:01:31 +03:00
|
|
|
if(items_cnt > BROWSER_SORT_THRESHOLD) {
|
2023-02-12 23:55:39 +03:00
|
|
|
browser_folder_load_chunked(
|
|
|
|
browser, path, browser->load_offset, browser->load_count);
|
|
|
|
} else {
|
2023-02-13 00:41:50 +03:00
|
|
|
browser_folder_load_full(browser, path);
|
2023-02-12 23:55:39 +03:00
|
|
|
}
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(flags & WorkerEvtStop) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(filename);
|
|
|
|
furi_string_free(path);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "End");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-07 13:52:44 +03:00
|
|
|
BrowserWorker* file_browser_worker_alloc(
|
|
|
|
FuriString* path,
|
2022-12-07 17:17:41 +03:00
|
|
|
const char* base_path,
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
const char* ext_filter,
|
2022-12-07 13:52:44 +03:00
|
|
|
bool skip_assets,
|
|
|
|
bool hide_dot_files) {
|
2022-12-26 15:13:30 +03:00
|
|
|
BrowserWorker* browser = malloc(sizeof(BrowserWorker));
|
2022-05-27 14:19:21 +03:00
|
|
|
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_init(browser->idx_last);
|
|
|
|
ExtFilterArray_init(browser->ext_filter);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
browser_parse_ext_filter(browser->ext_filter, ext_filter);
|
2022-05-27 14:19:21 +03:00
|
|
|
browser->skip_assets = skip_assets;
|
2022-12-07 13:52:44 +03:00
|
|
|
browser->hide_dot_files = hide_dot_files;
|
2022-12-07 17:17:41 +03:00
|
|
|
|
2022-11-28 21:59:24 +03:00
|
|
|
browser->path_current = furi_string_alloc_set(path);
|
2022-10-05 18:15:23 +03:00
|
|
|
browser->path_next = furi_string_alloc_set(path);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
2022-12-07 17:17:41 +03:00
|
|
|
browser->path_start = furi_string_alloc();
|
|
|
|
if(base_path) {
|
|
|
|
furi_string_set_str(browser->path_start, base_path);
|
2022-11-28 21:59:24 +03:00
|
|
|
}
|
|
|
|
|
2022-11-23 15:49:17 +03:00
|
|
|
browser->thread = furi_thread_alloc_ex("BrowserWorker", 2048, browser_worker, browser);
|
2022-05-27 14:19:21 +03:00
|
|
|
furi_thread_start(browser->thread);
|
|
|
|
|
|
|
|
return browser;
|
2022-12-26 15:13:30 +03:00
|
|
|
} //-V773
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
void file_browser_worker_free(BrowserWorker* browser) {
|
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtStop);
|
2022-05-27 14:19:21 +03:00
|
|
|
furi_thread_join(browser->thread);
|
|
|
|
furi_thread_free(browser->thread);
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(browser->path_next);
|
2022-11-28 21:59:24 +03:00
|
|
|
furi_string_free(browser->path_current);
|
|
|
|
furi_string_free(browser->path_start);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
IdxLastArray_clear(browser->idx_last);
|
|
|
|
ExtFilterArray_clear(browser->ext_filter);
|
2022-05-27 14:19:21 +03:00
|
|
|
|
|
|
|
free(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_browser_worker_set_callback_context(BrowserWorker* browser, void* context) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->cb_ctx = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_browser_worker_set_folder_callback(
|
|
|
|
BrowserWorker* browser,
|
|
|
|
BrowserWorkerFolderOpenCallback cb) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->folder_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_browser_worker_set_list_callback(
|
|
|
|
BrowserWorker* browser,
|
|
|
|
BrowserWorkerListLoadCallback cb) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->list_load_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_browser_worker_set_item_callback(
|
|
|
|
BrowserWorker* browser,
|
|
|
|
BrowserWorkerListItemCallback cb) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->list_item_cb = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void file_browser_worker_set_long_load_callback(
|
|
|
|
BrowserWorker* browser,
|
|
|
|
BrowserWorkerLongLoadCallback cb) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->long_load_cb = cb;
|
|
|
|
}
|
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
void file_browser_worker_set_config(
|
|
|
|
BrowserWorker* browser,
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* path,
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
const char* ext_filter,
|
2022-12-07 13:52:44 +03:00
|
|
|
bool skip_assets,
|
|
|
|
bool hide_dot_files) {
|
2022-06-09 10:09:52 +03:00
|
|
|
furi_assert(browser);
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_set(browser->path_next, path);
|
[FL-3579, FL-3601, FL-3714] JavaScript runner (#3286)
* FBT: cdefines to env, libs order
* API: strtod, modf, itoa, calloc
* Apps: elk js
* Apps: mjs
* JS: scripts as assets
* mjs: composite resolver
* mjs: stack trace
* ELK JS example removed
* MJS thread, MJS lib modified to support script interruption
* JS console UI
* Module system, BadUSB bindings rework
* JS notifications, simple dialog, BadUSB demo
* Custom dialogs, dialog demo
* MJS as system library, some dirty hacks to make it compile
* Plugin-based js modules
* js_uart(BadUART) module
* js_uart: support for byte array arguments
* Script icon and various fixes
* File browser: multiple extensions filter, running js scripts from app loader
* Running js scripts from archive browser
* JS Runner as system app
* Example scripts moved to /ext/apps/Scripts
* JS bytecode listing generation
* MJS builtin printf cleanup
* JS examples cleanup
* mbedtls version fix
* Unused lib cleanup
* Making PVS happy & TODOs cleanup
* TODOs cleanup #2
* MJS: initial typed arrays support
* JS: fix mem leak in uart destructor
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2024-02-12 11:54:32 +03:00
|
|
|
browser_parse_ext_filter(browser->ext_filter, ext_filter);
|
2022-06-09 10:09:52 +03:00
|
|
|
browser->skip_assets = skip_assets;
|
2022-12-07 13:52:44 +03:00
|
|
|
browser->hide_dot_files = hide_dot_files;
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
|
2022-06-09 10:09:52 +03:00
|
|
|
}
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx) {
|
2022-05-27 14:19:21 +03:00
|
|
|
furi_assert(browser);
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_set(browser->path_next, path);
|
2022-05-27 14:19:21 +03:00
|
|
|
browser->item_sel_idx = item_idx;
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 21:59:24 +03:00
|
|
|
bool file_browser_worker_is_in_start_folder(BrowserWorker* browser) {
|
|
|
|
furi_assert(browser);
|
|
|
|
return (furi_string_cmp(browser->path_start, browser->path_current) == 0);
|
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
void file_browser_worker_folder_exit(BrowserWorker* browser) {
|
|
|
|
furi_assert(browser);
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderExit);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|
|
|
|
|
2022-06-09 10:09:52 +03:00
|
|
|
void file_browser_worker_folder_refresh(BrowserWorker* browser, int32_t item_idx) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->item_sel_idx = item_idx;
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderRefresh);
|
2022-06-09 10:09:52 +03:00
|
|
|
}
|
|
|
|
|
2022-05-27 14:19:21 +03:00
|
|
|
void file_browser_worker_load(BrowserWorker* browser, uint32_t offset, uint32_t count) {
|
|
|
|
furi_assert(browser);
|
|
|
|
browser->load_offset = offset;
|
|
|
|
browser->load_count = count;
|
2022-06-20 17:54:48 +03:00
|
|
|
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtLoad);
|
2022-05-27 14:19:21 +03:00
|
|
|
}
|