|
| 1 | + |
| 2 | +#include "app_inspect.h" |
| 3 | +#include <string.h> |
| 4 | +#include "appfs.h" |
| 5 | +#include "bsp/input.h" |
| 6 | +#include "common/display.h" |
| 7 | +#include "gui_footer.h" |
| 8 | +#include "gui_style.h" |
| 9 | +#include "icons.h" |
| 10 | +#include "menu/apps.h" |
| 11 | +#include "menu/message_dialog.h" |
| 12 | +#include "pax_gfx.h" |
| 13 | +#include "pax_matrix.h" |
| 14 | +#include "pax_text.h" |
| 15 | +#include "pax_types.h" |
| 16 | + |
| 17 | +#if defined(CONFIG_BSP_TARGET_TANMATSU) || defined(CONFIG_BSP_TARGET_KONSOOL) || \ |
| 18 | + defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026) |
| 19 | +#define FOOTER_LEFT \ |
| 20 | + ((gui_header_field_t[]){{get_icon(ICON_ESC), "/"}, \ |
| 21 | + {get_icon(ICON_F1), "Back"}, \ |
| 22 | + {get_icon(ICON_F2), "Start"}, \ |
| 23 | + {get_icon(ICON_F5), "Delete App"}}), \ |
| 24 | + 4 |
| 25 | +#define FOOTER_RIGHT NULL, 0 |
| 26 | +#define TEXT_FONT pax_font_sky_mono |
| 27 | +#define TEXT_SIZE 18 |
| 28 | +#elif defined(CONFIG_BSP_TARGET_MCH2022) |
| 29 | +#define FOOTER_LEFT ((gui_header_field_t[]){{NULL, "🅱 Back"}}), 1 |
| 30 | +#define FOOTER_RIGHT NULL, 0 |
| 31 | +#define TEXT_FONT pax_font_sky_mono |
| 32 | +#define TEXT_SIZE 9 |
| 33 | +#else |
| 34 | +#define FOOTER_LEFT NULL, 0 |
| 35 | +#define FOOTER_RIGHT NULL, 0 |
| 36 | +#define TEXT_FONT pax_font_sky_mono |
| 37 | +#define TEXT_SIZE 9 |
| 38 | +#endif |
| 39 | + |
| 40 | +static void render(pax_buf_t* buffer, gui_theme_t* theme, pax_vec2_t position, bool partial, bool icons, app_t* app) { |
| 41 | + |
| 42 | + char text_buffer[256]; |
| 43 | + int line = 0; |
| 44 | + |
| 45 | + if (!partial || icons) { |
| 46 | + snprintf(text_buffer, sizeof(text_buffer), "App Info: %s", app->name); |
| 47 | + render_base_screen_statusbar(buffer, theme, !partial, !partial || icons, !partial, |
| 48 | + ((gui_header_field_t[]){{get_icon(ICON_DEVICE_INFO), text_buffer}}), 1, |
| 49 | + FOOTER_LEFT, FOOTER_RIGHT); |
| 50 | + } |
| 51 | + |
| 52 | + if (!partial) { |
| 53 | + |
| 54 | + if (app->name) { |
| 55 | + snprintf(text_buffer, sizeof(text_buffer), "Name: %s", app->name); |
| 56 | + pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0, |
| 57 | + position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer); |
| 58 | + } |
| 59 | + |
| 60 | + if (app->description) { |
| 61 | + snprintf(text_buffer, sizeof(text_buffer), "Description: %s", app->description); |
| 62 | + pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0, |
| 63 | + position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer); |
| 64 | + } |
| 65 | + |
| 66 | + if (app->author) { |
| 67 | + snprintf(text_buffer, sizeof(text_buffer), "Author: %s", app->author); |
| 68 | + pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0, |
| 69 | + position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer); |
| 70 | + } |
| 71 | + |
| 72 | + if (app->version) { |
| 73 | + snprintf(text_buffer, sizeof(text_buffer), "Version: %ld", app->version); |
| 74 | + pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0, |
| 75 | + position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer); |
| 76 | + } |
| 77 | + |
| 78 | + if (app->slug) { |
| 79 | + snprintf(text_buffer, sizeof(text_buffer), "Slug: %s", app->slug); |
| 80 | + pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0, |
| 81 | + position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + display_blit_buffer(buffer); |
| 86 | +} |
| 87 | + |
| 88 | +bool menu_app_inspect(pax_buf_t* buffer, gui_theme_t* theme, app_t* app) { |
| 89 | + QueueHandle_t input_event_queue = NULL; |
| 90 | + ESP_ERROR_CHECK(bsp_input_get_queue(&input_event_queue)); |
| 91 | + |
| 92 | + int header_height = theme->header.height + (theme->header.vertical_margin * 2); |
| 93 | + int footer_height = theme->footer.height + (theme->footer.vertical_margin * 2); |
| 94 | + |
| 95 | + pax_vec2_t position = { |
| 96 | + .x0 = theme->menu.horizontal_margin + theme->menu.horizontal_padding, |
| 97 | + .y0 = header_height + theme->menu.vertical_margin + theme->menu.vertical_padding, |
| 98 | + .x1 = pax_buf_get_width(buffer) - theme->menu.horizontal_margin - theme->menu.horizontal_padding, |
| 99 | + .y1 = pax_buf_get_height(buffer) - footer_height - theme->menu.vertical_margin - theme->menu.vertical_padding, |
| 100 | + }; |
| 101 | + |
| 102 | + render(buffer, theme, position, false, false, app); |
| 103 | + |
| 104 | + while (1) { |
| 105 | + bsp_input_event_t event; |
| 106 | + if (xQueueReceive(input_event_queue, &event, pdMS_TO_TICKS(1000)) == pdTRUE) { |
| 107 | + switch (event.type) { |
| 108 | + case INPUT_EVENT_TYPE_NAVIGATION: { |
| 109 | + if (event.args_navigation.state) { |
| 110 | + switch (event.args_navigation.key) { |
| 111 | + case BSP_INPUT_NAVIGATION_KEY_ESC: |
| 112 | + case BSP_INPUT_NAVIGATION_KEY_F1: |
| 113 | + case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B: |
| 114 | + return false; |
| 115 | + case BSP_INPUT_NAVIGATION_KEY_F2: |
| 116 | + execute_app(buffer, theme, position, app); |
| 117 | + render(buffer, theme, position, false, false, app); |
| 118 | + break; |
| 119 | + case BSP_INPUT_NAVIGATION_KEY_F5: |
| 120 | + message_dialog_return_type_t msg_ret = message_dialog_yes_no( |
| 121 | + buffer, theme, "Delete App", "Do you really want to delete the app?"); |
| 122 | + if (msg_ret == MSG_DIALOG_RETURN_OK) { |
| 123 | + appfsDeleteFile(app->slug); |
| 124 | + char text_buffer[256]; |
| 125 | + snprintf(text_buffer, sizeof(text_buffer), "/sd/apps/%s", app->slug); |
| 126 | + remove(text_buffer); |
| 127 | + snprintf(text_buffer, sizeof(text_buffer), "/int/apps/%s", app->slug); |
| 128 | + remove(text_buffer); |
| 129 | + return true; |
| 130 | + } |
| 131 | + render(buffer, theme, position, false, false, app); |
| 132 | + break; |
| 133 | + default: |
| 134 | + break; |
| 135 | + } |
| 136 | + } |
| 137 | + break; |
| 138 | + } |
| 139 | + default: |
| 140 | + break; |
| 141 | + } |
| 142 | + } else { |
| 143 | + render(buffer, theme, position, false, false, app); |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments