blackhat_scene_scripts.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "../blackhat_app_i.h"
  2. static bool console = false;
  3. static void blackhat_scene_script_list_enter_callback(
  4. void* context, uint32_t index
  5. )
  6. {
  7. furi_assert(context);
  8. BlackhatApp* app = context;
  9. console = true;
  10. app->selected_tx_string = "bh script run";
  11. app->selected_option_item_text = app->cmd[index + 1];
  12. app->text_input_req = false;
  13. app->selected_menu_index = index;
  14. FURI_LOG_I("tag/app name", "%s", app->selected_tx_string);
  15. scene_manager_search_and_switch_to_previous_scene(
  16. app->scene_manager, BlackhatAppViewConsoleOutput
  17. );
  18. }
  19. static void blackhat_scene_script_list_change_callback(VariableItem* item)
  20. {
  21. UNUSED(item);
  22. }
  23. void blackhat_scene_scripts_on_enter(void* context)
  24. {
  25. BlackhatApp* app = context;
  26. VariableItemList* var_item_list = app->script_item_list;
  27. size_t i = 0;
  28. int start = 0;
  29. app->num_scripts = 0;
  30. console = false;
  31. while (app->script_text[i++]) {
  32. if (app->script_text[i] == '\n') {
  33. i++;
  34. if(app->cmd[app->num_scripts]) {
  35. free(app->cmd[app->num_scripts]);
  36. }
  37. app->cmd[app->num_scripts] = malloc(i - start);
  38. memcpy(
  39. app->cmd[app->num_scripts], &app->script_text[start], i - start
  40. );
  41. start = i;
  42. app->num_scripts++;
  43. }
  44. }
  45. variable_item_list_set_enter_callback(
  46. var_item_list, blackhat_scene_script_list_enter_callback, app
  47. );
  48. for (int i = 1; i < app->num_scripts; i++) {
  49. variable_item_list_add(
  50. var_item_list,
  51. app->cmd[i],
  52. 1,
  53. blackhat_scene_script_list_change_callback,
  54. app
  55. );
  56. }
  57. view_dispatcher_switch_to_view(
  58. app->view_dispatcher, BlackhatAppViewScriptItemList
  59. );
  60. }
  61. bool blackhat_scene_scripts_on_event(void* context, SceneManagerEvent event)
  62. {
  63. UNUSED(context);
  64. UNUSED(event);
  65. return false;
  66. }
  67. void blackhat_scene_scripts_on_exit(void* context)
  68. {
  69. BlackhatApp* app = context;
  70. variable_item_list_reset(app->script_item_list);
  71. if(!console) {
  72. scene_manager_search_and_switch_to_previous_scene(
  73. app->scene_manager, BlackhatSceneStart
  74. );
  75. }
  76. }