From f6bccccfa31bf50459a788f8e71f1544c80954b7 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 14 Mar 2024 01:44:39 +0000 Subject: [PATCH] BadKB: Decouple from Momentum Settings --- applications/main/bad_kb/bad_kb_app.c | 23 ++++++------- .../main/bad_kb/scenes/bad_kb_scene_config.c | 1 - applications/main/bad_kb/views/bad_kb_view.c | 1 - .../scenes/momentum_app_scene_protocols.c | 32 ------------------- lib/momentum/momentum.h | 2 -- lib/momentum/settings.c | 4 --- 6 files changed, 12 insertions(+), 51 deletions(-) diff --git a/applications/main/bad_kb/bad_kb_app.c b/applications/main/bad_kb/bad_kb_app.c index 8242d6f02..883371c47 100644 --- a/applications/main/bad_kb/bad_kb_app.c +++ b/applications/main/bad_kb/bad_kb_app.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include "helpers/ducky_script_i.h" @@ -43,6 +42,16 @@ void bad_kb_load_settings(BadKbApp* app) { flipper_format_rewind(file); } + if(!flipper_format_read_bool(file, "Is_Bt", &app->is_bt, 1)) { + app->is_bt = false; + flipper_format_rewind(file); + } + + if(!flipper_format_read_bool(file, "Bt_Remember", &app->bt_remember, 1)) { + app->bt_remember = false; + flipper_format_rewind(file); + } + if(flipper_format_read_string(file, "Bt_Name", tmp_str)) { strlcpy(cfg->ble.name, furi_string_get_cstr(tmp_str), sizeof(cfg->ble.name)); } else { @@ -107,6 +116,8 @@ static void bad_kb_save_settings(BadKbApp* app) { FlipperFormat* file = flipper_format_file_alloc(storage); if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) { flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout); + flipper_format_write_bool(file, "Is_Bt", &app->is_bt, 1); + flipper_format_write_bool(file, "Bt_Remember", &app->bt_remember, 1); flipper_format_write_string_cstr(file, "Bt_Name", cfg->ble.name); flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac)); flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb.manuf); @@ -279,14 +290,6 @@ void bad_kb_config_refresh(BadKbApp* app) { // Reload config page scene_manager_next_scene(app->scene_manager, BadKbSceneConfig); scene_manager_previous_scene(app->scene_manager); - - // Update settings - if(momentum_settings.bad_bt != app->is_bt || - momentum_settings.bad_bt_remember != app->bt_remember) { - momentum_settings.bad_bt = app->is_bt; - momentum_settings.bad_bt_remember = app->bt_remember; - momentum_settings_save(); - } } BadKbApp* bad_kb_app_alloc(char* arg) { @@ -322,8 +325,6 @@ BadKbApp* bad_kb_app_alloc(char* arg) { Bt* bt = furi_record_open(RECORD_BT); app->bt = bt; app->bt->suppress_pin_screen = true; - app->is_bt = momentum_settings.bad_bt; - app->bt_remember = momentum_settings.bad_bt_remember; bad_kb_config_adjust(&app->config); // Save prev config diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_config.c b/applications/main/bad_kb/scenes/bad_kb_scene_config.c index 3083e8696..8845bd5d5 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_config.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_config.c @@ -1,7 +1,6 @@ #include "../bad_kb_app_i.h" #include "furi_hal_power.h" #include "furi_hal_usb.h" -#include enum VarItemListIndex { VarItemListIndexKeyboardLayout, diff --git a/applications/main/bad_kb/views/bad_kb_view.c b/applications/main/bad_kb/views/bad_kb_view.c index 5f1a8bdda..a5dea1a19 100644 --- a/applications/main/bad_kb/views/bad_kb_view.c +++ b/applications/main/bad_kb/views/bad_kb_view.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #define MAX_NAME_LEN 64 diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c b/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c index cbe69e46c..7258a9d9a 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_protocols.c @@ -1,8 +1,6 @@ #include "../momentum_app.h" enum VarItemListIndex { - VarItemListIndexBadkbMode, - VarItemListIndexBadbtRemember, VarItemListIndexSubghzFreqs, VarItemListIndexSubghzExtend, VarItemListIndexGpioPins, @@ -13,22 +11,6 @@ void momentum_app_scene_protocols_var_item_list_callback(void* context, uint32_t view_dispatcher_send_custom_event(app->view_dispatcher, index); } -static void momentum_app_scene_protocols_bad_bt_changed(VariableItem* item) { - MomentumApp* app = variable_item_get_context(item); - bool value = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, value ? "BT" : "USB"); - momentum_settings.bad_bt = value; - app->save_settings = true; -} - -static void momentum_app_scene_protocols_bad_bt_remember_changed(VariableItem* item) { - MomentumApp* app = variable_item_get_context(item); - bool value = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, value ? "ON" : "OFF"); - momentum_settings.bad_bt_remember = value; - app->save_settings = true; -} - static void momentum_app_scene_protocols_subghz_extend_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); app->subghz_extend = variable_item_get_current_value_index(item); @@ -49,20 +31,6 @@ void momentum_app_scene_protocols_on_enter(void* context) { VariableItemList* var_item_list = app->var_item_list; VariableItem* item; - item = variable_item_list_add( - var_item_list, "BadKB Mode", 2, momentum_app_scene_protocols_bad_bt_changed, app); - variable_item_set_current_value_index(item, momentum_settings.bad_bt); - variable_item_set_current_value_text(item, momentum_settings.bad_bt ? "BT" : "USB"); - - item = variable_item_list_add( - var_item_list, - "BadBT Remember", - 2, - momentum_app_scene_protocols_bad_bt_remember_changed, - app); - variable_item_set_current_value_index(item, momentum_settings.bad_bt_remember); - variable_item_set_current_value_text(item, momentum_settings.bad_bt_remember ? "ON" : "OFF"); - item = variable_item_list_add(var_item_list, "SubGHz Freqs", 0, NULL, app); variable_item_set_current_value_text(item, ">"); diff --git a/lib/momentum/momentum.h b/lib/momentum/momentum.h index e2555c99c..c3d43f43b 100644 --- a/lib/momentum/momentum.h +++ b/lib/momentum/momentum.h @@ -77,8 +77,6 @@ typedef struct { bool show_hidden_files; bool show_internal_tab; uint32_t favorite_timeout; - bool bad_bt; - bool bad_bt_remember; bool dark_mode; bool rgb_backlight; uint32_t butthurt_timer; diff --git a/lib/momentum/settings.c b/lib/momentum/settings.c index a4086ebbb..209f6bc4a 100644 --- a/lib/momentum/settings.c +++ b/lib/momentum/settings.c @@ -30,8 +30,6 @@ MomentumSettings momentum_settings = { .show_hidden_files = false, // OFF .show_internal_tab = false, // OFF .favorite_timeout = 0, // OFF - .bad_bt = false, // USB - .bad_bt_remember = false, // OFF .dark_mode = false, // OFF .rgb_backlight = false, // OFF .butthurt_timer = 21600, // 6 H @@ -102,8 +100,6 @@ static const struct { {setting_bool(show_hidden_files)}, {setting_bool(show_internal_tab)}, {setting_uint(favorite_timeout, 0, 60)}, - {setting_bool(bad_bt)}, - {setting_bool(bad_bt_remember)}, {setting_bool(dark_mode)}, {setting_bool(rgb_backlight)}, {setting_uint(butthurt_timer, 0, 172800)},