Przeglądaj źródła

Fix textbox hanging bug, refactor

0xchocolate 3 lat temu
rodzic
commit
beb29a56de

+ 4 - 3
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -8,7 +8,7 @@ void wifi_marauder_console_output_handle_rx_data_cb(uint8_t *buf, size_t len, vo
     app->text_box_store_strlen += len;
     if (app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
         string_right(app->text_box_store, app->text_box_store_strlen / 2);
-        app->text_box_store_strlen = string_size(app->text_box_store);
+        app->text_box_store_strlen = string_size(app->text_box_store) + len;
     }
 
     // Null-terminate buf and append to text box store
@@ -43,10 +43,11 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
             string_cat_str(app->text_box_store, help_msg);
             app->text_box_store_strlen += strlen(help_msg);
         }
-    } else { // "View Log" menu action
-        text_box_set_text(app->text_box, string_get_cstr(app->text_box_store));
     }
 
+    // Set starting text - for "View Log", this will just be what was already in the text box store
+    text_box_set_text(app->text_box, string_get_cstr(app->text_box_store));
+
     scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneConsoleOutput, 0);
     view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput);
 

+ 13 - 11
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c

@@ -31,7 +31,7 @@ typedef struct {
 
 // NUM_MENU_ITEMS defined in wifi_marauder_app_i.h - if you add an entry here, increment it!
 const WifiMarauderItem items[NUM_MENU_ITEMS] = {
-    { "View Log from", {"start", "end"}, 2, {}, NO_ARGS, FOCUS_CONSOLE_TOGGLE, NO_TIP },
+    { "View Log from", {"start", "end"}, 2, {"", ""}, NO_ARGS, FOCUS_CONSOLE_TOGGLE, NO_TIP },
     { "Scan AP", {""}, 1, {"scanap"}, NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP },
     { "SSID", {"add random", "add name", "remove"}, 3, {"ssid -a -g", "ssid -a -n", "ssid -r"}, INPUT_ARGS, FOCUS_CONSOLE_START, NO_TIP },
     { "List", {"ap", "ssid"}, 2, {"list -a", "list -s"}, NO_ARGS, FOCUS_CONSOLE_START, NO_TIP },
@@ -52,16 +52,20 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = {
 static void wifi_marauder_scene_start_var_list_enter_callback(void* context, uint32_t index) {
     furi_assert(context);
     WifiMarauderApp* app = context;
-    if (app->selected_option_index[index] < items[index].num_options_menu) {
-        app->selected_tx_string = items[index].actual_commands[app->selected_option_index[index]];
-    }
+
+    furi_assert(index < NUM_MENU_ITEMS);
+    const WifiMarauderItem* item = &items[index];
+
+    const int selected_option_index = app->selected_option_index[index];
+    furi_assert(selected_option_index < item->num_options_menu);
+    app->selected_tx_string = item->actual_commands[selected_option_index];
     app->is_command = (1 <= index);
     app->is_custom_tx_string = false;
     app->selected_menu_index = index;
-    app->focus_console_start = (items[index].focus_console == FOCUS_CONSOLE_TOGGLE) ? (app->selected_option_index[index] == 0) : items[index].focus_console;
-    app->show_stopscan_tip = items[index].show_stopscan_tip;
+    app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE) ? (selected_option_index == 0) : item->focus_console;
+    app->show_stopscan_tip = item->show_stopscan_tip;
 
-    bool needs_keyboard = (items[index].needs_keyboard == TOGGLE_ARGS) ? (app->selected_option_index[index] != 0) : items[index].needs_keyboard;
+    bool needs_keyboard = (item->needs_keyboard == TOGGLE_ARGS) ? (selected_option_index != 0) : item->needs_keyboard;
     if (needs_keyboard) {
         view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartKeyboard);
     } else {
@@ -92,10 +96,8 @@ void wifi_marauder_scene_start_on_enter(void* context) {
     VariableItem* item;
     for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
         item = variable_item_list_add(var_item_list, items[i].item_string, items[i].num_options_menu, wifi_marauder_scene_start_var_list_change_callback, app);
-        if (items[i].num_options_menu) {
-            variable_item_set_current_value_index(item, app->selected_option_index[i]);
-            variable_item_set_current_value_text(item, items[i].options_menu[app->selected_option_index[i]]);
-        }
+        variable_item_set_current_value_index(item, app->selected_option_index[i]);
+        variable_item_set_current_value_text(item, items[i].options_menu[app->selected_option_index[i]]);
     }
 
     variable_item_list_set_selected_item(