mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-10 05:59:08 -07:00
Merge branch 'dev' of https://github.com/flipperdevices/flipperzero-firmware into mntm-dev
This commit is contained in:
@@ -84,11 +84,6 @@ void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) {
|
||||
view_dispatcher);
|
||||
}
|
||||
|
||||
void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) {
|
||||
furi_check(view_dispatcher);
|
||||
view_dispatcher->event_context = context;
|
||||
}
|
||||
|
||||
void view_dispatcher_set_navigation_event_callback(
|
||||
ViewDispatcher* view_dispatcher,
|
||||
ViewDispatcherNavigationEventCallback callback) {
|
||||
@@ -112,6 +107,11 @@ void view_dispatcher_set_tick_event_callback(
|
||||
view_dispatcher->tick_period = tick_period;
|
||||
}
|
||||
|
||||
void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) {
|
||||
furi_check(view_dispatcher);
|
||||
view_dispatcher->event_context = context;
|
||||
}
|
||||
|
||||
FuriEventLoop* view_dispatcher_get_event_loop(ViewDispatcher* view_dispatcher) {
|
||||
furi_check(view_dispatcher);
|
||||
furi_check(view_dispatcher->event_loop);
|
||||
|
||||
@@ -107,7 +107,7 @@ void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher,
|
||||
* in view_dispatcher_run.
|
||||
*
|
||||
* You can add your objects into event_loop instance, but don't run the loop on
|
||||
* your side it will cause issues with input processing on dispatcher stop.
|
||||
* your side as it will cause issues with input processing on dispatcher stop.
|
||||
*
|
||||
* @param view_dispatcher ViewDispatcher instance
|
||||
*
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "view_i.h"
|
||||
#include "gui_i.h"
|
||||
|
||||
DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST)
|
||||
DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) // NOLINT
|
||||
|
||||
struct ViewDispatcher {
|
||||
FuriEventLoop* event_loop;
|
||||
|
||||
@@ -273,6 +273,43 @@ MenuAppList_t* loader_get_menu_apps(Loader* loader) {
|
||||
return &loader->menu_apps;
|
||||
}
|
||||
|
||||
bool loader_signal(Loader* loader, uint32_t signal, void* arg) {
|
||||
furi_check(loader);
|
||||
|
||||
LoaderMessageBoolResult result;
|
||||
|
||||
LoaderMessage message = {
|
||||
.type = LoaderMessageTypeSignal,
|
||||
.api_lock = api_lock_alloc_locked(),
|
||||
.signal.signal = signal,
|
||||
.signal.arg = arg,
|
||||
.bool_value = &result,
|
||||
};
|
||||
|
||||
furi_message_queue_put(loader->queue, &message, FuriWaitForever);
|
||||
api_lock_wait_unlock_and_free(message.api_lock);
|
||||
|
||||
return result.value;
|
||||
}
|
||||
|
||||
bool loader_get_application_name(Loader* loader, FuriString* name) {
|
||||
furi_check(loader);
|
||||
|
||||
LoaderMessageBoolResult result;
|
||||
|
||||
LoaderMessage message = {
|
||||
.type = LoaderMessageTypeGetApplicationName,
|
||||
.api_lock = api_lock_alloc_locked(),
|
||||
.application_name = name,
|
||||
.bool_value = &result,
|
||||
};
|
||||
|
||||
furi_message_queue_put(loader->queue, &message, FuriWaitForever);
|
||||
api_lock_wait_unlock_and_free(message.api_lock);
|
||||
|
||||
return result.value;
|
||||
}
|
||||
|
||||
// callbacks
|
||||
|
||||
static void loader_menu_closed_callback(void* context) {
|
||||
@@ -858,6 +895,28 @@ static void loader_do_app_closed(Loader* loader) {
|
||||
furi_pubsub_publish(loader->pubsub, &event);
|
||||
}
|
||||
|
||||
static bool loader_is_application_running(Loader* loader) {
|
||||
FuriThread* app_thread = loader->app.thread;
|
||||
return app_thread && (app_thread != (FuriThread*)LOADER_MAGIC_THREAD_VALUE);
|
||||
}
|
||||
|
||||
static bool loader_do_signal(Loader* loader, uint32_t signal, void* arg) {
|
||||
if(loader_is_application_running(loader)) {
|
||||
return furi_thread_signal(loader->app.thread, signal, arg);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool loader_do_get_application_name(Loader* loader, FuriString* name) {
|
||||
if(loader_is_application_running(loader)) {
|
||||
furi_string_set(name, furi_thread_get_name(loader->app.thread));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// app
|
||||
|
||||
int32_t loader_srv(void* p) {
|
||||
@@ -921,6 +980,16 @@ int32_t loader_srv(void* p) {
|
||||
case LoaderMessageTypeApplicationsClosed:
|
||||
loader_do_applications_closed(loader);
|
||||
break;
|
||||
case LoaderMessageTypeSignal:
|
||||
message.bool_value->value =
|
||||
loader_do_signal(loader, message.signal.signal, message.signal.arg);
|
||||
api_lock_unlock(message.api_lock);
|
||||
break;
|
||||
case LoaderMessageTypeGetApplicationName:
|
||||
message.bool_value->value =
|
||||
loader_do_get_application_name(loader, message.application_name);
|
||||
api_lock_unlock(message.api_lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,26 @@ void loader_show_settings(Loader* instance);
|
||||
*/
|
||||
FuriPubSub* loader_get_pubsub(Loader* instance);
|
||||
|
||||
/**
|
||||
* @brief Send a signal to the currently running application
|
||||
*
|
||||
* @param[in] instance pointer to the loader instance
|
||||
* @param[in] signal signal value to be sent
|
||||
* @param[in,out] arg optional argument (can be of any value, including NULL)
|
||||
*
|
||||
* @return true if the signal was handled by the application, false otherwise
|
||||
*/
|
||||
bool loader_signal(Loader* instance, uint32_t signal, void* arg);
|
||||
|
||||
/**
|
||||
* @brief Get the name of the currently running application
|
||||
*
|
||||
* @param[in] instance pointer to the loader instance
|
||||
* @param[in,out] name pointer to the string to contain the name (must be allocated)
|
||||
* @return true if it was possible to get an application name, false otherwise
|
||||
*/
|
||||
bool loader_get_application_name(Loader* instance, FuriString* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "loader.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <cli/cli.h>
|
||||
#include <applications.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include "loader.h"
|
||||
|
||||
static void loader_cli_print_usage(void) {
|
||||
printf("Usage:\r\n");
|
||||
@@ -12,6 +13,8 @@ static void loader_cli_print_usage(void) {
|
||||
printf("\tlist\t - List available applications\r\n");
|
||||
printf("\topen <Application Name:string>\t - Open application by name\r\n");
|
||||
printf("\tinfo\t - Show loader state\r\n");
|
||||
printf("\tclose\t - Close the current application\r\n");
|
||||
printf("\tsignal <signal:number> [arg:hex]\t - Send a signal with an optional argument\r\n");
|
||||
}
|
||||
|
||||
static void loader_cli_list(void) {
|
||||
@@ -29,12 +32,15 @@ static void loader_cli_list(void) {
|
||||
}
|
||||
|
||||
static void loader_cli_info(Loader* loader) {
|
||||
if(!loader_is_locked(loader)) {
|
||||
FuriString* app_name = furi_string_alloc();
|
||||
|
||||
if(!loader_get_application_name(loader, app_name)) {
|
||||
printf("No application is running\r\n");
|
||||
} else {
|
||||
// TODO FL-3513: print application name ???
|
||||
printf("Application is running\r\n");
|
||||
printf("Application \"%s\" is running\r\n", furi_string_get_cstr(app_name));
|
||||
}
|
||||
|
||||
furi_string_free(app_name);
|
||||
}
|
||||
|
||||
static void loader_cli_open(FuriString* args, Loader* loader) {
|
||||
@@ -58,9 +64,11 @@ static void loader_cli_open(FuriString* args, Loader* loader) {
|
||||
if(loader_start(loader, app_name_str, args_str, error_message) != LoaderStatusOk) {
|
||||
printf("%s\r\n", furi_string_get_cstr(error_message));
|
||||
} else {
|
||||
NotificationApp* notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
notification_message(notifications, &sequence_display_backlight_on);
|
||||
#ifdef SRV_NOTIFICATION
|
||||
NotificationApp* notification_srv = furi_record_open(RECORD_NOTIFICATION);
|
||||
notification_message(notification_srv, &sequence_display_backlight_on);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
#endif
|
||||
}
|
||||
furi_string_free(error_message);
|
||||
} while(false);
|
||||
@@ -68,6 +76,38 @@ static void loader_cli_open(FuriString* args, Loader* loader) {
|
||||
furi_string_free(app_name);
|
||||
}
|
||||
|
||||
static void loader_cli_close(Loader* loader) {
|
||||
FuriString* app_name = furi_string_alloc();
|
||||
|
||||
if(!loader_get_application_name(loader, app_name)) {
|
||||
printf("No application is running\r\n");
|
||||
} else if(!loader_signal(loader, FuriSignalExit, NULL)) {
|
||||
printf("Application \"%s\" has to be closed manually\r\n", furi_string_get_cstr(app_name));
|
||||
} else {
|
||||
printf("Application \"%s\" was closed\r\n", furi_string_get_cstr(app_name));
|
||||
}
|
||||
|
||||
furi_string_free(app_name);
|
||||
}
|
||||
|
||||
static void loader_cli_signal(FuriString* args, Loader* loader) {
|
||||
uint32_t signal;
|
||||
void* arg = NULL;
|
||||
|
||||
if(!sscanf(furi_string_get_cstr(args), "%lu %p", &signal, &arg)) {
|
||||
printf("Signal must be a decimal number\r\n");
|
||||
} else if(!loader_is_locked(loader)) {
|
||||
printf("No application is running\r\n");
|
||||
} else {
|
||||
const bool is_handled = loader_signal(loader, signal, arg);
|
||||
printf(
|
||||
"Signal %lu with argument 0x%p was %s\r\n",
|
||||
signal,
|
||||
arg,
|
||||
is_handled ? "handled" : "ignored");
|
||||
}
|
||||
}
|
||||
|
||||
static void loader_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
UNUSED(context);
|
||||
@@ -76,29 +116,21 @@ static void loader_cli(Cli* cli, FuriString* args, void* context) {
|
||||
FuriString* cmd;
|
||||
cmd = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
loader_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_string_cmp_str(cmd, "list") == 0) {
|
||||
loader_cli_list();
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_string_cmp_str(cmd, "open") == 0) {
|
||||
loader_cli_open(args, loader);
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_string_cmp_str(cmd, "info") == 0) {
|
||||
loader_cli_info(loader);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
loader_cli_print_usage();
|
||||
} while(false);
|
||||
} else if(furi_string_equal(cmd, "list")) {
|
||||
loader_cli_list();
|
||||
} else if(furi_string_equal(cmd, "open")) {
|
||||
loader_cli_open(args, loader);
|
||||
} else if(furi_string_equal(cmd, "info")) {
|
||||
loader_cli_info(loader);
|
||||
} else if(furi_string_equal(cmd, "close")) {
|
||||
loader_cli_close(loader);
|
||||
} else if(furi_string_equal(cmd, "signal")) {
|
||||
loader_cli_signal(args, loader);
|
||||
} else {
|
||||
loader_cli_print_usage();
|
||||
}
|
||||
|
||||
furi_string_free(cmd);
|
||||
furi_record_close(RECORD_LOADER);
|
||||
|
||||
@@ -34,6 +34,8 @@ typedef enum {
|
||||
LoaderMessageTypeUnlock,
|
||||
LoaderMessageTypeIsLocked,
|
||||
LoaderMessageTypeStartByNameDetachedWithGuiError,
|
||||
LoaderMessageTypeSignal,
|
||||
LoaderMessageTypeGetApplicationName,
|
||||
|
||||
LoaderMessageTypeShowSettings,
|
||||
} LoaderMessageType;
|
||||
@@ -44,6 +46,11 @@ typedef struct {
|
||||
FuriString* error_message;
|
||||
} LoaderMessageStartByName;
|
||||
|
||||
typedef struct {
|
||||
uint32_t signal;
|
||||
void* arg;
|
||||
} LoaderMessageSignal;
|
||||
|
||||
typedef enum {
|
||||
LoaderStatusErrorUnknown,
|
||||
LoaderStatusErrorInvalidFile,
|
||||
@@ -70,6 +77,8 @@ typedef struct {
|
||||
|
||||
union {
|
||||
LoaderMessageStartByName start;
|
||||
LoaderMessageSignal signal;
|
||||
FuriString* application_name;
|
||||
};
|
||||
|
||||
union {
|
||||
|
||||
Reference in New Issue
Block a user