From 6fc6d50904edb1272a547e72709c9dd5bf316e4d Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 7 Apr 2024 20:42:17 +0100 Subject: [PATCH] MNTM: Refactor device name to Spoof submenu --- .../scenes/momentum_app_scene_config.h | 3 +- .../scenes/momentum_app_scene_misc.c | 15 +++--- .../scenes/momentum_app_scene_misc_spoof.c | 52 +++++++++++++++++++ ...c => momentum_app_scene_misc_spoof_name.c} | 20 +++---- 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof.c rename applications/main/momentum_app/scenes/{momentum_app_scene_misc_rename.c => momentum_app_scene_misc_spoof_name.c} (70%) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_config.h b/applications/main/momentum_app/scenes/momentum_app_scene_config.h index 77eb464325..419d9b27d8 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_config.h +++ b/applications/main/momentum_app/scenes/momentum_app_scene_config.h @@ -18,6 +18,7 @@ ADD_SCENE(momentum_app, misc, Misc) ADD_SCENE(momentum_app, misc_screen, MiscScreen) ADD_SCENE(momentum_app, misc_screen_color, MiscScreenColor) ADD_SCENE(momentum_app, misc_dolphin, MiscDolphin) +ADD_SCENE(momentum_app, misc_spoof, MiscSpoof) +ADD_SCENE(momentum_app, misc_spoof_name, MiscSpoofName) ADD_SCENE(momentum_app, misc_vgm, MiscVgm) ADD_SCENE(momentum_app, misc_vgm_color, MiscVgmColor) -ADD_SCENE(momentum_app, misc_rename, MiscRename) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_misc.c b/applications/main/momentum_app/scenes/momentum_app_scene_misc.c index ba9c1077e2..64b9900f2b 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_misc.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_misc.c @@ -3,8 +3,8 @@ enum VarItemListIndex { VarItemListIndexScreen, VarItemListIndexDolphin, + VarItemListIndexSpoof, VarItemListIndexVgm, - VarItemListIndexChangeDeviceName, VarItemListIndexChargeCap, VarItemListIndexShowMomentumIntro, }; @@ -37,10 +37,11 @@ void momentum_app_scene_misc_on_enter(void* context) { item = variable_item_list_add(var_item_list, "Dolphin", 0, NULL, app); variable_item_set_current_value_text(item, ">"); - item = variable_item_list_add(var_item_list, "VGM Options", 0, NULL, app); + item = variable_item_list_add(var_item_list, "Spoofing Options", 0, NULL, app); variable_item_set_current_value_text(item, ">"); - variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app); + item = variable_item_list_add(var_item_list, "VGM Options", 0, NULL, app); + variable_item_set_current_value_text(item, ">"); char cap_str[6]; value_index = momentum_settings.charge_cap / CHARGE_CAP_INTV; @@ -81,14 +82,14 @@ bool momentum_app_scene_misc_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscDolphin, 0); scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscDolphin); break; + case VarItemListIndexSpoof: + scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscSpoof, 0); + scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscSpoof); + break; case VarItemListIndexVgm: scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscVgm, 0); scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscVgm); break; - case VarItemListIndexChangeDeviceName: - scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscRename, 0); - scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscRename); - break; case VarItemListIndexShowMomentumIntro: { for(int i = 0; i < 10; i++) { if(storage_common_copy( diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof.c b/applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof.c new file mode 100644 index 0000000000..7f7823376c --- /dev/null +++ b/applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof.c @@ -0,0 +1,52 @@ +#include "../momentum_app.h" + +enum VarItemListIndex { + VarItemListIndexFlipperName, // TODO: Split into name, mac, serial +}; + +void momentum_app_scene_misc_spoof_var_item_list_callback(void* context, uint32_t index) { + MomentumApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, index); +} + +void momentum_app_scene_misc_spoof_on_enter(void* context) { + MomentumApp* app = context; + VariableItemList* var_item_list = app->var_item_list; + VariableItem* item; + + item = variable_item_list_add(var_item_list, "Flipper Name", 0, NULL, app); + variable_item_set_current_value_text(item, app->device_name); + + variable_item_list_set_enter_callback( + var_item_list, momentum_app_scene_misc_spoof_var_item_list_callback, app); + + variable_item_list_set_selected_item( + var_item_list, + scene_manager_get_scene_state(app->scene_manager, MomentumAppSceneMiscSpoof)); + + view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewVarItemList); +} + +bool momentum_app_scene_misc_spoof_on_event(void* context, SceneManagerEvent event) { + MomentumApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscSpoof, event.event); + consumed = true; + switch(event.event) { + case VarItemListIndexFlipperName: + scene_manager_next_scene(app->scene_manager, MomentumAppSceneMiscSpoofName); + break; + default: + break; + } + } + + return consumed; +} + +void momentum_app_scene_misc_spoof_on_exit(void* context) { + MomentumApp* app = context; + variable_item_list_reset(app->var_item_list); +} diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_misc_rename.c b/applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof_name.c similarity index 70% rename from applications/main/momentum_app/scenes/momentum_app_scene_misc_rename.c rename to applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof_name.c index 5f0127dfd2..1ba6aed7bd 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_misc_rename.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_misc_spoof_name.c @@ -4,7 +4,7 @@ enum TextInputIndex { TextInputResultOk, }; -static void momentum_app_scene_misc_rename_text_input_callback(void* context) { +static void momentum_app_scene_misc_spoof_name_text_input_callback(void* context) { MomentumApp* app = context; app->save_name = true; @@ -12,8 +12,10 @@ static void momentum_app_scene_misc_rename_text_input_callback(void* context) { view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); } -static bool - momentum_app_scene_misc_rename_validator(const char* text, FuriString* error, void* context) { +static bool momentum_app_scene_misc_spoof_name_validator( + const char* text, + FuriString* error, + void* context) { UNUSED(context); for(; *text; ++text) { @@ -27,19 +29,19 @@ static bool return true; } -void momentum_app_scene_misc_rename_on_enter(void* context) { +void momentum_app_scene_misc_spoof_name_on_enter(void* context) { MomentumApp* app = context; TextInput* text_input = app->text_input; - text_input_set_header_text(text_input, "Leave empty for default"); + text_input_set_header_text(text_input, "Leave empty for real name"); - text_input_set_validator(text_input, momentum_app_scene_misc_rename_validator, NULL); + text_input_set_validator(text_input, momentum_app_scene_misc_spoof_name_validator, NULL); text_input_set_minimum_length(text_input, 0); text_input_set_result_callback( text_input, - momentum_app_scene_misc_rename_text_input_callback, + momentum_app_scene_misc_spoof_name_text_input_callback, app, app->device_name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH, @@ -48,7 +50,7 @@ void momentum_app_scene_misc_rename_on_enter(void* context) { view_dispatcher_switch_to_view(app->view_dispatcher, MomentumAppViewTextInput); } -bool momentum_app_scene_misc_rename_on_event(void* context, SceneManagerEvent event) { +bool momentum_app_scene_misc_spoof_name_on_event(void* context, SceneManagerEvent event) { MomentumApp* app = context; bool consumed = false; @@ -66,7 +68,7 @@ bool momentum_app_scene_misc_rename_on_event(void* context, SceneManagerEvent ev return consumed; } -void momentum_app_scene_misc_rename_on_exit(void* context) { +void momentum_app_scene_misc_spoof_name_on_exit(void* context) { MomentumApp* app = context; text_input_reset(app->text_input); }