2024-06-03 13:43:23 +00:00
|
|
|
#include "dialogs_message.h"
|
2023-02-07 16:33:05 +00:00
|
|
|
#include <gui/modules/file_browser.h>
|
2022-11-29 12:50:55 +00:00
|
|
|
#include <toolbox/api_lock.h>
|
2022-05-27 11:19:21 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
FuriApiLock lock;
|
|
|
|
bool result;
|
|
|
|
} DialogsAppFileBrowserContext;
|
|
|
|
|
|
|
|
static void dialogs_app_file_browser_back_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
DialogsAppFileBrowserContext* file_browser_context = context;
|
|
|
|
file_browser_context->result = false;
|
2022-11-29 12:50:55 +00:00
|
|
|
api_lock_unlock(file_browser_context->lock);
|
2022-05-27 11:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dialogs_app_file_browser_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
DialogsAppFileBrowserContext* file_browser_context = context;
|
|
|
|
file_browser_context->result = true;
|
2022-11-29 12:50:55 +00:00
|
|
|
api_lock_unlock(file_browser_context->lock);
|
2022-05-27 11:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrowser* data) {
|
|
|
|
bool ret = false;
|
2022-07-26 12:21:51 +00:00
|
|
|
Gui* gui = furi_record_open(RECORD_GUI);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
|
|
|
DialogsAppFileBrowserContext* file_browser_context =
|
|
|
|
malloc(sizeof(DialogsAppFileBrowserContext));
|
2022-11-29 12:50:55 +00:00
|
|
|
file_browser_context->lock = api_lock_alloc_locked();
|
2022-05-27 11:19:21 +00:00
|
|
|
|
|
|
|
ViewHolder* view_holder = view_holder_alloc();
|
|
|
|
view_holder_attach_to_gui(view_holder, gui);
|
|
|
|
view_holder_set_back_callback(
|
|
|
|
view_holder, dialogs_app_file_browser_back_callback, file_browser_context);
|
|
|
|
|
|
|
|
FileBrowser* file_browser = file_browser_alloc(data->result_path);
|
|
|
|
file_browser_set_callback(
|
|
|
|
file_browser, dialogs_app_file_browser_callback, file_browser_context);
|
|
|
|
file_browser_configure(
|
2022-12-07 10:52:44 +00:00
|
|
|
file_browser,
|
|
|
|
data->extension,
|
2022-12-07 14:17:41 +00:00
|
|
|
data->base_path,
|
2022-12-07 10:52:44 +00:00
|
|
|
data->skip_assets,
|
|
|
|
data->hide_dot_files,
|
|
|
|
data->file_icon,
|
|
|
|
data->hide_ext);
|
2022-09-14 16:11:38 +00:00
|
|
|
file_browser_set_item_callback(file_browser, data->item_callback, data->item_callback_context);
|
2022-05-27 11:19:21 +00:00
|
|
|
file_browser_start(file_browser, data->preselected_filename);
|
|
|
|
|
|
|
|
view_holder_set_view(view_holder, file_browser_get_view(file_browser));
|
2022-11-29 12:50:55 +00:00
|
|
|
api_lock_wait_unlock(file_browser_context->lock);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
|
|
|
ret = file_browser_context->result;
|
|
|
|
|
2024-08-07 03:49:41 +00:00
|
|
|
view_holder_set_view(view_holder, NULL);
|
2022-05-27 11:19:21 +00:00
|
|
|
view_holder_free(view_holder);
|
|
|
|
file_browser_stop(file_browser);
|
|
|
|
file_browser_free(file_browser);
|
2022-11-29 12:50:55 +00:00
|
|
|
api_lock_free(file_browser_context->lock);
|
2022-05-27 11:19:21 +00:00
|
|
|
free(file_browser_context);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_GUI);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|