From db4ad389780e852a14a2baf1eadd9e5ef9d56daa Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 15:36:37 +0300 Subject: [PATCH 01/19] feat(store): bounce long names like the launcher --- README.md | 8 ++- main/ui/appstore_pages.cpp | 110 +++++++++++++++++------------- main/ui/appstore_pages.hpp | 8 +++ main/ui/appstore_presenter.cpp | 6 +- main/ui/appstore_presenter.hpp | 1 + main/ui/horizontal_marquee.hpp | 26 ++++--- tests/test_horizontal_marquee.cpp | 19 ++++-- 7 files changed, 111 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index c53c289..f213871 100644 --- a/README.md +++ b/README.md @@ -101,9 +101,11 @@ metadata taking precedence. On the home screen, use `Z/C` (left/right) to change category and `F/X` (up/down) to select an app. Installed filters catalog apps by their actual package installation state and refreshes after package operations. The Installed category is hidden when empty; removing its last app returns the -selection to All. Long app names pause for two seconds, then scroll horizontally -at 20 pixels per second, with another pause at the end. Status-bar updates keep -the current reading position, and labels never scroll vertically. +selection to All. Long names bounce like the selected APPLaunch title: they +pause for two seconds, scroll horizontally at 40 pixels per second to the end, +pause again, and scroll back. Status-bar updates keep the current reading +position, and labels never scroll vertically. In search results only the +selected name scrolls; the others end with an ellipsis. The header shows the selection within the category and the total catalog size. Press `4` for settings, `5` for share code, `6` for search, `7` for install/reinstall, and `8` or Enter for details. AppStore syncs the registry diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index 9dbfc55..a2bf826 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -39,39 +39,6 @@ lv_obj_t *center_label(lv_obj_t *root, const std::string &text, int x, int y, in return obj; } -void horizontal_label(lv_obj_t *root, const std::string &text, int x, int y, - int width, int height, const lv_font_t *font, - HorizontalMarquee &state, const std::string &key) -{ - state.select(key, lv_tick_get()); - lv_obj_t *viewport = lv_obj_create(root); - lv_obj_remove_style_all(viewport); - lv_obj_set_pos(viewport, x, y); - lv_obj_set_size(viewport, width, height); - lv_obj_clear_flag(viewport, LV_OBJ_FLAG_SCROLLABLE); - // A content-sized, single-line label never starts LVGL's vertical marquee. - lv_obj_t *content = label(viewport, text, 0, 0, LV_SIZE_CONTENT, - font->line_height, font, 0xFFFFFF, LV_LABEL_LONG_CLIP); - lv_obj_update_layout(content); - const int distance = lv_obj_get_width(content) - width; - if (distance <= 0) return; - lv_obj_set_x(content, state.offset(lv_tick_get(), distance)); - lv_anim_t animation; - lv_anim_init(&animation); - lv_anim_set_var(&animation, content); - lv_anim_set_user_data(&animation, &state); - lv_anim_set_values(&animation, 0, 1000); - lv_anim_set_duration(&animation, 1000); - lv_anim_set_repeat_count(&animation, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_custom_exec_cb(&animation, [](lv_anim_t *anim, int32_t) { - auto *content = static_cast(anim->var); - auto *state = static_cast(lv_anim_get_user_data(anim)); - const int distance = lv_obj_get_width(content) - lv_obj_get_width(lv_obj_get_parent(content)); - lv_obj_set_x(content, state->offset(lv_tick_get(), distance)); - }); - lv_anim_start(&animation); -} - void strong_label(lv_obj_t *root, const std::string &text, int x, int y, int w, int h, const lv_font_t *font, uint32_t color, lv_label_long_mode_t mode = LV_LABEL_LONG_DOT) @@ -167,6 +134,54 @@ void radio_option(lv_obj_t *root, int x, int y, const std::string &text, } // namespace +lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, + int width, int height, const lv_font_t *font, uint32_t color, + HorizontalMarquee &state, const std::string &key, + lv_text_align_t align, bool strong) +{ + state.select(key, lv_tick_get()); + lv_obj_t *viewport = lv_obj_create(parent); + lv_obj_remove_style_all(viewport); + lv_obj_set_pos(viewport, x, y); + lv_obj_set_size(viewport, width, height); + lv_obj_clear_flag(viewport, LV_OBJ_FLAG_SCROLLABLE); + // A content-sized, single-line label never starts LVGL's vertical marquee. + lv_obj_t *content = nullptr; + if (strong) { + content = lv_obj_create(viewport); + lv_obj_remove_style_all(content); + lv_obj_set_size(content, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_clear_flag(content, LV_OBJ_FLAG_SCROLLABLE); + label(content, text, 0, 0, LV_SIZE_CONTENT, font->line_height, font, color); + label(content, text, 1, 0, LV_SIZE_CONTENT, font->line_height, font, color); + } else { + content = label(viewport, text, 0, 0, LV_SIZE_CONTENT, font->line_height, font, color); + } + lv_obj_update_layout(content); + const int distance = lv_obj_get_width(content) - width; + if (distance <= 0) { + if (align == LV_TEXT_ALIGN_CENTER) lv_obj_set_x(content, -distance / 2); + else if (align == LV_TEXT_ALIGN_RIGHT) lv_obj_set_x(content, -distance); + return viewport; + } + lv_obj_set_x(content, state.offset(lv_tick_get(), distance)); + lv_anim_t animation; + lv_anim_init(&animation); + lv_anim_set_var(&animation, content); + lv_anim_set_user_data(&animation, &state); + lv_anim_set_values(&animation, 0, 1000); + lv_anim_set_duration(&animation, 1000); + lv_anim_set_repeat_count(&animation, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_custom_exec_cb(&animation, [](lv_anim_t *anim, int32_t) { + auto *content = static_cast(anim->var); + auto *state = static_cast(lv_anim_get_user_data(anim)); + const int distance = lv_obj_get_width(content) - lv_obj_get_width(lv_obj_get_parent(content)); + lv_obj_set_x(content, state->offset(lv_tick_get(), distance)); + }); + lv_anim_start(&animation); + return viewport; +} + void render_exit_hint(lv_obj_t *root) { // Match Calculator's centered exit-hint card and dimmed backdrop. @@ -288,12 +303,12 @@ void CatalogDisplayPage::render(const PageRenderContext &context, label(root, model.empty_message, 137, 76, 178, 40, store_font(model.empty_message, 14), 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - horizontal_label(root, model.name, 137, 62, 178, 27, - store_font(model.name, 20, true), title_marquee_, model.name); + marquee_label(root, model.name, 137, 62, 178, 27, store_font(model.name, 20, true), + 0xFFFFFF, title_marquee_, model.name); label(root, model.version, 137, 90, 66, 22, store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - horizontal_label(root, model.author, 207, 90, 108, 22, - store_font(model.author, 14), author_marquee_, model.name + model.author); + marquee_label(root, model.author, 207, 90, 108, 22, store_font(model.author, 14), + 0xFFFFFF, author_marquee_, model.name + model.author); label(root, model.size, 137, 110, 68, 22, store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); label(root, model.updated, 207, 110, 110, 22, @@ -355,12 +370,13 @@ void CatalogDisplayPage::render_search(const PageRenderContext &context, box(root, 10, y, 300, 24, item.selected ? 0x142817 : 0x10171D, item.selected ? 0x7ED957 : 0x27313A, 1, 3); const std::string name = appstore::upper_ascii(item.name); - strong_label(root, name, 17, y + 2, 218, 14, - context.font_for_text(name, item.selected ? &lv_font_montserrat_12 : - &lv_font_montserrat_10), - item.selected ? 0xFFFFFF : 0xB8B8B8, - item.selected && appstore::utf8_display_width(name) > 24 - ? LV_LABEL_LONG_SCROLL_CIRCULAR : LV_LABEL_LONG_DOT); + const lv_font_t *name_font = context.font_for_text( + name, item.selected ? &lv_font_montserrat_12 : &lv_font_montserrat_10); + if (item.selected) + marquee_label(root, name, 17, y + 2, 218, 14, name_font, 0xFFFFFF, + search_marquee_, name, LV_TEXT_ALIGN_LEFT, true); + else + strong_label(root, name, 17, y + 2, 218, 14, name_font, 0xB8B8B8, LV_LABEL_LONG_DOT); label(root, appstore::one_line(item.meta.empty() ? "-" : item.meta, 28), 17, y + 14, 218, 9, &lv_font_montserrat_10, item.selected ? 0x7ED957 : 0x6E7681, @@ -643,16 +659,16 @@ void StoreSettingsPage::render(const PageRenderContext &context, const uint32_t nav = model.focus == 1 ? 0xFF6A3D : 0x6E7681; label(root, "<", 6, 85, 16, 22, store_font("", 20), nav); label(root, ">", 302, 85, 16, 22, store_font("", 20), nav); - horizontal_label(root, entry.name, 24, 86, 194, 20, - store_font(entry.name, 14), source_marquee_, entry.url + entry.name); + marquee_label(root, entry.name, 24, 86, 194, 20, store_font(entry.name, 14), + 0xFFFFFF, source_marquee_, entry.url + entry.name); lv_obj_t *count = label(root, entry.count + " apps", 224, 87, 72, 18, store_font("", 12), 0xCCCC33, LV_LABEL_LONG_DOT); lv_obj_set_style_text_align(count, LV_TEXT_ALIGN_RIGHT, 0); label(root, "URL", 24, 111, 32, 18, store_font("", 12), 0x58A6FF); box(root, 60, 108, 236, 24, 0x111923, 0x2A3A46, 1, 2); const std::string url = entry.builtin ? model.registry_url : entry.url; - horizontal_label(root, url, 66, 112, 224, 18, - store_font(url, 12), url_marquee_, url); + marquee_label(root, url, 66, 112, 224, 18, store_font(url, 12), 0xFFFFFF, + url_marquee_, url); } if (!model.status.empty()) { // Keep the full status readable without taking space from the action row. diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index 8414514..f0a28fe 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -19,6 +19,13 @@ namespace appstore_ui { void render_exit_hint(lv_obj_t *root); +// One line of text; when it does not fit, it bounces like APPLaunch's +// selected title. Text that fits is placed according to align. +lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, + int width, int height, const lv_font_t *font, uint32_t color, + HorizontalMarquee &state, const std::string &key, + lv_text_align_t align = LV_TEXT_ALIGN_LEFT, bool strong = false); + struct PageRenderContext { std::function prepare; std::function draw_system_bar; @@ -56,6 +63,7 @@ class CatalogDisplayPage : public AppStoreUiPage private: HorizontalMarquee title_marquee_; HorizontalMarquee author_marquee_; + HorizontalMarquee search_marquee_; }; class AppDetailPage : public AppStoreUiPage diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index 752af03..76c5c4b 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -119,10 +119,8 @@ void AppStorePresenter::draw_category_selector(lv_obj_t *root) if (!images_.draw_packaged(root, "store_arrow_left.png", 14, 27)) strong_label(root, "<", 14, 24, 14, 18, store_font("", 20), 0xFF6A3D); const std::string category = appstore::upper_ascii(session_.catalog.current_category_name()); - lv_obj_t *name = label(root, category, 28, 24, 86, 20, - store_font(category, 14, true), 0xFFFFFF, - LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_obj_set_style_text_align(name, LV_TEXT_ALIGN_CENTER, 0); + marquee_label(root, category, 28, 24, 86, 20, store_font(category, 14, true), 0xFFFFFF, + category_marquee_, category, LV_TEXT_ALIGN_CENTER); if (!images_.draw_packaged(root, "store_arrow_right.png", 116, 27)) strong_label(root, ">", 116, 24, 14, 18, store_font("", 20), 0xFF6A3D); } diff --git a/main/ui/appstore_presenter.hpp b/main/ui/appstore_presenter.hpp index fb3ada8..d3f42ed 100644 --- a/main/ui/appstore_presenter.hpp +++ b/main/ui/appstore_presenter.hpp @@ -45,6 +45,7 @@ class AppStorePresenter AppStoreImageRenderer &images_; std::function draw_system_bar_; lv_obj_t *rendered_root_ = nullptr; + HorizontalMarquee category_marquee_; }; } // namespace appstore_ui diff --git a/main/ui/horizontal_marquee.hpp b/main/ui/horizontal_marquee.hpp index 341c04e..9d88c4c 100644 --- a/main/ui/horizontal_marquee.hpp +++ b/main/ui/horizontal_marquee.hpp @@ -13,7 +13,14 @@ namespace appstore_ui { // Keep the reading position across redraws of the system/status bars. +// Long text bounces like APPLaunch's selected title: hold, scroll to the end, +// hold, scroll back. Speed and clamps match LVGL's LONG_SCROLL default. struct HorizontalMarquee { + static constexpr uint32_t kPauseMs = 2000; + static constexpr uint32_t kPixelsPerSecond = 40; + static constexpr uint32_t kMinTravelMs = 300; + static constexpr uint32_t kMaxTravelMs = 10000; + std::string key; uint32_t started_at = 0; @@ -27,15 +34,18 @@ struct HorizontalMarquee { int offset(uint32_t now, int distance) const { if (distance <= 0) return 0; - constexpr uint32_t start_pause = 2000, end_pause = 1500; - constexpr uint32_t pixels_per_second = 20; - const uint32_t travel = (static_cast(distance) * 1000 + - pixels_per_second - 1) / pixels_per_second; + const uint32_t travel = std::clamp( + static_cast(static_cast(distance) * 1000 / kPixelsPerSecond), + kMinTravelMs, kMaxTravelMs); const uint32_t phase = static_cast(now - started_at) % - (start_pause + travel + end_pause); - if (phase < start_pause) return 0; - return -std::min(distance, static_cast( - static_cast(phase - start_pause) * pixels_per_second / 1000)); + (2 * (kPauseMs + travel)); + const auto moved = [&](uint32_t elapsed) { + return static_cast(static_cast(elapsed) * distance / travel); + }; + if (phase < kPauseMs) return 0; + if (phase < kPauseMs + travel) return -moved(phase - kPauseMs); + if (phase < 2 * kPauseMs + travel) return -distance; + return moved(phase - 2 * kPauseMs - travel) - distance; } }; diff --git a/tests/test_horizontal_marquee.cpp b/tests/test_horizontal_marquee.cpp index 5db3b16..959bc06 100644 --- a/tests/test_horizontal_marquee.cpp +++ b/tests/test_horizontal_marquee.cpp @@ -10,15 +10,24 @@ int main() { appstore_ui::HorizontalMarquee m; m.select("Long title",100); assert(m.offset(2099,300)==0); - assert(m.offset(3100,300)==-20); + assert(m.offset(3100,300)==-40); m.select("Long title",5100); // A status refresh must not restart reading. - assert(m.offset(5100,300)==-60); + assert(m.offset(5100,300)==-120); assert(m.offset(5100,0)==0); - assert(m.offset(17100,300)==-300); - assert(m.offset(18000,300)==-300); - assert(m.offset(18600,300)==0); + assert(m.offset(9600,300)==-300); // Hold at the end... + assert(m.offset(11599,300)==-300); + assert(m.offset(15350,300)==-150); // ...then scroll back instead of jumping. + assert(m.offset(19099,300)==-1); + assert(m.offset(19100,300)==0); + assert(m.offset(21100,300)==0); + appstore_ui::HorizontalMarquee clamped; + clamped.select("Short",0); + assert(clamped.offset(2150,4)==-2); // A tiny overflow still takes 300 ms. + assert(clamped.offset(2300,4)==-4); + assert(clamped.offset(7000,1000)==-500); // A huge one is capped at 10 s. m.select("Other app",19000); assert(m.offset(20000,300)==0); m.select("Wrap",0xfffffff0U); assert(m.offset(0x20U,300)==0); + assert(m.offset(2990U,300)==-40); } From be99b969fd44750b3dc02366ccc6f46db066054f Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 15:37:21 +0300 Subject: [PATCH 02/19] feat(store): realign the app selection screen --- README.md | 5 +- main/ui/appstore_image_renderer.cpp | 14 ++-- main/ui/appstore_image_renderer.hpp | 3 +- main/ui/appstore_pages.cpp | 44 ++++++++---- main/ui/appstore_pages.hpp | 14 ++++ main/ui/appstore_presenter.cpp | 103 +++++++++++++++++++++++----- 6 files changed, 144 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index f213871..949b038 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,10 @@ pause for two seconds, scroll horizontally at 40 pixels per second to the end, pause again, and scroll back. Status-bar updates keep the current reading position, and labels never scroll vertically. In search results only the selected name scrolls; the others end with an ellipsis. -The header shows the selection within the category and the total catalog size. +The category's position in the category list (for example `2 / 5`) is shown +under its name. The selected app's position in the category (for example +`1 / 4`) is shown beside its icon, and the catalog size is shown next to the +Store icon on the category row. Press `4` for settings, `5` for share code, `6` for search, `7` for install/reinstall, and `8` or Enter for details. AppStore syncs the registry automatically when it starts. diff --git a/main/ui/appstore_image_renderer.cpp b/main/ui/appstore_image_renderer.cpp index ce9c25e..a7d9064 100644 --- a/main/ui/appstore_image_renderer.cpp +++ b/main/ui/appstore_image_renderer.cpp @@ -6,6 +6,7 @@ #include "appstore_image_renderer.hpp" +#include "appstore_pages.hpp" #include "appstore_paths.hpp" #include "cp0_lvgl_app.h" @@ -25,23 +26,23 @@ const char *AppStoreImageRenderer::retain_source(std::string source) return sources_.back().c_str(); } -bool AppStoreImageRenderer::draw_packaged(lv_obj_t *root, const std::string &name, int x, int y) +lv_obj_t *AppStoreImageRenderer::draw_packaged(lv_obj_t *root, const std::string &name, int x, int y) { #if LV_USE_LODEPNG && LV_USE_FS_POSIX const char *path = cp0_file_path_c(name.c_str()); - if (!path || !path[0]) return false; + if (!path || !path[0]) return nullptr; lv_obj_t *image = lv_image_create(root); lv_image_set_src(image, path); lv_obj_update_layout(image); if (lv_obj_get_width(image) <= 0 || lv_obj_get_height(image) <= 0) { lv_obj_delete(image); - return false; + return nullptr; } lv_obj_set_pos(image, x, y); - return true; + return image; #else (void)root; (void)name; (void)x; (void)y; - return false; + return nullptr; #endif } @@ -51,7 +52,8 @@ bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app #if LV_USE_LODEPNG && LV_USE_FS_POSIX const std::string path = icon_file_path(app_dir, app); if (path.empty()) return false; - constexpr int x = 39, y = 65, width = 60, height = 60; + constexpr int x = catalog_home::kIconX, y = catalog_home::kIconY; + constexpr int width = catalog_home::kIconSize, height = catalog_home::kIconSize; lv_obj_t *clip = lv_obj_create(root); lv_obj_remove_style_all(clip); lv_obj_set_pos(clip, x, y); diff --git a/main/ui/appstore_image_renderer.hpp b/main/ui/appstore_image_renderer.hpp index 0185047..e0bc5a9 100644 --- a/main/ui/appstore_image_renderer.hpp +++ b/main/ui/appstore_image_renderer.hpp @@ -18,7 +18,8 @@ class AppStoreImageRenderer { public: void begin_frame(); - bool draw_packaged(lv_obj_t *root, const std::string &name, int x, int y); + // Returns the image so callers can align it by its real size; null on failure. + lv_obj_t *draw_packaged(lv_obj_t *root, const std::string &name, int x, int y); bool draw_app_icon(lv_obj_t *root, const std::string &app_dir, const appstore::StoreApp &app); bool draw_screenshot(lv_obj_t *root, const std::string &path); diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index a2bf826..a838b1b 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -134,6 +134,14 @@ void radio_option(lv_obj_t *root, int x, int y, const std::string &text, } // namespace +int glyph_middle(const lv_font_t *font, uint32_t letter) +{ + if (!font) return 0; + lv_font_glyph_dsc_t glyph = {}; + if (!lv_font_get_glyph_dsc(font, &glyph, letter, 0)) return font->line_height / 2; + return font->line_height - font->base_line - glyph.ofs_y - glyph.box_h / 2; +} + lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, int width, int height, const lv_font_t *font, uint32_t color, HorizontalMarquee &state, const std::string &key, @@ -294,24 +302,32 @@ void CatalogDisplayPage::render(const PageRenderContext &context, box(root, 0, 20, 320, 150, 0x081010, 0x081010, 0); draw_category(); draw_icon(); - label(root, "In category: " + std::to_string(model.show_empty ? 0 : model.selected_index + 1) + - "/" + std::to_string(model.app_count), 138, 26, 116, 18, - store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT); - label(root, "All: " + std::to_string(model.total_count), 256, 26, 64, 18, - store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT); + const int details_width = catalog_home::kDetailsRight - catalog_home::kDetailsX; if (model.show_empty) { - label(root, model.empty_message, 137, 76, 178, 40, - store_font(model.empty_message, 14), 0xFFFFFF, LV_LABEL_LONG_WRAP); + const lv_font_t *font = store_font(model.empty_message, 14); + label(root, model.empty_message, catalog_home::kDetailsX, + catalog_home::kIconCenterY - font->line_height, details_width, + font->line_height * 2, font, 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - marquee_label(root, model.name, 137, 62, 178, 27, store_font(model.name, 20, true), - 0xFFFFFF, title_marquee_, model.name); - label(root, model.version, 137, 90, 66, 22, + // Keep the name and its details one block, centered on the icon. + const lv_font_t *name_font = store_font(model.name, 20, true); + constexpr int row_height = 22, row_gap = 3, name_gap = 4; + const int stack = name_font->line_height + name_gap + row_height + row_gap + row_height; + // The name's line box keeps room below the baseline, so the block's + // center sits below its visible text. Nudge it down to match the icon. + int y = catalog_home::kIconCenterY - stack / 2 + 4; + marquee_label(root, model.name, catalog_home::kDetailsX, y, details_width, + name_font->line_height, name_font, 0xFFFFFF, title_marquee_, model.name); + y += name_font->line_height + name_gap; + label(root, model.version, catalog_home::kDetailsX, y, 66, row_height, store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - marquee_label(root, model.author, 207, 90, 108, 22, store_font(model.author, 14), - 0xFFFFFF, author_marquee_, model.name + model.author); - label(root, model.size, 137, 110, 68, 22, + marquee_label(root, model.author, catalog_home::kDetailsX + 70, y, details_width - 70, + row_height, store_font(model.author, 14), 0xFFFFFF, + author_marquee_, model.name + model.author); + y += row_height + row_gap; + label(root, model.size, catalog_home::kDetailsX, y, 68, row_height, store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - label(root, model.updated, 207, 110, 110, 22, + label(root, model.updated, catalog_home::kDetailsX + 70, y, details_width - 70, row_height, store_font(model.updated, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); } if (model.show_status) scrolling_status_label(root, model.status, 110, 136, 205, 12); diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index f0a28fe..28a18e9 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -19,6 +19,20 @@ namespace appstore_ui { void render_exit_hint(lv_obj_t *root); +// Middle of a glyph's ink, measured from the top of the font's line box. +int glyph_middle(const lv_font_t *font, uint32_t letter); + +// Home catalog geometry shared by the page and the icon panel. +namespace catalog_home { +constexpr int kIconX = 39; +constexpr int kIconY = 65; +constexpr int kIconSize = 60; +constexpr int kIconCenterY = kIconY + kIconSize / 2; +constexpr int kDetailsX = 148; +constexpr int kDetailsRight = 315; +constexpr uint32_t kMuted = 0x8B949E; +} // namespace catalog_home + // One line of text; when it does not fit, it bounces like APPLaunch's // selected title. Text that fits is placed according to align. lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index 76c5c4b..2c02d04 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -15,9 +15,10 @@ namespace appstore_ui { namespace { -constexpr int kHomeIconX = 39; -constexpr int kHomeIconY = 65; -constexpr int kHomeIconSize = 60; +constexpr int kCategoryX = 28; +constexpr int kCategoryY = 24; +constexpr int kCategoryWidth = 86; +constexpr int kCategoryPositionY = 37; constexpr uint32_t kStatusVisibleMs = 6000; lv_obj_t *label(lv_obj_t *parent, const std::string &text, int x, int y, int w, int h, @@ -79,6 +80,46 @@ std::string app_initial(const appstore::StoreApp &app) return "A"; } +// Selection inside the current category, centered on the icon. +void draw_selection_position(lv_obj_t *root, int index, int count) +{ + const std::string text = std::to_string(index) + " / " + std::to_string(count); + const lv_font_t *font = store_font("", 12); + // The name and tags start at kDetailsX; stay clear of them. + label(root, text, catalog_home::kIconX + catalog_home::kIconSize + 4, + catalog_home::kIconCenterY - glyph_middle(font, '0'), + catalog_home::kDetailsX - (catalog_home::kIconX + catalog_home::kIconSize + 4), + font->line_height, font, catalog_home::kMuted); +} + +// Whole-catalog count, sitting on the same line as the category name. +void draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, + int count, int category_middle) +{ + // The Store artwork is a badge with its own padding, so the box has to be + // larger than the category's letter height to look the same size. + constexpr int icon_size = 18, gap = 4, right = 312; + const std::string text = std::to_string(count); + const lv_font_t *font = store_font("", 14); + lv_point_t size = {}; + lv_text_get_size(&size, text.c_str(), font, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + const int text_x = right - size.x; + label(root, text, text_x, category_middle - glyph_middle(font, '0'), size.x + 4, + font->line_height, font, catalog_home::kMuted); + const int icon_x = text_x - gap - icon_size; + if (lv_obj_t *icon = images.draw_packaged(root, "store_100.png", icon_x, 0)) { + const int scale = std::max(1, std::min(icon_size * 256 / lv_obj_get_width(icon), + icon_size * 256 / lv_obj_get_height(icon))); + lv_image_set_scale(icon, static_cast(scale)); + lv_image_set_inner_align(icon, LV_IMAGE_ALIGN_CENTER); + lv_obj_set_size(icon, icon_size, icon_size); + lv_obj_set_y(icon, category_middle - icon_size / 2); + return; + } + strong_label(root, "*", icon_x, category_middle - glyph_middle(font, '*'), icon_size, + font->line_height, font, catalog_home::kMuted); +} + } // namespace AppStorePresenter::AppStorePresenter( @@ -116,32 +157,60 @@ void AppStorePresenter::prepare(AppStoreUiPage &page) void AppStorePresenter::draw_category_selector(lv_obj_t *root) { - if (!images_.draw_packaged(root, "store_arrow_left.png", 14, 27)) - strong_label(root, "<", 14, 24, 14, 18, store_font("", 20), 0xFF6A3D); const std::string category = appstore::upper_ascii(session_.catalog.current_category_name()); - marquee_label(root, category, 28, 24, 86, 20, store_font(category, 14, true), 0xFFFFFF, + const lv_font_t *font = store_font(category, 14, true); + marquee_label(root, category, kCategoryX, kCategoryY, kCategoryWidth, 20, font, 0xFFFFFF, category_marquee_, category, LV_TEXT_ALIGN_CENTER); - if (!images_.draw_packaged(root, "store_arrow_right.png", 116, 27)) - strong_label(root, ">", 116, 24, 14, 18, store_font("", 20), 0xFF6A3D); + // The name is uppercase: center on its capitals, not on the line box, + // which also reserves room below the baseline for descenders. + const int middle = kCategoryY + glyph_middle(font, 'H'); + auto chevron = [&](const char *image, const char *fallback, int x) { + if (lv_obj_t *arrow = images_.draw_packaged(root, image, x, 0)) { + lv_obj_set_y(arrow, middle - lv_obj_get_height(arrow) / 2); + return; + } + const lv_font_t *arrow_font = store_font("", 20); + strong_label(root, fallback, x, middle - glyph_middle(arrow_font, fallback[0]), 14, + arrow_font->line_height, arrow_font, 0xFF6A3D); + }; + chevron("store_arrow_left.png", "<", 14); + chevron("store_arrow_right.png", ">", 116); + draw_catalog_total(root, images_, static_cast(session_.catalog.apps().size()), middle); + + const auto &categories = session_.catalog.categories(); + const int index = session_.catalog.category_index(); + if (index < 0 || index >= static_cast(categories.size())) return; + lv_obj_t *position = label(root, std::to_string(index + 1) + " / " + + std::to_string(categories.size()), + kCategoryX, kCategoryPositionY, kCategoryWidth, 12, + &lv_font_montserrat_10, 0x8B949E); + lv_obj_set_style_text_align(position, LV_TEXT_ALIGN_CENTER, 0); } void AppStorePresenter::draw_home_icon_panel(lv_obj_t *root, const appstore::StoreApp *app) { - const int arrow_x = kHomeIconX + (kHomeIconSize - 14) / 2; - if (!images_.draw_packaged(root, "store_arrow_up.png", arrow_x, 48)) - center_strong_label(root, "^", kHomeIconX + 16, 46, 28, 18, + using catalog_home::kIconSize; + using catalog_home::kIconX; + using catalog_home::kIconY; + const int arrow_x = kIconX + (kIconSize - 14) / 2; + if (!images_.draw_packaged(root, "store_arrow_up.png", arrow_x, 51)) + center_strong_label(root, "^", kIconX + 16, 49, 28, 18, &lv_font_montserrat_20, 0xFF6A3D); if (!app) { - center_strong_label(root, "-", kHomeIconX + 22, kHomeIconY + 24, 24, 22, + center_strong_label(root, "-", kIconX + 22, kIconY + 24, 24, 22, &lv_font_montserrat_20, 0x9A9A9A); } else if (!images_.draw_app_icon(root, session_.app_dir, *app)) { - center_strong_label(root, app_initial(*app), kHomeIconX, kHomeIconY + 21, - kHomeIconSize, 28, &lv_font_montserrat_20, + center_strong_label(root, app_initial(*app), kIconX, kIconY + 21, + kIconSize, 28, &lv_font_montserrat_20, app->installed ? 0x52D05D : 0xFFFFFF); } - if (!images_.draw_packaged(root, "store_arrow_down.png", arrow_x, 136)) - center_strong_label(root, "v", kHomeIconX + 16, 134, 28, 18, + const int index = session_.catalog.selected_index(); + const int count = static_cast(session_.catalog.visible().size()); + if (index >= 0 && index < count) + draw_selection_position(root, index + 1, count); + if (!images_.draw_packaged(root, "store_arrow_down.png", arrow_x, 133)) + center_strong_label(root, "v", kIconX + 16, 131, 28, 18, &lv_font_montserrat_20, 0xFF6A3D); } @@ -185,7 +254,7 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running) return images_.draw_thumbnail(parent, path, x, y); }, [this](lv_obj_t *parent, const std::string &name, int x, int y) { - return images_.draw_packaged(parent, name, x, y); + return images_.draw_packaged(parent, name, x, y) != nullptr; }, [this](const appstore::StoreApp &app) { AppStoreShortcutBar::render_detail( From d15c638c59031554a66b4cd95ef16c8a1f13e79b Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 15:37:39 +0300 Subject: [PATCH 03/19] feat(store): make the app details screen readable --- README.md | 18 +- main/ui/appstore_input_controller.cpp | 4 +- main/ui/appstore_pages.cpp | 222 +++++++++++++++------ main/ui/appstore_pages.hpp | 3 + main/ui/appstore_view_model_factory.cpp | 2 + main/ui/appstore_view_models.hpp | 2 + main/ui/detail_action_controller.cpp | 4 +- main/ui/detail_action_controller.hpp | 2 +- main/ui/detail_media_state.cpp | 28 ++- main/ui/detail_media_state.hpp | 11 +- tests/test_appstore_input_controller.cpp | 1 + tests/test_appstore_view_model_factory.cpp | 2 + tests/test_detail_media_state.cpp | 23 ++- 13 files changed, 238 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 949b038..45366f5 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,9 @@ selection to All. Long names bounce like the selected APPLaunch title: they pause for two seconds, scroll horizontally at 40 pixels per second to the end, pause again, and scroll back. Status-bar updates keep the current reading position, and labels never scroll vertically. In search results only the -selected name scrolls; the others end with an ellipsis. +selected name scrolls; the others end with an ellipsis. The selected app's +version, maintainer, size, and update date are shown in green, orange, blue, +and violet tags. The category's position in the category list (for example `2 / 5`) is shown under its name. The selected app's position in the category (for example `1 / 4`) is shown beside its icon, and the catalog size is shown next to the @@ -120,11 +122,15 @@ the hint without activating the page underneath. On other screens, short `Esc` keeps its back/cancel behavior. Hold `Esc` for three seconds to exit from any screen, including while the hint is open. -The detail page shows the complete combined summary and description, followed -by 160 x 85 screenshot previews loaded from the registry. `F/X` scrolls the -whole content area; the system bar and bottom actions stay fixed. Descriptions -wrap without a height limit or automatic scrolling. `Z/C` cycles screenshots; -apps without screenshots have no screenshot area. Detail actions are `4` back, +The detail page shows the app name, the same color-coded version, maintainer, +size, and update fields as the home screen, the install state, the complete +description, 160 x 85 screenshot previews loaded from the registry, and the +package and categories. `F/X` scrolls the whole content area with a short +glide, 24 pixels per press; holding the key scrolls continuously. The system +bar and bottom actions stay fixed, and status messages appear just above the +actions at any scroll position. Descriptions wrap without a height limit or +automatic scrolling. `Z/C` cycles screenshots; apps without screenshots have +no screenshot area. Detail actions are `4` back, `6` install/reinstall, `7` upgrade, and `8` remove, shown when applicable. The existing full-screen screenshot viewer remains accessible through `5`. diff --git a/main/ui/appstore_input_controller.cpp b/main/ui/appstore_input_controller.cpp index e1ac83d..8a7f814 100644 --- a/main/ui/appstore_input_controller.cpp +++ b/main/ui/appstore_input_controller.cpp @@ -126,9 +126,9 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) case Screen::Detail: { appstore::StoreApp *app = catalog_.ensure_selected(); if (key.code == KEY_UP || key.code == KEY_F || key.ch == 'f') - detail_.scroll_page(-1); + detail_.scroll_page(-1, now); else if (key.code == KEY_DOWN || key.code == KEY_X || key.ch == 'x') - detail_.scroll_page(1); + detail_.scroll_page(1, now); else if (key.code == KEY_LEFT || key.code == KEY_Z || key.ch == 'z') detail_.cycle_screenshot(-1, now); else if (key.code == KEY_RIGHT || key.code == KEY_C || key.ch == 'c') diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index a838b1b..e151b1c 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -80,6 +80,93 @@ lv_obj_t *box(lv_obj_t *root, int x, int y, int w, int h, uint32_t color, return obj; } +// A field keeps its color on the home and detail pages. +constexpr uint32_t kVersionColor = 0x7EE787; +constexpr uint32_t kMaintainerColor = 0xFFA657; +constexpr uint32_t kSizeColor = 0x79C0FF; +constexpr uint32_t kDateColor = 0xD2A8FF; + +void field_chip(lv_obj_t *parent, int x, int y, int w, int h, uint32_t color) +{ + // Keep the tint faint: the value is drawn in the same color on top. + lv_obj_t *chip = box(parent, x, y, w, h, color, color, 1, 5, LV_OPA_20); + lv_obj_set_style_border_opa(chip, LV_OPA_40, 0); +} + +void field_value(lv_obj_t *parent, const std::string &value, int x, int y, int w, + uint32_t color, HorizontalMarquee *marquee, const std::string &key) +{ + const lv_font_t *font = store_font(value, 14); + if (marquee) + marquee_label(parent, value, x, y, w, font->line_height, font, color, *marquee, key); + else + label(parent, value, x, y, w, font->line_height, font, color, LV_LABEL_LONG_DOT); +} + +void home_field(lv_obj_t *root, const std::string &value, int x, int y, int w, + uint32_t color, HorizontalMarquee *marquee = nullptr, + const std::string &key = {}) +{ + constexpr int height = 20, pad = 6; + field_chip(root, x, y, w, height, color); + const int line_height = store_font(value, 14)->line_height; + field_value(root, value, x + pad, y + (height - line_height) / 2, w - 2 * pad, + color, marquee, key); +} + +void detail_field(lv_obj_t *parent, const char *caption, const std::string &value, + int x, int y, int w, uint32_t color, HorizontalMarquee *marquee = nullptr, + const std::string &key = {}) +{ + constexpr int height = 31, pad = 7; + field_chip(parent, x, y, w, height, color); + lv_obj_t *title = label(parent, caption, x + pad, y + 2, w - 2 * pad, 12, + &lv_font_montserrat_10, color); + lv_obj_set_style_text_opa(title, LV_OPA_70, 0); + field_value(parent, value, x + pad, y + 13, w - 2 * pad, color, marquee, key); +} + +int detail_info_row(lv_obj_t *parent, const char *caption, const std::string &value, int y) +{ + label(parent, caption, 10, y + 2, 64, 12, &lv_font_montserrat_10, 0x8B949E); + lv_obj_t *text = label(parent, value, 76, y, 234, LV_SIZE_CONTENT, + store_font(value, 12), 0xC9D1D9, LV_LABEL_LONG_WRAP); + lv_obj_update_layout(text); + return y + lv_obj_get_height(text) + 4; +} + +// Content that runs under a fixed edge fades out instead of being cut mid-line. +void edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towards_bottom) +{ + lv_obj_t *fade = box(root, 0, y, 320, height, color, color, 0); + lv_obj_set_style_bg_grad_color(fade, lv_color_hex(color), 0); + lv_obj_set_style_bg_grad_dir(fade, LV_GRAD_DIR_VER, 0); + lv_obj_set_style_bg_main_opa(fade, towards_bottom ? LV_OPA_TRANSP : LV_OPA_COVER, 0); + lv_obj_set_style_bg_grad_opa(fade, towards_bottom ? LV_OPA_COVER : LV_OPA_TRANSP, 0); +} + +void glide_page(lv_obj_t *document, DetailMediaState &media, uint32_t now) +{ + const uint32_t remaining = media.page_glide_remaining(now); + if (remaining == 0) return; + lv_anim_t animation; + lv_anim_init(&animation); + lv_anim_set_var(&animation, document); + lv_anim_set_user_data(&animation, &media); + lv_anim_set_values(&animation, 0, static_cast(remaining)); + lv_anim_set_duration(&animation, remaining); + lv_anim_set_custom_exec_cb(&animation, [](lv_anim_t *anim, int32_t) { + auto *media = static_cast(lv_anim_get_user_data(anim)); + lv_obj_set_y(static_cast(anim->var), -media->page_scroll_at(lv_tick_get())); + }); + // The animation timer can finish a frame early; land exactly on the target. + lv_anim_set_completed_cb(&animation, [](lv_anim_t *anim) { + auto *media = static_cast(lv_anim_get_user_data(anim)); + lv_obj_set_y(static_cast(anim->var), -media->page_scroll()); + }); + lv_anim_start(&animation); +} + void screenshot_arrow(lv_obj_t *root, int x, int y, bool right, uint32_t color) { // Keep navigation visible without font glyphs when packaged arrows cannot load. @@ -309,26 +396,25 @@ void CatalogDisplayPage::render(const PageRenderContext &context, catalog_home::kIconCenterY - font->line_height, details_width, font->line_height * 2, font, 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - // Keep the name and its details one block, centered on the icon. + // Keep the name and its detail tags one block, centered on the icon. const lv_font_t *name_font = store_font(model.name, 20, true); - constexpr int row_height = 22, row_gap = 3, name_gap = 4; - const int stack = name_font->line_height + name_gap + row_height + row_gap + row_height; + constexpr int chip_height = 20, chip_gap = 3, name_gap = 4; + constexpr int chip_width = 70, column_gap = 4; + const int stack = name_font->line_height + name_gap + chip_height + chip_gap + chip_height; // The name's line box keeps room below the baseline, so the block's // center sits below its visible text. Nudge it down to match the icon. int y = catalog_home::kIconCenterY - stack / 2 + 4; marquee_label(root, model.name, catalog_home::kDetailsX, y, details_width, name_font->line_height, name_font, 0xFFFFFF, title_marquee_, model.name); y += name_font->line_height + name_gap; - label(root, model.version, catalog_home::kDetailsX, y, 66, row_height, - store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - marquee_label(root, model.author, catalog_home::kDetailsX + 70, y, details_width - 70, - row_height, store_font(model.author, 14), 0xFFFFFF, - author_marquee_, model.name + model.author); - y += row_height + row_gap; - label(root, model.size, catalog_home::kDetailsX, y, 68, row_height, - store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - label(root, model.updated, catalog_home::kDetailsX + 70, y, details_width - 70, row_height, - store_font(model.updated, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); + const int value_width = details_width - chip_width - column_gap; + home_field(root, model.version, catalog_home::kDetailsX, y, chip_width, kVersionColor); + home_field(root, model.author, catalog_home::kDetailsX + chip_width + column_gap, y, + value_width, kMaintainerColor, &author_marquee_, model.name + model.author); + y += chip_height + chip_gap; + home_field(root, model.size, catalog_home::kDetailsX, y, chip_width, kSizeColor); + home_field(root, model.updated, catalog_home::kDetailsX + chip_width + column_gap, y, + value_width, kDateColor); } if (model.show_status) scrolling_status_label(root, model.status, 110, 136, 205, 12); draw_shortcuts(); @@ -418,7 +504,7 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView context.draw_system_bar(); lv_obj_t *root = screen(); constexpr uint32_t background = 0x081010; - constexpr uint32_t blue = 0x0099DD; + constexpr int viewport_y = 20; constexpr int viewport_height = 129; box(root, 0, 20, 320, 150, background, background, 0); if (!model.has_app) { @@ -428,7 +514,7 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView // Clip the entire detail document between the system bar and fixed action row. lv_obj_t *viewport = lv_obj_create(root); lv_obj_remove_style_all(viewport); - lv_obj_set_pos(viewport, 0, 20); + lv_obj_set_pos(viewport, 0, viewport_y); lv_obj_set_size(viewport, 320, viewport_height); lv_obj_clear_flag(viewport, LV_OBJ_FLAG_SCROLLABLE); lv_obj_t *document = lv_obj_create(viewport); @@ -436,51 +522,46 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView lv_obj_set_width(document, 320); lv_obj_clear_flag(document, LV_OBJ_FLAG_SCROLLABLE); - auto text = [&](const std::string &value, int x, int y, int width, - int size, uint32_t color, bool wrap = false) { - return label(document, value, x, y, width, wrap ? LV_SIZE_CONTENT : size + 6, - store_font(value, size), color, - wrap ? LV_LABEL_LONG_WRAP : LV_LABEL_LONG_DOT); - }; - box(document, 0, 0, 320, 22, 0x007AC2, 0x007AC2, 0); - auto header_text = [&](const std::string &value, int x, int width) { - const lv_font_t *font = store_font(value, 14); - // Center the line box, with a one-pixel optical correction for the baseline. - const int y = std::max(0, (22 - static_cast(font->line_height)) / 2 + 1); - return label(document, value, x, y, width, font->line_height, - font, 0xFFFFFF, LV_LABEL_LONG_DOT); - }; - header_text(model.app.name, 16, 120); - header_text(model.app.version, 142, 78); - auto *author = header_text(model.app.author.empty() ? "-" : model.app.author, 226, 84); - lv_obj_set_style_text_align(author, LV_TEXT_ALIGN_RIGHT, 0); - - text("State", 10, 24, 48, 12, blue); - text(model.state, 60, 24, 96, 12, 0xFFFFFF); - text("Size", 160, 24, 48, 12, blue); - text(model.app.size, 210, 24, 105, 12, 0xFFFFFF); - text("Updated", 10, 41, 48, 10, blue); - text(model.updated, 60, 41, 96, 10, 0xFFFFFF); - text("Package", 160, 41, 48, 10, blue); - text(model.app.package.empty() ? "-" : model.app.package, 210, 41, 105, 10, 0xFFFFFF); - text("Category", 10, 59, 48, 10, blue); - auto *categories = text(model.categories, 60, 59, 250, 10, 0xFFFFFF, true); - lv_obj_update_layout(categories); - const int description_y = std::max(77, 59 + lv_obj_get_height(categories) + 6); - text("Desc", 10, description_y, 48, 12, blue); - auto *description = text(model.description, 60, description_y, 250, 12, 0xFFFFFF, true); - lv_obj_set_style_text_line_space(description, 1, 0); + const appstore::StoreApp &app = model.app; + const lv_font_t *title_font = store_font(app.name, 20, true); + marquee_label(document, app.name, 10, 4, 300, title_font->line_height, title_font, + 0xFFFFFF, title_marquee_, app.id + app.name); + int y = 8 + title_font->line_height; + // Same fields, arrangement and colors as the home page. + detail_field(document, "VERSION", model.version, 10, y, 146, kVersionColor); + detail_field(document, "MAINTAINER", model.author, 164, y, 146, kMaintainerColor, + &author_marquee_, app.id + model.author); + y += 34; + detail_field(document, "SIZE", app.size, 10, y, 146, kSizeColor); + detail_field(document, "UPDATED", model.updated, 164, y, 146, kDateColor); + y += 36; + + const uint32_t state_color = !app.installed ? 0x6E7681 : + (appstore::can_upgrade_app(app) ? 0xF0B429 : 0x52D05D); + box(document, 11, y + 5, 8, 8, state_color, state_color, 0, 4); + label(document, model.state, 25, y, 285, 17, store_font(model.state, 14), + app.installed ? 0xE6EDF3 : 0xB1BAC4, LV_LABEL_LONG_DOT); + y += 23; + box(document, 10, y, 300, 1, 0x1E2A30, 0x1E2A30, 0); + y += 7; + lv_obj_t *description = label(document, model.description, 10, y, 300, LV_SIZE_CONTENT, + store_font(model.description, 12), 0xC9D1D9, + LV_LABEL_LONG_WRAP); + lv_obj_set_style_text_line_space(description, 2, 0); lv_obj_update_layout(description); - int bottom = description_y + lv_obj_get_height(description); - if (model.show_status) { - auto *status = text(model.status, 60, bottom + 6, 250, 12, 0xCCCC33, true); - lv_obj_update_layout(status); - bottom += 6 + lv_obj_get_height(status); - } - media.normalize_images(model.app.id, static_cast(screenshots.size())); + y += lv_obj_get_height(description) + 10; + + media.normalize_images(app.id, static_cast(screenshots.size())); if (!screenshots.empty()) { - const int shot_y = bottom + 8; const int index = media.image_index(); + label(document, "SCREENSHOTS", 10, y, 150, 12, &lv_font_montserrat_10, 0x8B949E); + if (screenshots.size() > 1) { + lv_obj_t *count = label(document, std::to_string(index + 1) + "/" + + std::to_string(screenshots.size()), 250, y, 60, 12, + &lv_font_montserrat_10, 0x8B949E); + lv_obj_set_style_text_align(count, LV_TEXT_ALIGN_RIGHT, 0); + } + const int shot_y = y + 16; // One complete 160 x 85 preview and a glimpse of the next image. draw_thumbnail(document, screenshots[index], 20, shot_y); if (screenshots.size() > 1) { @@ -490,13 +571,28 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView if (!draw_packaged(document, "store_arrow_right.png", 304, shot_y + 35)) screenshot_arrow(document, 304, shot_y + 33, true, 0xFF6A3D); } - bottom = shot_y + 85; + y = shot_y + 85 + 10; + } + y = detail_info_row(document, "PACKAGE", app.package.empty() ? "-" : app.package, y); + y = detail_info_row(document, "CATEGORY", model.categories, y); + y += 6; + lv_obj_set_height(document, y); + media.normalize_page(app.id, y, viewport_height); + const uint32_t now = lv_tick_get(); + lv_obj_set_y(document, -media.page_scroll_at(now)); + glide_page(document, media, now); + + if (media.page_scroll() > 0) + edge_fade(root, viewport_y, 10, background, false); + if (media.page_scroll() < y - viewport_height) + edge_fade(root, viewport_y + viewport_height - 12, 12, background, true); + if (model.show_status) { + // Fixed above the actions so feedback is visible at any scroll position. + lv_obj_t *toast = box(root, 0, 132, 320, 17, background, 0x2A3A46, 1); + lv_obj_set_style_border_side(toast, LV_BORDER_SIDE_TOP, 0); + scrolling_status_label(root, model.status, 10, 135, 300, 12); } - bottom += 8; - lv_obj_set_height(document, bottom); - media.normalize_page(model.app.id, bottom, viewport_height); - lv_obj_set_y(document, -media.page_scroll()); - draw_shortcuts(model.app); + draw_shortcuts(app); } void AppDetailPage::render_confirmation(const PageRenderContext &context, diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index 28a18e9..5ff446c 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -98,6 +98,9 @@ class AppDetailPage : public AppStoreUiPage void render_screenshot_overlay(const PageRenderContext &context, const ScreenshotOverlayViewModel &model, const std::function &draw_background); +private: + HorizontalMarquee title_marquee_; + HorizontalMarquee author_marquee_; }; class StoreSettingsPage : public AppStoreUiPage diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 9b2bff0..3470686 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -108,6 +108,8 @@ AppDetailViewModel AppStoreViewModelFactory::detail(StoreApp *selected, uint32_t model.app = *selected; model.app.size = human_size(selected->size); model.title = single_line(selected->name) + " " + single_line(selected->version); + model.version = single_line(selected->version.empty() ? "-" : selected->version); + model.author = single_line(selected->author.empty() ? "-" : selected->author); model.state = selected->installed ? "Installed" : "Not installed"; if (selected->installed && !selected->installed_version.empty()) model.state += " " + one_line(selected->installed_version, 10); diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index f9c681b..d7518d7 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -73,6 +73,8 @@ struct AppDetailViewModel { bool has_app = false; appstore::StoreApp app; std::string title; + std::string version; + std::string author; std::string state; std::string updated; bool installable = false; diff --git a/main/ui/detail_action_controller.cpp b/main/ui/detail_action_controller.cpp index 7d0643d..7292c26 100644 --- a/main/ui/detail_action_controller.cpp +++ b/main/ui/detail_action_controller.cpp @@ -200,9 +200,9 @@ void DetailActionController::ensure_screenshots() if (start_screenshots_(app->id)) session_.detail_media.begin_loading(app->id); } -void DetailActionController::scroll_page(int delta) +void DetailActionController::scroll_page(int delta, uint32_t now) { - session_.detail_media.scroll_page(delta); + session_.detail_media.scroll_page(delta, now); session_.status.value().clear(); } diff --git a/main/ui/detail_action_controller.hpp b/main/ui/detail_action_controller.hpp index 6726734..e1f4ce0 100644 --- a/main/ui/detail_action_controller.hpp +++ b/main/ui/detail_action_controller.hpp @@ -42,7 +42,7 @@ class DetailActionController void cycle_screenshot(int delta, uint32_t now); bool open_screenshots(uint32_t now); void ensure_screenshots(); - void scroll_page(int delta); + void scroll_page(int delta, uint32_t now); private: appstore::StoreApp *selected_app(); diff --git a/main/ui/detail_media_state.cpp b/main/ui/detail_media_state.cpp index e8d970b..c0f0802 100644 --- a/main/ui/detail_media_state.cpp +++ b/main/ui/detail_media_state.cpp @@ -42,14 +42,38 @@ void DetailMediaState::normalize_page(const std::string &app_id, int content_hei if (page_app_id_ != app_id) { page_app_id_ = app_id; page_scroll_ = 0; + page_scroll_from_ = 0; } page_max_scroll_ = std::max(0, content_height - viewport_height); page_scroll_ = std::clamp(page_scroll_, 0, page_max_scroll_); + page_scroll_from_ = std::clamp(page_scroll_from_, 0, page_max_scroll_); } -void DetailMediaState::scroll_page(int delta) +void DetailMediaState::scroll_page(int delta, uint32_t now) { - page_scroll_ = std::clamp(page_scroll_ + delta * 24, 0, page_max_scroll_); + const int target = std::clamp(page_scroll_ + delta * kPageStep, 0, page_max_scroll_); + if (target == page_scroll_) return; + // Start from the drawn position so key repeat keeps one continuous motion. + page_scroll_from_ = page_scroll_at(now); + page_scroll_ = target; + page_glide_tick_ = now; +} + +int DetailMediaState::page_scroll_at(uint32_t now) const +{ + const uint32_t left = page_glide_remaining(now); + if (left == 0) return page_scroll_; + // Cubic ease-out: moves as soon as the key is pressed, settles gently. + const int64_t total = static_cast(kPageGlideMs) * kPageGlideMs * kPageGlideMs; + const int64_t rest = static_cast(left) * left * left; + return page_scroll_ - static_cast((page_scroll_ - page_scroll_from_) * rest / total); +} + +uint32_t DetailMediaState::page_glide_remaining(uint32_t now) const +{ + const uint32_t elapsed = now - page_glide_tick_; + if (page_scroll_from_ == page_scroll_ || elapsed >= kPageGlideMs) return 0; + return kPageGlideMs - elapsed; } bool DetailMediaState::hide_overlay_if_elapsed(uint32_t now, uint32_t timeout_ms) diff --git a/main/ui/detail_media_state.hpp b/main/ui/detail_media_state.hpp index c1040bb..b649f80 100644 --- a/main/ui/detail_media_state.hpp +++ b/main/ui/detail_media_state.hpp @@ -14,11 +14,18 @@ namespace appstore_ui { class DetailMediaState { public: + static constexpr int kPageStep = 24; + static constexpr uint32_t kPageGlideMs = 180; + void normalize_images(const std::string &app_id, int image_count); void cycle_image(int delta, int image_count); void normalize_page(const std::string &app_id, int content_height, int viewport_height); - void scroll_page(int delta); + void scroll_page(int delta, uint32_t now); + // Target offset; the page glides there from where it was drawn. int page_scroll() const { return page_scroll_; } + // Time-based so a redraw in the middle of a glide continues it. + int page_scroll_at(uint32_t now) const; + uint32_t page_glide_remaining(uint32_t now) const; bool needs_loading(const std::string &app_id) const { return !loading_ && loading_app_id_ != app_id; } void show_overlay(uint32_t now); @@ -42,6 +49,8 @@ class DetailMediaState std::string loading_app_id_; std::string page_app_id_; int page_scroll_ = 0; + int page_scroll_from_ = 0; + uint32_t page_glide_tick_ = 0; int page_max_scroll_ = 0; }; diff --git a/tests/test_appstore_input_controller.cpp b/tests/test_appstore_input_controller.cpp index 95716c3..fc3d72b 100644 --- a/tests/test_appstore_input_controller.cpp +++ b/tests/test_appstore_input_controller.cpp @@ -210,6 +210,7 @@ int main() session.detail_media.normalize_page(detail_id, 400, 129); input.handle({KEY_X, 0, 'x'}, 186); assert(session.detail_media.page_scroll() == 24); + assert(session.detail_media.page_scroll_at(186) == 0); input.handle({KEY_F, 0, 'f'}, 187); assert(session.detail_media.page_scroll() == 0); session.catalog.selected_app()->images = "icon,one,two"; diff --git a/tests/test_appstore_view_model_factory.cpp b/tests/test_appstore_view_model_factory.cpp index b0c2fd5..9a58c03 100644 --- a/tests/test_appstore_view_model_factory.cpp +++ b/tests/test_appstore_view_model_factory.cpp @@ -80,6 +80,7 @@ int main() assert(detail.app.size == "19.6 MB"); assert(detail.updated == "2026-07-23 14:32"); assert(detail.title == "A very long application name that must stay intact 2.0"); + assert(detail.version == "2.0" && detail.author == "-"); catalog = factory.catalog(100, 6000); assert(catalog.version == "2.0"); @@ -100,6 +101,7 @@ int main() app.version = "2.0\tbeta"; detail = factory.detail(&app, 100, 6000); assert(detail.title == "Line one Line two 2.0 beta"); + assert(detail.version == "2.0 beta"); app.name = "App 0"; app.version = "2.0"; diff --git a/tests/test_detail_media_state.cpp b/tests/test_detail_media_state.cpp index 615c81c..8038aea 100644 --- a/tests/test_detail_media_state.cpp +++ b/tests/test_detail_media_state.cpp @@ -18,18 +18,27 @@ int main() state.normalize_images("b", 2); assert(state.image_index() == 0); state.normalize_page("a", 269, 129); - state.scroll_page(1); + state.scroll_page(1, 1000); assert(state.page_scroll() == 24); - state.scroll_page(20); + assert(state.page_scroll_at(1000) == 0 && state.page_glide_remaining(1000) == 180); + assert(state.page_scroll_at(1090) == 21); // Ease-out: most of the way at half time. + assert(state.page_scroll_at(1180) == 24 && state.page_glide_remaining(1180) == 0); + state.scroll_page(1, 1300); + state.scroll_page(1, 1390); // Key repeat continues from the drawn position. + assert(state.page_scroll() == 72 && state.page_scroll_at(1390) == 45); + state.scroll_page(20, 2000); assert(state.page_scroll() == 140); - state.scroll_page(-20); + state.scroll_page(-20, 3000); assert(state.page_scroll() == 0); - state.scroll_page(2); + state.scroll_page(2, 4000); state.normalize_page("b", 269, 129); - assert(state.page_scroll() == 0); + assert(state.page_scroll() == 0 && state.page_scroll_at(4010) == 0); state.normalize_page("b", 90, 129); - state.scroll_page(10); - assert(state.page_scroll() == 0); + state.scroll_page(10, 5000); + assert(state.page_scroll() == 0 && state.page_glide_remaining(5000) == 0); + state.normalize_page("c", 400, 129); + state.scroll_page(1, 0xffffffa0U); + assert(state.page_glide_remaining(0x14U) == 64 && state.page_scroll_at(0x14U) == 23); assert(state.needs_loading("a")); state.begin_loading("a"); state.normalize_images("b", 0); From e9e43b041e47da17a5e0d7764872085e8f6d2208 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 17:49:03 +0300 Subject: [PATCH 04/19] feat(store): hang shortcut labels as bookmark tabs --- main/ui/appstore_shortcut_bar.cpp | 49 +++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/main/ui/appstore_shortcut_bar.cpp b/main/ui/appstore_shortcut_bar.cpp index f5c2b1e..ba72aaf 100644 --- a/main/ui/appstore_shortcut_bar.cpp +++ b/main/ui/appstore_shortcut_bar.cpp @@ -7,31 +7,42 @@ #include "appstore_shortcut_bar.hpp" #include "appstore_fonts.hpp" -#include "appstore_fonts.hpp" - namespace appstore_ui { namespace { -void centered_strong_label(lv_obj_t *root, const std::string &text, int x, int y, - int w, int h, uint32_t color) -{ - { - lv_obj_t *label = lv_label_create(root); - lv_obj_set_pos(label, x, y); - lv_obj_set_size(label, w, h); - lv_obj_set_style_text_font(label, store_font(text, 12), 0); - lv_obj_set_style_text_color(label, lv_color_hex(color), 0); - lv_obj_set_style_text_letter_space(label, 0, 0); - lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); - lv_label_set_long_mode(label, LV_LABEL_LONG_DOT); - lv_label_set_text(label, text.c_str()); - } -} +constexpr int kScreenHeight = 170; +// A bookmark tab: the same tinted chip as the detail fields, but the rounded +// bottom continues past the screen, so the page edge cuts it with no border. void shortcut_label(lv_obj_t *root, int center_x, - const std::string &text, uint32_t color, int width = 56) + const std::string &text, uint32_t color, int width = 52) { - centered_strong_label(root, text, center_x - width / 2, 151, width, 18, color); + constexpr int top = 152, radius = 7; + const int x = center_x - width / 2; + const int visible = kScreenHeight - top; + lv_obj_t *tab = lv_obj_create(root); + lv_obj_remove_style_all(tab); + lv_obj_set_pos(tab, x, top); + lv_obj_set_size(tab, width, visible + radius); + lv_obj_clear_flag(tab, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_style_radius(tab, radius, 0); + lv_obj_set_style_bg_color(tab, lv_color_hex(color), 0); + lv_obj_set_style_bg_opa(tab, LV_OPA_50, 0); + lv_obj_set_style_border_width(tab, 1, 0); + lv_obj_set_style_border_color(tab, lv_color_hex(color), 0); + lv_obj_set_style_border_opa(tab, LV_OPA_50, 0); + lv_obj_set_style_border_side(tab, static_cast( + LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT), 0); + + const lv_font_t *font = store_font(text, 12); + lv_obj_t *label = lv_label_create(root); + lv_obj_set_pos(label, x + 2, top + (visible - font->line_height) / 2); + lv_obj_set_size(label, width - 4, font->line_height); + lv_obj_set_style_text_font(label, font, 0); + lv_obj_set_style_text_color(label, lv_color_hex(0xFFFFFF), 0); + lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); + lv_label_set_long_mode(label, LV_LABEL_LONG_DOT); + lv_label_set_text(label, text.c_str()); } } // namespace From 494913e137bb7733fc33e35b1143bfd57ffefb63 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 23:53:18 +0300 Subject: [PATCH 05/19] feat(store): read app permissions from the registry --- main/backend/appstore_native.cpp | 14 +++++++++++++- main/interface/appstore_client.cpp | 1 + main/interface/appstore_client.hpp | 15 +++++++++++++++ main/ui/appstore_view_model_factory.cpp | 1 + main/ui/appstore_view_models.hpp | 1 + tests/test_appstore_view_model_factory.cpp | 2 ++ tests/test_native_backend.cpp | 4 +++- 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/main/backend/appstore_native.cpp b/main/backend/appstore_native.cpp index d4f2731..df8c4cd 100644 --- a/main/backend/appstore_native.cpp +++ b/main/backend/appstore_native.cpp @@ -1115,13 +1115,25 @@ std::string summary_output() const json assets = app.value("assets", json::object()); const auto screenshot_refs = string_list(assets.contains("screenshots") ? assets["screenshots"] : app.value("screenshots", json::array())); + const json declared = app.value("permissions", json::object()); + uint32_t permissions = 0; + auto permit = [&](const char *name, uint32_t bit) { + if (declared.value(name, false)) permissions |= bit; + }; + permit("network", 1u << 0); + permit("microphone", 1u << 1); + permit("camera", 1u << 2); + permit("imu", 1u << 3); + permit("additional_hardware", 1u << 4); + permit("background_service", 1u << 5); + permit("external_display", 1u << 6); emit(out, "APP", app_key(app), localized(app, "title"), app.value("version", ""), app_categories.empty() ? "Other" : app_categories.front(), installed(app) ? "1" : "0", (app.value("featured", false) || review(app) == "approved") ? "1" : "0", field(download.value("size", json("online"))), full_description, author(app), source, image_text.str(), dependencies, app.value("share_code", ""), app.value("_registry_name", ""), app.value("updated_at", app.value("published_at", "")), review(app), review(app) == "approved" ? "1" : "0", state.version, - category_text.str(), package_name(app), screenshot_refs.size()); + category_text.str(), package_name(app), screenshot_refs.size(), permissions); } return out.str(); } diff --git a/main/interface/appstore_client.cpp b/main/interface/appstore_client.cpp index ae63a36..b31e124 100644 --- a/main/interface/appstore_client.cpp +++ b/main/interface/appstore_client.cpp @@ -561,6 +561,7 @@ SummaryData load_summary(SortRule rule) if (fields.size() >= 19) app.installed_version = fields[18]; if (fields.size() >= 21) app.package = fields[20]; if (fields.size() >= 22) app.screenshot_count = std::atoi(fields[21].c_str()); + if (fields.size() >= 23) app.permissions = static_cast(std::strtoul(fields[22].c_str(), nullptr, 10)); if (fields.size() >= 20) { std::istringstream categories(fields[19]); std::string category; diff --git a/main/interface/appstore_client.hpp b/main/interface/appstore_client.hpp index 72c1118..2e8ae6d 100644 --- a/main/interface/appstore_client.hpp +++ b/main/interface/appstore_client.hpp @@ -11,6 +11,7 @@ #include "appstore_protocol.hpp" #include "appstore_text.hpp" +#include #include #include @@ -38,6 +39,20 @@ struct StoreApp { bool installable = false; std::string package; int screenshot_count = -1; + // Bit set from the registry permissions object. Zero when the registry + // does not declare permissions, so older summaries stay readable. + uint32_t permissions = 0; +}; + +// Order matches the selection screen icon row. +enum AppPermission : uint32_t { + kPermissionNetwork = 1u << 0, + kPermissionMicrophone = 1u << 1, + kPermissionCamera = 1u << 2, + kPermissionImu = 1u << 3, + kPermissionHardware = 1u << 4, + kPermissionBackground = 1u << 5, + kPermissionDisplay = 1u << 6, }; struct RegistryEntry { diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 3470686..8dbffe3 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -95,6 +95,7 @@ CatalogDisplayViewModel AppStoreViewModelFactory::catalog( model.author = single_line(app->author.empty() ? "-" : app->author); model.size = human_size(app->size); model.updated = app->updated_at.empty() ? "-" : app->updated_at.substr(0, 10); + model.permissions = app->permissions; } return model; } diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index d7518d7..805af23 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -34,6 +34,7 @@ struct CatalogDisplayViewModel { std::string size; std::string updated; std::string empty_message; + uint32_t permissions = 0; int selected_index = 0; int app_count = 0; int total_count = 0; diff --git a/tests/test_appstore_view_model_factory.cpp b/tests/test_appstore_view_model_factory.cpp index 9a58c03..8ea4a33 100644 --- a/tests/test_appstore_view_model_factory.cpp +++ b/tests/test_appstore_view_model_factory.cpp @@ -82,7 +82,9 @@ int main() assert(detail.title == "A very long application name that must stay intact 2.0"); assert(detail.version == "2.0" && detail.author == "-"); + app.permissions = appstore::kPermissionNetwork | appstore::kPermissionCamera; catalog = factory.catalog(100, 6000); + assert(catalog.permissions == (appstore::kPermissionNetwork | appstore::kPermissionCamera)); assert(catalog.version == "2.0"); assert(catalog.size == "19.6 MB"); assert(catalog.updated == "2026-07-23"); diff --git a/tests/test_native_backend.cpp b/tests/test_native_backend.cpp index 456c433..192b208 100644 --- a/tests/test_native_backend.cpp +++ b/tests/test_native_backend.cpp @@ -74,6 +74,7 @@ static json app(const std::string &id, const std::string &review) { {"description","Full detailed description"}, {"icon","https://assets.invalid/"+id+".png"}, {"app",{{"dependencies",{"lib-one","lib-two"}},{"applaunch",{{"desktop_entry","applications/demo.desktop"},{"exec","/usr/bin/demo-package"}}}}}, + {"permissions",{{"network",true},{"camera",id=="app-id"},{"microphone",false}}}, {"download",{{"type","deb"},{"package","demo-package"},{"url","https://example.invalid/demo.deb"},{"md5",getenv("FAKE_MD5")},{"size","42K"}}}}; result["author"] = id == "app-id" ? json{{"display_name", "Tester"}, {"github", "ignored-user"}} @@ -121,7 +122,8 @@ static void registry_cases() { Result sum=call({"--summary"}); CHECK(has(sum,"META\t1\t2 apps/1 registries")); CHECK(has(sum,"CAT\tUtilities")); CHECK(has(sum,"CAT\tInstalled")); CHECK(has(sum,"APP\tapp-id\tDemo Local\t1.2.0\tUtilities")); CHECK(has(sum,"\tTester\thttps://example.invalid/source\t")); CHECK(has(sum,"Localized summary\\nFull detailed description")); - CHECK(has(sum,"\tdemo-package\t0")); + // Screenshot count, then the permissions bit set: network (1) and camera (4). + CHECK(has(sum,"\tdemo-package\t0\t5")); CHECK(call({"--clear-registry-cache"}).rc==0); setenv("FAKE_DROP_DURING_ASSETS","1",1); Result dropped=call({"--sync"}); From f3f5724451807c9ddfa20ad66558de7bec08a0d2 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Fri, 16 Oct 2026 23:54:12 +0300 Subject: [PATCH 06/19] feat(store): rework the app selection screen --- README.md | 9 +- main/ui/appstore_image_renderer.cpp | 2 +- main/ui/appstore_pages.cpp | 182 ++++++++++++++++++++++------ main/ui/appstore_pages.hpp | 33 +++-- main/ui/appstore_presenter.cpp | 141 +++++++++++---------- 5 files changed, 252 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 45366f5..985a625 100644 --- a/README.md +++ b/README.md @@ -108,10 +108,11 @@ position, and labels never scroll vertically. In search results only the selected name scrolls; the others end with an ellipsis. The selected app's version, maintainer, size, and update date are shown in green, orange, blue, and violet tags. -The category's position in the category list (for example `2 / 5`) is shown -under its name. The selected app's position in the category (for example -`1 / 4`) is shown beside its icon, and the catalog size is shown next to the -Store icon on the category row. +The category row shows the category name between left and right buttons, +followed by the category's position in the category list (for example +`2 / 5`). On the same row, the selected app's position in the category (for +example `1 / 4`) follows up and down buttons, and the catalog size follows the +Store icon. Press `4` for settings, `5` for share code, `6` for search, `7` for install/reinstall, and `8` or Enter for details. AppStore syncs the registry automatically when it starts. diff --git a/main/ui/appstore_image_renderer.cpp b/main/ui/appstore_image_renderer.cpp index a7d9064..420bcc9 100644 --- a/main/ui/appstore_image_renderer.cpp +++ b/main/ui/appstore_image_renderer.cpp @@ -61,7 +61,7 @@ bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app lv_obj_clear_flag(clip, LV_OBJ_FLAG_SCROLLABLE); lv_obj_set_style_bg_opa(clip, LV_OPA_TRANSP, 0); lv_obj_set_style_border_width(clip, 0, 0); - lv_obj_set_style_radius(clip, 10, 0); + lv_obj_set_style_radius(clip, width / 6, 0); lv_obj_set_style_clip_corner(clip, true, 0); lv_obj_set_style_pad_all(clip, 0, 0); lv_obj_t *icon = lv_image_create(clip); diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index e151b1c..bf3556f 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -94,24 +94,36 @@ void field_chip(lv_obj_t *parent, int x, int y, int w, int h, uint32_t color) } void field_value(lv_obj_t *parent, const std::string &value, int x, int y, int w, - uint32_t color, HorizontalMarquee *marquee, const std::string &key) + uint32_t color, HorizontalMarquee *marquee, const std::string &key, + uint16_t size = 14) { - const lv_font_t *font = store_font(value, 14); + const lv_font_t *font = store_font(value, size); if (marquee) marquee_label(parent, value, x, y, w, font->line_height, font, color, *marquee, key); else label(parent, value, x, y, w, font->line_height, font, color, LV_LABEL_LONG_DOT); } +// 12 px values so a full date and a size such as "1023.9 KB" fit their tags. +constexpr uint16_t kHomeChipFontSize = 12; + void home_field(lv_obj_t *root, const std::string &value, int x, int y, int w, uint32_t color, HorizontalMarquee *marquee = nullptr, const std::string &key = {}) { - constexpr int height = 20, pad = 6; + constexpr int pad = 5, height = catalog_home::kTagHeight; field_chip(root, x, y, w, height, color); - const int line_height = store_font(value, 14)->line_height; + const int line_height = store_font(value, kHomeChipFontSize)->line_height; field_value(root, value, x + pad, y + (height - line_height) / 2, w - 2 * pad, - color, marquee, key); + color, marquee, key, kHomeChipFontSize); +} + +// Top of a glyph's ink, measured from the top of the font's line box. +int glyph_top(const lv_font_t *font, uint32_t letter) +{ + lv_font_glyph_dsc_t glyph = {}; + if (!lv_font_get_glyph_dsc(font, &glyph, letter, 0)) return 0; + return font->line_height - font->base_line - glyph.ofs_y - glyph.box_h; } void detail_field(lv_obj_t *parent, const char *caption, const std::string &value, @@ -145,6 +157,84 @@ void edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towards_b lv_obj_set_style_bg_grad_opa(fade, towards_bottom ? LV_OPA_COVER : LV_OPA_TRANSP, 0); } +void permission_badge(lv_obj_t *parent, int x, int y, uint32_t color) +{ + constexpr int size = catalog_home::kPermissionSize; + lv_obj_t *badge = box(parent, x, y, size, size, color, color, 1, 4, LV_OPA_20); + lv_obj_set_style_border_opa(badge, LV_OPA_40, 0); +} + +// Filled mark, so the glyph stays readable inside a 14 px badge. +void permission_fill(lv_obj_t *parent, int x, int y, int w, int h, uint32_t color, int radius = 0) +{ + box(parent, x, y, w, h, color, color, 0, radius); +} + +// One badge per declared permission, in the registry's order. +void permission_icons(lv_obj_t *parent, int x, int y, uint32_t permissions) +{ + constexpr int step = 18; + constexpr uint32_t color = 0x8B949E; + using appstore::kPermissionBackground; + using appstore::kPermissionCamera; + using appstore::kPermissionDisplay; + using appstore::kPermissionHardware; + using appstore::kPermissionImu; + using appstore::kPermissionMicrophone; + using appstore::kPermissionNetwork; + struct Item { uint32_t bit; void (*draw)(lv_obj_t *, int, int); }; + const Item items[] = { + {kPermissionNetwork, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 6, y + 2, 2, 3, color); + permission_fill(parent, x + 4, y + 4, 6, 2, color); + permission_fill(parent, x + 6, y + 6, 2, 6, color); + }}, + {kPermissionMicrophone, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 5, y + 2, 4, 6, color, 2); + permission_fill(parent, x + 3, y + 6, 2, 3, color); + permission_fill(parent, x + 9, y + 6, 2, 3, color); + permission_fill(parent, x + 3, y + 8, 8, 2, color); + permission_fill(parent, x + 6, y + 10, 2, 2, color); + }}, + {kPermissionCamera, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 2, y + 5, 10, 6, color, 1); + permission_fill(parent, x + 4, y + 3, 3, 2, color); + box(parent, x + 5, y + 6, 4, 4, 0x081010, 0x081010, 0, 2); + }}, + {kPermissionImu, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 3, y + 3, 8, 8, color, 4); + box(parent, x + 5, y + 5, 4, 4, 0x081010, 0x081010, 0, 2); + }}, + {kPermissionHardware, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 3, y + 5, 8, 6, color, 1); + permission_fill(parent, x + 5, y + 2, 1, 3, color); + permission_fill(parent, x + 8, y + 2, 1, 3, color); + }}, + {kPermissionBackground, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 3, y + 3, 8, 2, color); + permission_fill(parent, x + 6, y + 5, 2, 6, color); + }}, + {kPermissionDisplay, [](lv_obj_t *parent, int x, int y) { + permission_badge(parent, x, y, color); + permission_fill(parent, x + 2, y + 3, 10, 6, color, 1); + permission_fill(parent, x + 6, y + 9, 2, 2, color); + permission_fill(parent, x + 4, y + 11, 6, 1, color); + }}, + }; + int drawn = 0; + for (const auto &item : items) { + if ((permissions & item.bit) == 0) continue; + item.draw(parent, x + drawn * step, y); + ++drawn; + } +} + void glide_page(lv_obj_t *document, DetailMediaState &media, uint32_t now) { const uint32_t remaining = media.page_glide_remaining(now); @@ -167,19 +257,6 @@ void glide_page(lv_obj_t *document, DetailMediaState &media, uint32_t now) lv_anim_start(&animation); } -void screenshot_arrow(lv_obj_t *root, int x, int y, bool right, uint32_t color) -{ - // Keep navigation visible without font glyphs when packaged arrows cannot load. - static const lv_point_precise_t left_points[] = {{9, 1}, {1, 9}, {9, 17}}; - static const lv_point_precise_t right_points[] = {{1, 1}, {9, 9}, {1, 17}}; - lv_obj_t *arrow = lv_line_create(root); - lv_line_set_points(arrow, right ? right_points : left_points, 3); - lv_obj_set_pos(arrow, x, y); - lv_obj_set_style_line_color(arrow, lv_color_hex(color), 0); - lv_obj_set_style_line_width(arrow, 2, 0); - lv_obj_set_style_line_rounded(arrow, true, 0); -} - void set_progress_scan_x(void *object, int32_t x) { lv_obj_set_x(static_cast(object), x); @@ -229,6 +306,28 @@ int glyph_middle(const lv_font_t *font, uint32_t letter) return font->line_height - font->base_line - glyph.ofs_y - glyph.box_h / 2; } +void draw_arrow_key(lv_obj_t *parent, ArrowKey arrow, int center_x, int center_y, + int width, int height) +{ + const int x = center_x - width / 2; + // Raised look: a lighter top fading to a darker bottom, with a hairline edge. + lv_obj_t *button = box(parent, x, center_y - height / 2, width, height, 0x34424D, + 0x4E5D69, 1, 5); + lv_obj_set_style_bg_grad_color(button, lv_color_hex(0x182127), 0); + lv_obj_set_style_bg_grad_dir(button, LV_GRAD_DIR_VER, 0); + + // Solid triangles, in ArrowKey order: left, up, right, down. + static const char *const glyphs[] = {"\xE2\x97\x80", "\xE2\x96\xB2", "\xE2\x96\xB6", + "\xE2\x96\xBC"}; + static constexpr uint32_t codepoints[] = {0x25C0, 0x25B2, 0x25B6, 0x25BC}; + const int index = static_cast(arrow); + const lv_font_t *font = store_font(glyphs[index], 10); + lv_obj_t *glyph = label(parent, glyphs[index], x, + center_y - glyph_middle(font, codepoints[index]), width, + font->line_height, font, 0xFF7A45); + lv_obj_set_style_text_align(glyph, LV_TEXT_ALIGN_CENTER, 0); +} + lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, int width, int height, const lv_font_t *font, uint32_t color, HorizontalMarquee &state, const std::string &key, @@ -396,27 +495,33 @@ void CatalogDisplayPage::render(const PageRenderContext &context, catalog_home::kIconCenterY - font->line_height, details_width, font->line_height * 2, font, 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - // Keep the name and its detail tags one block, centered on the icon. + // Fixed rows, whether or not an app declares permissions, so the block + // stays centered on the icon. const lv_font_t *name_font = store_font(model.name, 20, true); - constexpr int chip_height = 20, chip_gap = 3, name_gap = 4; - constexpr int chip_width = 70, column_gap = 4; - const int stack = name_font->line_height + name_gap + chip_height + chip_gap + chip_height; - // The name's line box keeps room below the baseline, so the block's - // center sits below its visible text. Nudge it down to match the icon. - int y = catalog_home::kIconCenterY - stack / 2 + 4; - marquee_label(root, model.name, catalog_home::kDetailsX, y, details_width, + constexpr int chip_width = 84, column_gap = 4; + marquee_label(root, model.name, catalog_home::kDetailsX, + catalog_home::kTopY - glyph_top(name_font, 'H'), details_width, name_font->line_height, name_font, 0xFFFFFF, title_marquee_, model.name); - y += name_font->line_height + name_gap; + const int value_x = catalog_home::kDetailsX + chip_width + column_gap; const int value_width = details_width - chip_width - column_gap; - home_field(root, model.version, catalog_home::kDetailsX, y, chip_width, kVersionColor); - home_field(root, model.author, catalog_home::kDetailsX + chip_width + column_gap, y, - value_width, kMaintainerColor, &author_marquee_, model.name + model.author); - y += chip_height + chip_gap; - home_field(root, model.size, catalog_home::kDetailsX, y, chip_width, kSizeColor); - home_field(root, model.updated, catalog_home::kDetailsX + chip_width + column_gap, y, - value_width, kDateColor); + home_field(root, model.version, catalog_home::kDetailsX, catalog_home::kTagRow1Y, + chip_width, kVersionColor); + home_field(root, model.author, value_x, catalog_home::kTagRow1Y, value_width, + kMaintainerColor, &author_marquee_, model.name + model.author); + home_field(root, model.size, catalog_home::kDetailsX, catalog_home::kTagRow2Y, + chip_width, kSizeColor); + home_field(root, model.updated, value_x, catalog_home::kTagRow2Y, value_width, + kDateColor); + permission_icons(root, catalog_home::kDetailsX, catalog_home::kPermissionsY, + model.permissions); + } + if (model.show_status) { + // A status message temporarily takes over the permission row. + box(root, catalog_home::kDetailsX - 2, catalog_home::kPermissionsY - 1, + details_width + 4, 16, 0x081010, 0x081010, 0); + scrolling_status_label(root, model.status, catalog_home::kDetailsX, + catalog_home::kPermissionsY + 1, details_width, 12); } - if (model.show_status) scrolling_status_label(root, model.status, 110, 136, 205, 12); draw_shortcuts(); } @@ -497,7 +602,6 @@ void CatalogDisplayPage::render_search(const PageRenderContext &context, void AppDetailPage::render(const PageRenderContext &context, const AppDetailViewModel &model, DetailMediaState &media, const std::vector &screenshots, const std::function &draw_thumbnail, - const std::function &draw_packaged, const std::function &draw_shortcuts) { context.prepare(); @@ -566,10 +670,8 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView draw_thumbnail(document, screenshots[index], 20, shot_y); if (screenshots.size() > 1) { draw_thumbnail(document, screenshots[(index + 1) % screenshots.size()], 185, shot_y); - if (!draw_packaged(document, "store_arrow_left.png", 5, shot_y + 35)) - screenshot_arrow(document, 5, shot_y + 33, false, 0xFF6A3D); - if (!draw_packaged(document, "store_arrow_right.png", 304, shot_y + 35)) - screenshot_arrow(document, 304, shot_y + 33, true, 0xFF6A3D); + draw_arrow_key(document, ArrowKey::Left, 10, shot_y + 42); + draw_arrow_key(document, ArrowKey::Right, 311, shot_y + 42); } y = shot_y + 85 + 10; } diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index 5ff446c..b4cca11 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -22,14 +22,34 @@ void render_exit_hint(lv_obj_t *root); // Middle of a glyph's ink, measured from the top of the font's line box. int glyph_middle(const lv_font_t *font, uint32_t letter); +enum class ArrowKey { Left, Up, Right, Down }; + +// A small raised button with a solid arrow, for on-screen navigation hints. +void draw_arrow_key(lv_obj_t *parent, ArrowKey arrow, int center_x, int center_y, + int width = 18, int height = 16); + // Home catalog geometry shared by the page and the icon panel. namespace catalog_home { -constexpr int kIconX = 39; -constexpr int kIconY = 65; -constexpr int kIconSize = 60; -constexpr int kIconCenterY = kIconY + kIconSize / 2; -constexpr int kDetailsX = 148; -constexpr int kDetailsRight = 315; +// Content edges: the category's left key and the header counters' right end. +constexpr int kLeft = 9; +constexpr int kRight = 312; +// Left rows: the name's capitals, two tag rows and the permission icons, +// centered as one block between the header and the bookmark tabs. +constexpr int kTopY = 54; +constexpr int kTagHeight = 17; +// Clears the 20 px name, including its descenders. +constexpr int kTagRow1Y = kTopY + 23; +constexpr int kTagRow2Y = kTagRow1Y + kTagHeight + 3; +constexpr int kPermissionSize = 14; +constexpr int kPermissionsY = kTagRow2Y + kTagHeight + 6; +// The icon on the right fills the height between the header and the bookmark +// tabs, centered on the left block. +constexpr int kIconSize = 100; +constexpr int kIconX = kRight - kIconSize; +constexpr int kIconCenterY = (kTopY + kPermissionsY + kPermissionSize) / 2; +constexpr int kIconY = kIconCenterY - kIconSize / 2; +constexpr int kDetailsX = kLeft; +constexpr int kDetailsRight = kIconX - 9; constexpr uint32_t kMuted = 0x8B949E; } // namespace catalog_home @@ -87,7 +107,6 @@ class AppDetailPage : public AppStoreUiPage const AppDetailViewModel &model, DetailMediaState &media, const std::vector &screenshots, const std::function &draw_thumbnail, - const std::function &draw_packaged, const std::function &draw_shortcuts); void render_confirmation(const PageRenderContext &context, const ConfirmationViewModel &model); diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index 2c02d04..5032d7b 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -18,7 +18,7 @@ namespace { constexpr int kCategoryX = 28; constexpr int kCategoryY = 24; constexpr int kCategoryWidth = 86; -constexpr int kCategoryPositionY = 37; +constexpr int kCategoryKeyWidth = 18; constexpr uint32_t kStatusVisibleMs = 6000; lv_obj_t *label(lv_obj_t *parent, const std::string &text, int x, int y, int w, int h, @@ -80,44 +80,68 @@ std::string app_initial(const appstore::StoreApp &app) return "A"; } -// Selection inside the current category, centered on the icon. -void draw_selection_position(lv_obj_t *root, int index, int count) +constexpr int kCounterIconGap = 4; + +int counter_width(const std::string &text) +{ + lv_point_t size = {}; + lv_text_get_size(&size, text.c_str(), store_font("", 14), 0, 0, LV_COORD_MAX, + LV_TEXT_FLAG_NONE); + return size.x; +} + +// Gray header count at x, centered on `middle`; "..." if it needs more than `width`. +void counter_label(lv_obj_t *root, const std::string &text, int x, int width, int middle) +{ + const lv_font_t *font = store_font("", 14); + label(root, text, x, middle - glyph_middle(font, '0'), width, font->line_height, font, + catalog_home::kMuted, LV_LABEL_LONG_DOT); +} + +// Gray count, right-aligned at `right` and centered on `middle`. Returns its left edge. +int header_count(lv_obj_t *root, const std::string &text, int right, int middle) { - const std::string text = std::to_string(index) + " / " + std::to_string(count); - const lv_font_t *font = store_font("", 12); - // The name and tags start at kDetailsX; stay clear of them. - label(root, text, catalog_home::kIconX + catalog_home::kIconSize + 4, - catalog_home::kIconCenterY - glyph_middle(font, '0'), - catalog_home::kDetailsX - (catalog_home::kIconX + catalog_home::kIconSize + 4), - font->line_height, font, catalog_home::kMuted); + const int width = counter_width(text); + counter_label(root, text, right - width, width + 4, middle); + return right - width; } -// Whole-catalog count, sitting on the same line as the category name. -void draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, - int count, int category_middle) +// Catalog size: Store icon, then the count. Returns the icon's left edge. +int draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, int total, + int right, int middle) { // The Store artwork is a badge with its own padding, so the box has to be // larger than the category's letter height to look the same size. - constexpr int icon_size = 18, gap = 4, right = 312; - const std::string text = std::to_string(count); - const lv_font_t *font = store_font("", 14); - lv_point_t size = {}; - lv_text_get_size(&size, text.c_str(), font, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); - const int text_x = right - size.x; - label(root, text, text_x, category_middle - glyph_middle(font, '0'), size.x + 4, - font->line_height, font, catalog_home::kMuted); - const int icon_x = text_x - gap - icon_size; + constexpr int icon_size = 18; + const int icon_x = header_count(root, std::to_string(total), right, middle) - + kCounterIconGap - icon_size; if (lv_obj_t *icon = images.draw_packaged(root, "store_100.png", icon_x, 0)) { const int scale = std::max(1, std::min(icon_size * 256 / lv_obj_get_width(icon), icon_size * 256 / lv_obj_get_height(icon))); lv_image_set_scale(icon, static_cast(scale)); lv_image_set_inner_align(icon, LV_IMAGE_ALIGN_CENTER); lv_obj_set_size(icon, icon_size, icon_size); - lv_obj_set_y(icon, category_middle - icon_size / 2); - return; + lv_obj_set_y(icon, middle - icon_size / 2); + } else { + const lv_font_t *font = store_font("", 14); + strong_label(root, "*", icon_x, middle - glyph_middle(font, '*'), icon_size, + font->line_height, font, catalog_home::kMuted); } - strong_label(root, "*", icon_x, category_middle - glyph_middle(font, '*'), icon_size, - font->line_height, font, catalog_home::kMuted); + return icon_x; +} + +// Selected app within the category: the up/down keys that change it, then "x / y". +// Returns the group's left edge. +int draw_selection_position(lv_obj_t *root, int position, int count, int right, int middle) +{ + constexpr int key = 16, key_gap = 2; + const int text_x = header_count(root, std::to_string(position) + " / " + + std::to_string(count), right, middle); + const int down_x = text_x - kCounterIconGap - key / 2; + const int up_x = down_x - key - key_gap; + draw_arrow_key(root, ArrowKey::Down, down_x, middle, key, key); + draw_arrow_key(root, ArrowKey::Up, up_x, middle, key, key); + return up_x - key / 2; } } // namespace @@ -164,54 +188,48 @@ void AppStorePresenter::draw_category_selector(lv_obj_t *root) // The name is uppercase: center on its capitals, not on the line box, // which also reserves room below the baseline for descenders. const int middle = kCategoryY + glyph_middle(font, 'H'); - auto chevron = [&](const char *image, const char *fallback, int x) { - if (lv_obj_t *arrow = images_.draw_packaged(root, image, x, 0)) { - lv_obj_set_y(arrow, middle - lv_obj_get_height(arrow) / 2); - return; - } - const lv_font_t *arrow_font = store_font("", 20); - strong_label(root, fallback, x, middle - glyph_middle(arrow_font, fallback[0]), 14, - arrow_font->line_height, arrow_font, 0xFF6A3D); - }; - chevron("store_arrow_left.png", "<", 14); - chevron("store_arrow_right.png", ">", 116); - draw_catalog_total(root, images_, static_cast(session_.catalog.apps().size()), middle); + const int right_key_x = kCategoryX + kCategoryWidth + 10; + draw_arrow_key(root, ArrowKey::Left, kCategoryX - 10, middle, kCategoryKeyWidth); + draw_arrow_key(root, ArrowKey::Right, right_key_x, middle, kCategoryKeyWidth); + + // Header counters, right to left: catalog size, then the selected app's + // position in the category. The category's own position follows its right + // key and gets whatever room is left. + constexpr int counter_gap = 10; + int free_right = draw_catalog_total(root, images_, + static_cast(session_.catalog.apps().size()), + catalog_home::kRight, middle) - counter_gap; + const int selected = session_.catalog.selected_index(); + const int visible = static_cast(session_.catalog.visible().size()); + if (selected >= 0 && selected < visible) + free_right = draw_selection_position(root, selected + 1, visible, free_right, middle) - + counter_gap; const auto &categories = session_.catalog.categories(); const int index = session_.catalog.category_index(); if (index < 0 || index >= static_cast(categories.size())) return; - lv_obj_t *position = label(root, std::to_string(index + 1) + " / " + - std::to_string(categories.size()), - kCategoryX, kCategoryPositionY, kCategoryWidth, 12, - &lv_font_montserrat_10, 0x8B949E); - lv_obj_set_style_text_align(position, LV_TEXT_ALIGN_CENTER, 0); + const std::string position = std::to_string(index + 1) + " / " + + std::to_string(categories.size()); + const int position_x = right_key_x + kCategoryKeyWidth / 2 + kCounterIconGap; + const int width = std::min(counter_width(position) + 4, free_right - position_x); + if (width > 0) counter_label(root, position, position_x, width, middle); } void AppStorePresenter::draw_home_icon_panel(lv_obj_t *root, const appstore::StoreApp *app) { + using catalog_home::kIconCenterY; using catalog_home::kIconSize; using catalog_home::kIconX; - using catalog_home::kIconY; - const int arrow_x = kIconX + (kIconSize - 14) / 2; - if (!images_.draw_packaged(root, "store_arrow_up.png", arrow_x, 51)) - center_strong_label(root, "^", kIconX + 16, 49, 28, 18, - &lv_font_montserrat_20, 0xFF6A3D); + const lv_font_t *font = &lv_font_montserrat_20; if (!app) { - center_strong_label(root, "-", kIconX + 22, kIconY + 24, 24, 22, - &lv_font_montserrat_20, 0x9A9A9A); + center_strong_label(root, "-", kIconX, kIconCenterY - glyph_middle(font, '-'), + kIconSize, font->line_height, font, 0x9A9A9A); } else if (!images_.draw_app_icon(root, session_.app_dir, *app)) { - center_strong_label(root, app_initial(*app), kIconX, kIconY + 21, - kIconSize, 28, &lv_font_montserrat_20, - app->installed ? 0x52D05D : 0xFFFFFF); + center_strong_label(root, app_initial(*app), kIconX, + kIconCenterY - glyph_middle(font, 'H'), kIconSize, + font->line_height, font, app->installed ? 0x52D05D : 0xFFFFFF); } - const int index = session_.catalog.selected_index(); - const int count = static_cast(session_.catalog.visible().size()); - if (index >= 0 && index < count) - draw_selection_position(root, index + 1, count); - if (!images_.draw_packaged(root, "store_arrow_down.png", arrow_x, 133)) - center_strong_label(root, "v", kIconX + 16, 131, 28, 18, - &lv_font_montserrat_20, 0xFF6A3D); } bool AppStorePresenter::draw_detail_background(lv_obj_t *root, @@ -253,9 +271,6 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running) [this](lv_obj_t *parent, const std::string &path, int x, int y) { return images_.draw_thumbnail(parent, path, x, y); }, - [this](lv_obj_t *parent, const std::string &name, int x, int y) { - return images_.draw_packaged(parent, name, x, y) != nullptr; - }, [this](const appstore::StoreApp &app) { AppStoreShortcutBar::render_detail( detail_page_.screen(), session_.app_dir, app); From 54d7e90af64c64bf5a70e5de6f6e049080cc3a36 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Sat, 17 Oct 2026 00:19:53 +0300 Subject: [PATCH 07/19] feat(audio): play the launcher's key sounds in the Store --- README.md | 6 +++ linux_x86_cross_cp0_config_defaults.mk | 1 + linux_x86_sdl2_config_defaults.mk | 1 + main/ui/appstore.cpp | 42 ++++++++++++++++++++- main/ui/appstore_app.hpp | 6 +++ main/ui/appstore_input_controller.cpp | 35 +++++++++++++++-- main/ui/appstore_input_controller.hpp | 10 +++++ main/ui/appstore_pages.cpp | 35 ++++++++++++++--- main/ui/appstore_pages.hpp | 9 +++++ main/ui/appstore_presenter.cpp | 5 +++ main/ui/appstore_presenter.hpp | 2 + main/ui/detail_media_state.hpp | 1 + tests/test_appstore_input_controller.cpp | 48 +++++++++++++++++++++--- 13 files changed, 185 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 985a625..4956f54 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,12 @@ the hint without activating the page underneath. On other screens, short `Esc` keeps its back/cancel behavior. Hold `Esc` for three seconds to exit from any screen, including while the hint is open. +Keys play the launcher's system sounds: arrows and `F/X/Z/C` play the switch +sound on every step, including repeats while held, and Enter, Tab, a short +`Esc`, and shortcut keys play the enter sound. Typing in text fields is +silent. A held key repeats no faster than the screen redraws, so the view +keeps up and stops when the key is released. + The detail page shows the app name, the same color-coded version, maintainer, size, and update fields as the home screen, the install state, the complete description, 160 x 85 screenshot previews loaded from the registry, and the diff --git a/linux_x86_cross_cp0_config_defaults.mk b/linux_x86_cross_cp0_config_defaults.mk index 2ea47d4..597430b 100644 --- a/linux_x86_cross_cp0_config_defaults.mk +++ b/linux_x86_cross_cp0_config_defaults.mk @@ -37,6 +37,7 @@ CONFIG_V9_5_LV_DRAW_THREAD_PRIO=3 CONFIG_CP0_LVGL_COMPONENT_ENABLED=y CONFIG_CP0_LVGL_INIT_FILESYSTEM=y CONFIG_CP0_LVGL_INIT_CONFIG=y +CONFIG_CP0_LVGL_INIT_AUDIO=y CONFIG_CP0_LVGL_INIT_SUDO=y CONFIG_CP0_LVGL_INIT_PROCESS=y CONFIG_CP0_LVGL_INIT_WIFI=y diff --git a/linux_x86_sdl2_config_defaults.mk b/linux_x86_sdl2_config_defaults.mk index e87a194..bfdbc57 100644 --- a/linux_x86_sdl2_config_defaults.mk +++ b/linux_x86_sdl2_config_defaults.mk @@ -31,6 +31,7 @@ CONFIG_V9_5_LV_DRAW_THREAD_PRIO=3 CONFIG_CP0_LVGL_COMPONENT_ENABLED=y CONFIG_CP0_LVGL_INIT_FILESYSTEM=y CONFIG_CP0_LVGL_INIT_CONFIG=y +CONFIG_CP0_LVGL_INIT_AUDIO=y CONFIG_CP0_LVGL_INIT_SUDO=y CONFIG_CP0_LVGL_INIT_PROCESS=y CONFIG_CP0_LVGL_INIT_WIFI=y diff --git a/main/ui/appstore.cpp b/main/ui/appstore.cpp index 131c523..443a792 100644 --- a/main/ui/appstore.cpp +++ b/main/ui/appstore.cpp @@ -111,6 +111,25 @@ void request_quit() cp0_lvgl_wake(); } +// The launcher's system sounds: slot 1 when it switches apps, slot 2 when it +// launches one. +void play_key_sound(KeySound sound) noexcept +{ + try { + cp0_signal_audio_api({"SystemSoundPlay", sound == KeySound::Move ? "1" : "2"}, + nullptr); + } catch (...) { + } +} + +bool display_refresh_pending() +{ + lv_display_t *display = lv_display_get_default(); + lv_timer_t *refresh = display ? lv_display_get_refr_timer(display) : nullptr; + // The refresh timer sleeps until something on screen changes. + return refresh && !lv_timer_get_paused(refresh); +} + void handle_signal(int) { request_quit(); @@ -364,12 +383,17 @@ void AppStoreApp::repair_package_error() void AppStoreApp::handle_key(const AppStoreKeyEvent &key) { + // Keys are handled back to back while more are queued, so repeats that + // come faster than a screen rebuilds would hold off drawing until the key + // is released. Skip repeats until the last key's change is on screen. + if (key.repeated && key.code != KEY_ESC && key_frame_pending_) return; const uint32_t key_start = lv_tick_get(); const Screen before_screen = g_runtime.session.screen; app_tracef("handle_key begin screen=%s code=%u ch=%d release=%d repeat=%d", screen_name(before_screen), key.code, static_cast(key.ch), key.release ? 1 : 0, key.repeated ? 1 : 0); input_controller_.handle(key, key_start); + key_frame_pending_ = display_refresh_pending(); app_tracef("handle_key end elapsed=%ums before=%s after=%s code=%u ch=%d", lv_tick_elaps(key_start), screen_name(before_screen), screen_name(g_runtime.session.screen), key.code, static_cast(key.ch)); @@ -435,7 +459,9 @@ AppStoreApp::AppStoreApp() [this]() { open_registry_screen(); }, [this]() { open_registry_add_screen(); }, [this]() { execute_detail_confirmation(); }, [this]() { repair_package_error(); }, - [this]() { render_current_screen(); }}), + [this]() { render_current_screen(); }, + [this]() { return presenter_.scroll_detail(); }, + [](KeySound sound) { play_key_sound(sound); }}), event_adapter_( [this](const AppStoreKeyEvent &key) { handle_key(key); }, [this](const cp0_battery_info_t &info) { @@ -540,15 +566,29 @@ AppStoreApp::AppStoreApp() bind_page(settings_page_); current_ = this; set_active_page(*this); + lv_display_add_event_cb(lv_display_get_default(), frame_ready, LV_EVENT_REFR_READY, this); + // Open the sound output in the background so the first key click is on time. + sound_warmup_ = std::async(std::launch::async, []() { + try { + cp0_signal_audio_api({"SystemSoundPrepare"}, nullptr); + } catch (...) { + } + }); ui_init(startup_argc_, startup_argv_); } AppStoreApp::~AppStoreApp() { + lv_display_remove_event_cb_with_user_data(lv_display_get_default(), frame_ready, this); ui_deinit(); current_ = nullptr; } +void AppStoreApp::frame_ready(lv_event_t *event) +{ + static_cast(lv_event_get_user_data(event))->key_frame_pending_ = false; +} + void AppStoreApp::set_arguments(int argc, char **argv) { startup_argc_ = argc; diff --git a/main/ui/appstore_app.hpp b/main/ui/appstore_app.hpp index 8e00741..5afb90e 100644 --- a/main/ui/appstore_app.hpp +++ b/main/ui/appstore_app.hpp @@ -34,6 +34,8 @@ #include "system_status_controller.hpp" #include "system_status_state.hpp" +#include + namespace appstore_ui { class AppStoreApp : public InitializationProgressPage @@ -68,6 +70,7 @@ class AppStoreApp : public InitializationProgressPage void open_registry_add_screen(); void execute_detail_confirmation(); void repair_package_error(); + static void frame_ready(lv_event_t *event); static int startup_argc_; static char **startup_argv_; @@ -96,6 +99,9 @@ class AppStoreApp : public InitializationProgressPage AppStoreTimerService timers_; AppStoreLifecycle lifecycle_; AppStoreUiPage *active_page_ = nullptr; + // A key changed the screen and the display has not drawn it yet. + bool key_frame_pending_ = false; + std::future sound_warmup_; }; } // namespace appstore_ui diff --git a/main/ui/appstore_input_controller.cpp b/main/ui/appstore_input_controller.cpp index 8a7f814..cc21799 100644 --- a/main/ui/appstore_input_controller.cpp +++ b/main/ui/appstore_input_controller.cpp @@ -14,6 +14,22 @@ namespace appstore_ui { +KeySound key_sound(const AppStoreKeyEvent &key, cp0_keyboard_input_context_t context) +{ + if (key.release) return KeySound::None; + const bool text = context == KBD_INPUT_CONTEXT_TEXT; + const bool arrow = key.code == KEY_UP || key.code == KEY_DOWN || + key.code == KEY_LEFT || key.code == KEY_RIGHT; + // F, X, Z and C type letters in text fields. + const bool alias = !text && (key.code == KEY_F || key.code == KEY_X || + key.code == KEY_Z || key.code == KEY_C); + if (arrow || alias) return KeySound::Move; + if (key.repeated) return KeySound::None; + if (key.code == KEY_ENTER) return KeySound::Select; + if (text) return KeySound::None; + return key.ch != 0 || key.code == KEY_TAB ? KeySound::Select : KeySound::None; +} + AppStoreInputController::AppStoreInputController( AppStoreSessionState &session, PackageJobState &package_job, ExitController &exit, ShareCodeState &share_code, CatalogController &catalog, @@ -31,6 +47,11 @@ bool AppStoreInputController::matches(const AppStoreKeyEvent &key, char ch, return key.ch == ch || key.code == code; } +void AppStoreInputController::play(KeySound sound) +{ + if (sound != KeySound::None && actions_.play_sound) actions_.play_sound(sound); +} + void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) { if (exit_.requested()) return; @@ -42,6 +63,7 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) if (held) { if (actions_.request_quit) actions_.request_quit(); } else if (short_press) { + play(KeySound::Select); if (session_.exit_hint_visible) { session_.exit_hint_visible = false; } else if (session_.screen == Screen::Home || @@ -71,6 +93,7 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } if (key.repeated && dismiss_key_ == key.code) return; dismiss_key_ = 0; + play(key_sound(key, appstore_input_context(session_.screen))); switch (session_.screen) { case Screen::StartupSync: @@ -125,10 +148,14 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) break; case Screen::Detail: { appstore::StoreApp *app = catalog_.ensure_selected(); - if (key.code == KEY_UP || key.code == KEY_F || key.ch == 'f') - detail_.scroll_page(-1, now); - else if (key.code == KEY_DOWN || key.code == KEY_X || key.ch == 'x') - detail_.scroll_page(1, now); + const bool up = key.code == KEY_UP || key.code == KEY_F || key.ch == 'f'; + if (up || key.code == KEY_DOWN || key.code == KEY_X || key.ch == 'x') { + // Rebuilding the page takes longer than the key repeat interval, + // so move the drawn page unless a status toast has to be cleared. + const bool toast = !session_.status.value().empty(); + detail_.scroll_page(up ? -1 : 1, now); + if (!toast && actions_.scroll_detail && actions_.scroll_detail()) return; + } else if (key.code == KEY_LEFT || key.code == KEY_Z || key.ch == 'z') detail_.cycle_screenshot(-1, now); else if (key.code == KEY_RIGHT || key.code == KEY_C || key.ch == 'c') diff --git a/main/ui/appstore_input_controller.hpp b/main/ui/appstore_input_controller.hpp index bcaf1b5..6e444b5 100644 --- a/main/ui/appstore_input_controller.hpp +++ b/main/ui/appstore_input_controller.hpp @@ -38,6 +38,12 @@ struct AppStoreKeyEvent { bool repeated = false; }; +// The launcher's key sounds: Move when a key moves through the screen, Select +// when it acts. +enum class KeySound { None, Move, Select }; + +KeySound key_sound(const AppStoreKeyEvent &key, cp0_keyboard_input_context_t context); + class AppStoreInputController { public: @@ -49,6 +55,9 @@ class AppStoreInputController std::function execute_confirmation; std::function repair_package; std::function render; + // Moves the drawn detail page to its scroll target; false if it needs a render. + std::function scroll_detail; + std::function play_sound; }; AppStoreInputController(AppStoreSessionState &session, PackageJobState &package_job, @@ -61,6 +70,7 @@ class AppStoreInputController private: static bool matches(const AppStoreKeyEvent &key, char ch, uint32_t code); + void play(KeySound sound); AppStoreSessionState &session_; PackageJobState &package_job_; diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index bf3556f..7c9df5e 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -148,13 +148,14 @@ int detail_info_row(lv_obj_t *parent, const char *caption, const std::string &va } // Content that runs under a fixed edge fades out instead of being cut mid-line. -void edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towards_bottom) +lv_obj_t *edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towards_bottom) { lv_obj_t *fade = box(root, 0, y, 320, height, color, color, 0); lv_obj_set_style_bg_grad_color(fade, lv_color_hex(color), 0); lv_obj_set_style_bg_grad_dir(fade, LV_GRAD_DIR_VER, 0); lv_obj_set_style_bg_main_opa(fade, towards_bottom ? LV_OPA_TRANSP : LV_OPA_COVER, 0); lv_obj_set_style_bg_grad_opa(fade, towards_bottom ? LV_OPA_COVER : LV_OPA_TRANSP, 0); + return fade; } void permission_badge(lv_obj_t *parent, int x, int y, uint32_t color) @@ -625,6 +626,12 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView lv_obj_remove_style_all(document); lv_obj_set_width(document, 320); lv_obj_clear_flag(document, LV_OBJ_FLAG_SCROLLABLE); + document_ = document; + // The fades are deleted along with the document when the page is cleared. + lv_obj_add_event_cb(document, [](lv_event_t *event) { + auto *page = static_cast(lv_event_get_user_data(event)); + page->document_ = page->top_fade_ = page->bottom_fade_ = nullptr; + }, LV_EVENT_DELETE, this); const appstore::StoreApp &app = model.app; const lv_font_t *title_font = store_font(app.name, 20, true); @@ -684,10 +691,9 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView lv_obj_set_y(document, -media.page_scroll_at(now)); glide_page(document, media, now); - if (media.page_scroll() > 0) - edge_fade(root, viewport_y, 10, background, false); - if (media.page_scroll() < y - viewport_height) - edge_fade(root, viewport_y + viewport_height - 12, 12, background, true); + top_fade_ = edge_fade(root, viewport_y, 10, background, false); + bottom_fade_ = edge_fade(root, viewport_y + viewport_height - 12, 12, background, true); + show_page_edges(media); if (model.show_status) { // Fixed above the actions so feedback is visible at any scroll position. lv_obj_t *toast = box(root, 0, 132, 320, 17, background, 0x2A3A46, 1); @@ -697,6 +703,25 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView draw_shortcuts(app); } +bool AppDetailPage::scroll(DetailMediaState &media) +{ + if (!document_) return false; + const uint32_t now = lv_tick_get(); + lv_anim_delete(document_, nullptr); + lv_obj_set_y(document_, -media.page_scroll_at(now)); + glide_page(document_, media, now); + show_page_edges(media); + return true; +} + +void AppDetailPage::show_page_edges(const DetailMediaState &media) +{ + // Fade only the edges with more of the page beyond them. + lv_obj_set_flag(top_fade_, LV_OBJ_FLAG_HIDDEN, media.page_scroll() <= 0); + lv_obj_set_flag(bottom_fade_, LV_OBJ_FLAG_HIDDEN, + media.page_scroll() >= media.page_max_scroll()); +} + void AppDetailPage::render_confirmation(const PageRenderContext &context, const ConfirmationViewModel &model) { diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index b4cca11..da20633 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -108,6 +108,9 @@ class AppDetailPage : public AppStoreUiPage DetailMediaState &media, const std::vector &screenshots, const std::function &draw_thumbnail, const std::function &draw_shortcuts); + // Glides the drawn page to the media's scroll target without rebuilding + // it. False when no detail page is drawn. + bool scroll(DetailMediaState &media); void render_confirmation(const PageRenderContext &context, const ConfirmationViewModel &model); void render_progress(const PageRenderContext &context, @@ -118,8 +121,14 @@ class AppDetailPage : public AppStoreUiPage const ScreenshotOverlayViewModel &model, const std::function &draw_background); private: + void show_page_edges(const DetailMediaState &media); + HorizontalMarquee title_marquee_; HorizontalMarquee author_marquee_; + // The drawn page, cleared when the page content is deleted. + lv_obj_t *document_ = nullptr; + lv_obj_t *top_fade_ = nullptr; + lv_obj_t *bottom_fade_ = nullptr; }; class StoreSettingsPage : public AppStoreUiPage diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index 5032d7b..fbd2683 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -241,6 +241,11 @@ bool AppStorePresenter::draw_detail_background(lv_obj_t *root, images_.draw_screenshot(root, screenshots[session_.detail_media.image_index()]); } +bool AppStorePresenter::scroll_detail() +{ + return detail_page_.scroll(session_.detail_media); +} + void AppStorePresenter::render(Screen screen, bool registry_operation_running) { rendered_root_ = nullptr; diff --git a/main/ui/appstore_presenter.hpp b/main/ui/appstore_presenter.hpp index d3f42ed..7edc288 100644 --- a/main/ui/appstore_presenter.hpp +++ b/main/ui/appstore_presenter.hpp @@ -27,6 +27,8 @@ class AppStorePresenter std::function draw_system_bar); void render(Screen screen, bool registry_operation_running); + // Moves the drawn detail page to its scroll target; false if it needs a render. + bool scroll_detail(); private: PageRenderContext context(AppStoreUiPage &page); diff --git a/main/ui/detail_media_state.hpp b/main/ui/detail_media_state.hpp index b649f80..f23eca2 100644 --- a/main/ui/detail_media_state.hpp +++ b/main/ui/detail_media_state.hpp @@ -23,6 +23,7 @@ class DetailMediaState void scroll_page(int delta, uint32_t now); // Target offset; the page glides there from where it was drawn. int page_scroll() const { return page_scroll_; } + int page_max_scroll() const { return page_max_scroll_; } // Time-based so a redraw in the middle of a glide continues it. int page_scroll_at(uint32_t now) const; uint32_t page_glide_remaining(uint32_t now) const; diff --git a/tests/test_appstore_input_controller.cpp b/tests/test_appstore_input_controller.cpp index fc3d72b..0915917 100644 --- a/tests/test_appstore_input_controller.cpp +++ b/tests/test_appstore_input_controller.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace appstore { @@ -63,6 +64,20 @@ int main() assert(appstore_ui::appstore_input_context(appstore_ui::Screen::Detail) == KBD_INPUT_CONTEXT_NAVIGATION); using namespace appstore_ui; + + // Moving keys tick on every repeat; other keys sound once per press. + constexpr auto nav = KBD_INPUT_CONTEXT_NAVIGATION; + constexpr auto text = KBD_INPUT_CONTEXT_TEXT; + assert(key_sound({KEY_DOWN}, nav) == KeySound::Move); + assert(key_sound({KEY_X, 0, 'x', false, true}, nav) == KeySound::Move); + assert(key_sound({KEY_X, 0, 'x'}, text) == KeySound::None); + assert(key_sound({KEY_UP}, text) == KeySound::Move); + assert(key_sound({KEY_ENTER}, text) == KeySound::Select); + assert(key_sound({KEY_8, 0, '8'}, nav) == KeySound::Select); + assert(key_sound({KEY_8, 0, '8', false, true}, nav) == KeySound::None); + assert(key_sound({KEY_LEFTSHIFT}, nav) == KeySound::None); + assert(key_sound({KEY_DOWN, 0, 0, true}, nav) == KeySound::None); + AppStoreSessionState session; PackageJobState package_job; ExitController exit; @@ -91,6 +106,9 @@ int main() int registry_opens = 0; int registry_adds = 0; int confirmations = 0; + int page_moves = 0; + bool page_drawn = true; + std::vector sounds; AppStoreInputController input( session, package_job, exit, share_code, catalog, detail, registry, sync, {[&]() { ++quits; }, @@ -100,7 +118,9 @@ int main() }, [&]() { ++registry_opens; session.screen = Screen::Registry; }, [&]() { ++registry_adds; session.screen = Screen::RegistryEdit; }, - [&]() { ++confirmations; }, [&]() { ++repairs; }, [&]() { ++renders; }}); + [&]() { ++confirmations; }, [&]() { ++repairs; }, [&]() { ++renders; }, + [&]() { ++page_moves; return page_drawn; }, + [&](KeySound sound) { sounds.push_back(sound); }}); session.catalog.categories() = {"All"}; appstore::StoreApp first; @@ -114,11 +134,12 @@ int main() session.screen = Screen::Home; input.handle({KEY_DOWN}, 100); assert(session.catalog.selected_index() == 1 && renders == 1); + assert(sounds == std::vector{KeySound::Move}); - input.handle({KEY_5}, 110); - assert(session.screen == Screen::ShareCode); + input.handle({KEY_5, 0, '5'}, 110); + assert(session.screen == Screen::ShareCode && sounds.back() == KeySound::Select); input.handle({0, 0, 'A'}, 120); - assert(share_code.input() == "A"); + assert(share_code.input() == "A" && sounds.size() == 2); input.handle({KEY_BACKSPACE}, 130); assert(share_code.input().empty()); @@ -208,11 +229,24 @@ int main() session.screen = Screen::Detail; const std::string detail_id = session.catalog.selected_app()->id; session.detail_media.normalize_page(detail_id, 400, 129); + const int renders_before_scroll = renders; input.handle({KEY_X, 0, 'x'}, 186); assert(session.detail_media.page_scroll() == 24); assert(session.detail_media.page_scroll_at(186) == 0); - input.handle({KEY_F, 0, 'f'}, 187); - assert(session.detail_media.page_scroll() == 0); + // Scrolling moves the drawn page instead of rebuilding it. + assert(page_moves == 1 && renders == renders_before_scroll); + input.handle({KEY_F, 0, 'f', false, true}, 187); + assert(session.detail_media.page_scroll() == 0 && sounds.back() == KeySound::Move); + // Clearing a status toast takes a full render. + session.status.value() = "Installed"; + input.handle({KEY_X, 0, 'x'}, 188); + assert(session.status.value().empty() && page_moves == 2); + assert(renders == renders_before_scroll + 1); + // So does a page that is not drawn yet. + page_drawn = false; + input.handle({KEY_F, 0, 'f'}, 189); + assert(page_moves == 3 && renders == renders_before_scroll + 2); + page_drawn = true; session.catalog.selected_app()->images = "icon,one,two"; input.handle({KEY_C, 0, 'c'}, 188); assert(session.detail_media.image_index() == 1 && session.screen == Screen::Detail); @@ -221,9 +255,11 @@ int main() input.handle({KEY_5}, 190); assert(session.screen == Screen::Screenshots); session.screen = Screen::Detail; + const size_t sounds_before_back = sounds.size(); input.handle({KEY_ESC}, 200); input.handle({KEY_ESC, 0, 0, true}, 300); assert(backs == 1 && session.screen == Screen::Home); + assert(sounds.size() == sounds_before_back + 1 && sounds.back() == KeySound::Select); session.screen = Screen::StartupSync; session.sync.startup_failed = false; From f2343b733ddcf52cfeb31f424bd2781b6e81ac0a Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Sat, 17 Oct 2026 00:54:09 +0300 Subject: [PATCH 08/19] feat(store): redesign the startup screen --- README.md | 6 +- main/ui/appstore.cpp | 6 +- main/ui/appstore_pages.cpp | 257 +++++++++++++++------ main/ui/appstore_pages.hpp | 11 +- main/ui/appstore_presenter.cpp | 28 ++- main/ui/appstore_view_model_factory.cpp | 48 +++- main/ui/appstore_view_models.hpp | 8 +- main/ui/sync_controller.cpp | 14 +- tests/test_appstore_view_model_factory.cpp | 22 +- tests/test_sync_controller.cpp | 4 +- 10 files changed, 296 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 4956f54..db04022 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,11 @@ example `1 / 4`) follows up and down buttons, and the catalog size follows the Store icon. Press `4` for settings, `5` for share code, `6` for search, `7` for install/reinstall, and `8` or Enter for details. AppStore syncs the registry -automatically when it starts. +automatically when it starts. The startup screen names the current step +(connecting, updating the catalog, loading artwork, preparing apps) above a +progress bar with the registry's host, and `Tab` opens settings. If no +registry can be reached, an alert offers Exit or Settings; `Z/C` moves between +them and Enter confirms. On the home and startup screens, a short `Esc` press opens the centered "Hold ESC for 3s to exit." hint. Press `Esc` again or another key to dismiss diff --git a/main/ui/appstore.cpp b/main/ui/appstore.cpp index 443a792..aec0861 100644 --- a/main/ui/appstore.cpp +++ b/main/ui/appstore.cpp @@ -200,6 +200,8 @@ void AppStoreApp::draw_system_bar() lv_tick_elaps(g_runtime.session.sync.visible_until_tick) < 1000) { sync_active = true; } + // The startup screen shows the sync itself. + if (g_runtime.session.screen == Screen::StartupSync) sync_active = false; if (active_page_) { auto *sync_component = dynamic_cast( active_page_->top_bar_component("appstore.sync")); @@ -449,8 +451,10 @@ AppStoreApp::AppStoreApp() [this]() { registry_actions_.request_refresh(); }, [this]() { render_current_screen(); }, []() { + // The startup screen animates on its own. return g_runtime.session.screen != Screen::Registry && - g_runtime.session.screen != Screen::RegistryEdit; + g_runtime.session.screen != Screen::RegistryEdit && + g_runtime.session.screen != Screen::StartupSync; }}), input_controller_( runtime_.session, runtime_.package_jobs.state(), runtime_.exit, share_code_, catalog_actions_, diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index 7c9df5e..ca4a112 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -258,11 +258,6 @@ void glide_page(lv_obj_t *document, DetailMediaState &media, uint32_t now) lv_anim_start(&animation); } -void set_progress_scan_x(void *object, int32_t x) -{ - lv_obj_set_x(static_cast(object), x); -} - void modal_backdrop(lv_obj_t *root) { lv_obj_t *obj = lv_obj_create(root); @@ -276,6 +271,130 @@ void modal_backdrop(lv_obj_t *root) lv_obj_set_style_blur_quality(obj, LV_BLUR_QUALITY_SPEED, 0); } +// The startup screen follows Apple's dark system colors. +constexpr uint32_t kPageBackground = 0x081010; +constexpr uint32_t kSecondaryText = 0x8E8E93; +constexpr uint32_t kSystemBlue = 0x0A84FF; +constexpr uint32_t kSystemGray = 0x3A3A3C; + +namespace startup { +constexpr int kLogoSize = 44; +constexpr int kLogoY = 30; +// The artwork has its own padding, so the visible gap is larger than this. +constexpr int kTitleCapsY = kLogoY + kLogoSize + 9; +constexpr int kBarWidth = 184; +constexpr int kBarHeight = 4; +constexpr int kBarX = (320 - kBarWidth) / 2; +constexpr int kBarY = kTitleCapsY + 24; +constexpr int kCaptionY = kBarY + kBarHeight + 7; +constexpr int kHintMiddle = 154; +constexpr int kSweepWidth = 56; +constexpr uint32_t kSweepMs = 1400; +constexpr uint32_t kProgressGlideMs = 400; +} // namespace startup + +int text_width(const std::string &text, const lv_font_t *font) +{ + lv_point_t size = {}; + lv_text_get_size(&size, text.c_str(), font, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + return size.x; +} + +// A key name in a small keycap, then what the key does, centered on center_x. +void key_hint(lv_obj_t *root, const char *key, const char *action, int center_x, int middle) +{ + const lv_font_t *key_font = store_font(key, 10); + const lv_font_t *action_font = store_font(action, 12); + constexpr int pad = 5, gap = 6, cap_height = 15; + const int cap_width = text_width(key, key_font) + 2 * pad; + const int action_width = text_width(action, action_font); + const int x = center_x - (cap_width + gap + action_width) / 2; + box(root, x, middle - cap_height / 2, cap_width, cap_height, kPageBackground, 0x48484A, 1, 4); + label(root, key, x + pad, middle - glyph_middle(key_font, 'b'), cap_width - pad, + key_font->line_height, key_font, kSecondaryText); + label(root, action, x + cap_width + gap, middle - glyph_middle(action_font, 'S'), + action_width + 2, action_font->line_height, action_font, kSecondaryText); +} + +// Indeterminate progress: a short segment sweeping across the track. Timed by +// the clock, so redrawing the page does not restart it. +void sweep_progress(lv_obj_t *track) +{ + using namespace startup; + lv_obj_t *segment = box(track, -kSweepWidth, 0, kSweepWidth, kBarHeight, kSystemBlue, + kSystemBlue, 0, kBarHeight / 2); + lv_anim_t animation; + lv_anim_init(&animation); + lv_anim_set_var(&animation, segment); + // The callback only runs when this value changes, so let it change every tick. + lv_anim_set_values(&animation, 0, static_cast(kSweepMs)); + lv_anim_set_duration(&animation, kSweepMs); + lv_anim_set_repeat_count(&animation, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_custom_exec_cb(&animation, [](lv_anim_t *anim, int32_t) { + // Cubic ease-in-out from off the left edge to off the right edge. + const int64_t p = static_cast(lv_tick_get() % kSweepMs) * 1024 / kSweepMs; + const int64_t q = 1024 - p; + const int64_t eased = p < 512 ? 4 * p * p * p / (1024 * 1024) + : 1024 - 4 * q * q * q / (1024 * 1024); + lv_obj_set_x(static_cast(anim->var), + static_cast(-kSweepWidth + (kBarWidth + kSweepWidth) * eased / 1024)); + }); + lv_anim_start(&animation); +} + +int progress_width(int percent) +{ + using namespace startup; + if (percent <= 0) return 0; + return std::max(kBarHeight, kBarWidth * std::min(percent, 100) / 100); +} + +// An alert in the style of Apple's: title, message, and two buttons, the +// focused one filled. +void startup_alert(lv_obj_t *root, const InitializationProgressViewModel &model) +{ + modal_backdrop(root); + constexpr int width = 256, x = (320 - width) / 2, pad = 14, line_space = 2; + constexpr int button_height = 26, button_gap = 8; + const lv_font_t *title_font = store_font(model.error_title, 15, true); + const lv_font_t *body_font = store_font(model.error_message, 12); + lv_point_t body = {}; + lv_text_get_size(&body, model.error_message.c_str(), body_font, 0, line_space, + width - 2 * pad, LV_TEXT_FLAG_NONE); + const int body_height = + std::min(body.y, 3 * body_font->line_height + 2 * line_space); + const int height = + pad + title_font->line_height + 4 + body_height + 14 + button_height + pad; + const int y = 20 + (150 - height) / 2; + box(root, x, y, width, height, 0x1C1C1E, 0x2C2C2E, 1, 14); + + int row = y + pad; + center_strong_label(root, model.error_title, x + pad, row, width - 2 * pad, + title_font->line_height, title_font, 0xFFFFFF, LV_LABEL_LONG_DOT); + row += title_font->line_height + 4; + lv_obj_t *message = center_label(root, model.error_message, x + pad, row, width - 2 * pad, + body_height, body_font, kSecondaryText, LV_LABEL_LONG_DOT); + lv_obj_set_style_text_line_space(message, line_space, 0); + row += body_height + 14; + + const int button_width = (width - 2 * pad - button_gap) / 2; + const char *const buttons[] = {"Exit", "Settings"}; + for (int i = 0; i < 2; ++i) { + const bool focused = model.failure_focus == i; + const int button_x = x + pad + i * (button_width + button_gap); + const uint32_t fill = focused ? kSystemBlue : kSystemGray; + box(root, button_x, row, button_width, button_height, fill, fill, 0, 8); + const lv_font_t *font = store_font(buttons[i], 13); + const int text_y = row + button_height / 2 - glyph_middle(font, 'E'); + if (focused) + center_strong_label(root, buttons[i], button_x, text_y, button_width, + font->line_height, font, 0xFFFFFF); + else + center_label(root, buttons[i], button_x, text_y, button_width, font->line_height, + font, 0xFFFFFF); + } +} + void scrolling_status_label(lv_obj_t *root, const std::string &text, int x, int y, int w, int h, uint32_t color = 0xCCCC33) { @@ -405,76 +524,78 @@ void AppStoreUiPage::activate() cp0_lvgl_start_app_page(*this); } -void InitializationProgressPage::render(const PageRenderContext &context, - const InitializationProgressViewModel &model) +void InitializationProgressPage::render( + const PageRenderContext &context, const InitializationProgressViewModel &model, + const std::function &draw_logo) { + using namespace startup; context.prepare(); context.draw_system_bar(); lv_obj_t *root = screen(); - box(root, 0, 20, 320, 150, 0x0D1117, 0x0D1117, 0); - box(root, 0, 20, 320, 22, 0x101B2D, 0x101B2D, 0); - const bool preparing_catalog = model.phase == "CATALOG"; - label(root, preparing_catalog ? "Preparing App Catalog" : "Checking Network", - 8, 24, 190, 15, &lv_font_montserrat_12, 0xFFFFFF); - label(root, "Hold ESC", 254, 24, 60, 14, &lv_font_montserrat_10, 0xAECBFA); - center_strong_label(root, appstore::upper_ascii(model.phase), 28, 47, 264, 16, - &lv_font_montserrat_12, 0x58A6FF, LV_LABEL_LONG_DOT); - label(root, appstore::one_line(model.url, 62), 18, 68, 284, 20, - &lv_font_montserrat_10, 0xC9D1D9, LV_LABEL_LONG_DOT); - box(root, 20, 94, 280, 15, 0x111923, 0x30363D, 1, 3); - for (int i = 0; i < 7; ++i) box(root, 24 + i * 39, 98, 28, 7, 0x162235, 0x162235, 0, 2); - if (model.percent >= 0) { - const int fill = std::max(5, std::min(272, model.percent * 272 / 100)); - box(root, 24, 98, fill, 7, 0x2FEC8D, 0x2FEC8D, 0, 2); - box(root, std::max(24, std::min(286, 24 + fill - 4)), 96, 8, 11, - 0xD8FF6A, 0xD8FF6A, 0, 3); - } else { - lv_obj_t *scan = box(root, 24, 97, 52, 9, 0x2FEC8D, 0xD8FF6A, 1, 3); - lv_anim_t animation; - lv_anim_init(&animation); - lv_anim_set_var(&animation, scan); - lv_anim_set_values(&animation, 24, 244); - lv_anim_set_duration(&animation, 900); - lv_anim_set_playback_duration(&animation, 900); - lv_anim_set_repeat_count(&animation, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_path_cb(&animation, lv_anim_path_ease_in_out); - lv_anim_set_exec_cb(&animation, set_progress_scan_x); - lv_anim_start(&animation); + box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0); + draw_logo(root, (320 - kLogoSize) / 2, kLogoY, kLogoSize); + if (model.failed) { + startup_alert(root, model); + return; } - center_label(root, appstore::one_line(model.detail, 52), 18, 119, 284, 14, - &lv_font_montserrat_10, 0xB8B8B8, LV_LABEL_LONG_DOT); - center_strong_label(root, model.cancel_requested ? "Cancelling..." : - (preparing_catalog ? "Building app list... Tab: Settings" : - "Tab: Settings Hold ESC: Exit"), 18, 151, 284, 12, - &lv_font_montserrat_10, 0xCCCC33, LV_LABEL_LONG_DOT); - if (!model.failed) return; - modal_backdrop(root); - box(root, 16, 27, 288, 136, 0x111923, 0xF85149, 2, 4); - box(root, 16, 27, 288, 24, 0x8B2F34, 0x8B2F34, 0); - center_strong_label(root, model.error_title, 32, 32, 256, 15, - &lv_font_montserrat_12, 0xFFFFFF, LV_LABEL_LONG_DOT); - center_strong_label(root, appstore::one_line(model.error_message, 38), 30, 61, 260, 15, - &lv_font_montserrat_12, 0xFFD2D2, LV_LABEL_LONG_DOT); - int y = 82; - for (const auto &line_text : model.error_detail_lines) { - center_label(root, appstore::one_line(line_text, 44), 30, y, 260, 12, - &lv_font_montserrat_10, 0xB8B8B8, LV_LABEL_LONG_DOT); - y += 13; - if (y > 95) break; + const lv_font_t *title_font = store_font(model.title, 17, true); + center_strong_label(root, model.title, 10, kTitleCapsY - glyph_top(title_font, 'C'), 300, + title_font->line_height, title_font, 0xFFFFFF, LV_LABEL_LONG_DOT); + + lv_obj_t *track = box(root, kBarX, kBarY, kBarWidth, kBarHeight, kSystemGray, kSystemGray, 0, + kBarHeight / 2); + lv_obj_set_style_clip_corner(track, true, 0); + const uint32_t now = lv_tick_get(); + if (model.percent != progress_to_) { + // Glide on from the drawn value; a new phase starts from empty. + progress_from_ = progress_to_ >= 0 && model.percent > progress_to_ ? progress_at(now) : 0; + progress_to_ = model.percent; + progress_changed_at_ = now; } - const bool exit_focused = model.failure_focus == 0; - const bool settings_focused = model.failure_focus == 1; - box(root, 45, 119, 92, 19, exit_focused ? 0x8B2F34 : 0x4B1F24, - exit_focused ? 0xCCCC33 : 0xF85149, exit_focused ? 2 : 1, 2); - center_strong_label(root, "EXIT", 49, 123, 84, 12, - &lv_font_montserrat_10, 0xFFFFFF); - box(root, 166, 119, 109, 19, settings_focused ? 0x2EA043 : 0x1A6A2A, - settings_focused ? 0xCCCC33 : 0x2EA043, settings_focused ? 2 : 1, 2); - center_strong_label(root, "SETTINGS", 170, 123, 101, 12, - &lv_font_montserrat_10, 0xFFFFFF); - center_label(root, "Tab: Settings Enter confirm", 48, 146, 224, 12, - &lv_font_montserrat_10, 0xCCCC33); + if (model.percent < 0) { + sweep_progress(track); + } else { + lv_obj_t *fill = box(track, 0, 0, progress_width(progress_at(now)), kBarHeight, + kSystemBlue, kSystemBlue, 0, kBarHeight / 2); + const uint32_t remaining = kProgressGlideMs - std::min(kProgressGlideMs, now - progress_changed_at_); + if (remaining > 0) { + lv_anim_t animation; + lv_anim_init(&animation); + lv_anim_set_var(&animation, fill); + lv_anim_set_user_data(&animation, this); + lv_anim_set_values(&animation, 0, static_cast(remaining)); + lv_anim_set_duration(&animation, remaining); + lv_anim_set_custom_exec_cb(&animation, [](lv_anim_t *anim, int32_t) { + auto *page = static_cast(lv_anim_get_user_data(anim)); + lv_obj_set_width(static_cast(anim->var), + progress_width(page->progress_at(lv_tick_get()))); + }); + lv_anim_set_completed_cb(&animation, [](lv_anim_t *anim) { + auto *page = static_cast(lv_anim_get_user_data(anim)); + lv_obj_set_width(static_cast(anim->var), progress_width(page->progress_to_)); + }); + lv_anim_start(&animation); + } + } + + std::string caption = model.source; + if (model.percent >= 0) + caption += (caption.empty() ? "" : " \xC2\xB7 ") + std::to_string(model.percent) + "%"; + const lv_font_t *caption_font = store_font(caption, 11); + center_label(root, caption, 10, kCaptionY, 300, caption_font->line_height, caption_font, + kSecondaryText, LV_LABEL_LONG_DOT); + key_hint(root, "tab", "Settings", 160, kHintMiddle); +} + +int InitializationProgressPage::progress_at(uint32_t now) const +{ + const uint32_t elapsed = now - progress_changed_at_; + if (progress_to_ < 0 || elapsed >= startup::kProgressGlideMs) return progress_to_; + // Quadratic ease-out. + const int64_t left = startup::kProgressGlideMs - elapsed; + return progress_to_ - static_cast((progress_to_ - progress_from_) * left * left / + (startup::kProgressGlideMs * startup::kProgressGlideMs)); } void CatalogDisplayPage::render(const PageRenderContext &context, diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index da20633..12da59f 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -78,8 +78,17 @@ class AppStoreUiPage : public AppPageRoot class InitializationProgressPage : public AppStoreUiPage { public: + // draw_logo draws the Store icon in the size x size square at x, y. void render(const PageRenderContext &context, - const InitializationProgressViewModel &model); + const InitializationProgressViewModel &model, + const std::function &draw_logo); +private: + int progress_at(uint32_t now) const; + + // The bar glides from the drawn value when progress is reported. + int progress_from_ = 0; + int progress_to_ = -1; + uint32_t progress_changed_at_ = 0; }; class CatalogDisplayPage : public AppStoreUiPage diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index fbd2683..eb7eaac 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -106,6 +106,19 @@ int header_count(lv_obj_t *root, const std::string &text, int right, int middle) return right - width; } +// The Store icon scaled into the size x size square at x, y; false if it is missing. +bool draw_store_icon(lv_obj_t *root, AppStoreImageRenderer &images, int x, int y, int size) +{ + lv_obj_t *icon = images.draw_packaged(root, "store_100.png", x, y); + if (!icon) return false; + const int scale = std::max(1, std::min(size * 256 / lv_obj_get_width(icon), + size * 256 / lv_obj_get_height(icon))); + lv_image_set_scale(icon, static_cast(scale)); + lv_image_set_inner_align(icon, LV_IMAGE_ALIGN_CENTER); + lv_obj_set_size(icon, size, size); + return true; +} + // Catalog size: Store icon, then the count. Returns the icon's left edge. int draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, int total, int right, int middle) @@ -115,14 +128,7 @@ int draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, int total, constexpr int icon_size = 18; const int icon_x = header_count(root, std::to_string(total), right, middle) - kCounterIconGap - icon_size; - if (lv_obj_t *icon = images.draw_packaged(root, "store_100.png", icon_x, 0)) { - const int scale = std::max(1, std::min(icon_size * 256 / lv_obj_get_width(icon), - icon_size * 256 / lv_obj_get_height(icon))); - lv_image_set_scale(icon, static_cast(scale)); - lv_image_set_inner_align(icon, LV_IMAGE_ALIGN_CENTER); - lv_obj_set_size(icon, icon_size, icon_size); - lv_obj_set_y(icon, middle - icon_size / 2); - } else { + if (!draw_store_icon(root, images, icon_x, middle - icon_size / 2, icon_size)) { const lv_font_t *font = store_font("", 14); strong_label(root, "*", icon_x, middle - glyph_middle(font, '*'), icon_size, font->line_height, font, catalog_home::kMuted); @@ -251,7 +257,11 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running) rendered_root_ = nullptr; switch (screen) { case Screen::StartupSync: - initialization_page_.render(context(initialization_page_), view_models_.initialization()); + initialization_page_.render( + context(initialization_page_), view_models_.initialization(), + [this](lv_obj_t *root, int x, int y, int size) { + draw_store_icon(root, images_, x, y, size); + }); break; case Screen::Home: { lv_obj_t *root = catalog_page_.screen(); diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 8dbffe3..27414e4 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -52,6 +52,33 @@ std::string human_size(const std::string &value) return result; } +// What the startup sync is doing, as the startup screen's title. +std::string startup_title(const SyncStatus &status) +{ + if (status.cancel_requested) return "Cancelling…"; + if (status.phase.empty() || status.phase == "network" || status.phase == "config") + return "Connecting…"; + if (status.phase == "catalog") return "Preparing Apps…"; + if (status.phase == "assets") return "Loading Artwork…"; + return "Updating Catalog…"; +} + +// The registry's host name, or the address itself when it has none. +std::string registry_host(const std::string &url) +{ + const size_t scheme = url.find("://"); + if (scheme == std::string::npos) return url; + const size_t start = scheme + 3; + const std::string host = url.substr(start, url.find('/', start) - start); + return host.empty() ? url : host; +} + +std::string sentence(std::string text) +{ + if (!text.empty() && std::string(".!?").find(text.back()) == std::string::npos) text += '.'; + return text; +} + std::string friendly_updated_at(std::string value) { if (value.empty()) return "-"; @@ -165,19 +192,18 @@ ErrorDialogViewModel AppStoreViewModelFactory::error() const InitializationProgressViewModel AppStoreViewModelFactory::initialization() const { InitializationProgressViewModel model; - model.phase = upper_ascii(session_.sync.status.phase.empty() ? "registry" : session_.sync.status.phase); - model.url = session_.sync.status.url.empty() ? session_.registry.registry_url() : session_.sync.status.url; - model.detail = session_.sync.status.detail.empty() ? "Connecting to registry..." : session_.sync.status.detail; - model.percent = session_.sync.status.percent; - if (model.percent >= 0) model.detail += " " + std::to_string(model.percent) + "%"; - model.cancel_requested = session_.sync.status.cancel_requested; + const SyncStatus &status = session_.sync.status; + model.title = startup_title(status); + model.source = registry_host(status.url.empty() ? session_.registry.registry_url() : status.url); + model.percent = status.percent; model.failed = session_.sync.startup_failed; model.failure_focus = session_.sync.failure_focus; - model.error_title = session_.error.title.empty() ? "NETWORK FAILED" : session_.error.title; - model.error_message = session_.error.message.empty() ? "Network check failed." : session_.error.message; - const std::string detail = session_.error.detail.empty() - ? "Check Wi-Fi before opening Store again." : session_.error.detail; - model.error_detail_lines = wrap_display_text(detail, 44); + model.error_title = session_.error.title.empty() ? "Cannot Connect to Store" : session_.error.title; + // The reason, then what to do about it. The non-breaking hyphen keeps Wi-Fi on one line. + model.error_message = + sentence(session_.error.message.empty() ? "No registry could be reached" : session_.error.message) + + " " + sentence(session_.error.detail.empty() + ? "Check Wi\u2011Fi or change registries in Settings" : session_.error.detail); return model; } diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index 805af23..695486c 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -15,16 +15,14 @@ namespace appstore_ui { struct InitializationProgressViewModel { - std::string phase; - std::string url; - std::string detail; + std::string title; + // Host of the registry being synced. + std::string source; int percent = -1; - bool cancel_requested = false; bool failed = false; int failure_focus = 0; std::string error_title; std::string error_message; - std::vector error_detail_lines; }; struct CatalogDisplayViewModel { diff --git a/main/ui/sync_controller.cpp b/main/ui/sync_controller.cpp index d312c66..237ac1c 100644 --- a/main/ui/sync_controller.cpp +++ b/main/ui/sync_controller.cpp @@ -61,9 +61,9 @@ void SyncController::set_start_failure() session_.sync.status.phase = "network"; session_.sync.status.detail = "Unable to start network check"; session_.status.value() = "Network unavailable - press R to retry"; - session_.error.title = "NETWORK FAILED"; - session_.error.message = "No registry is reachable."; - session_.error.detail = "Exit Store or open settings to change registry addresses."; + session_.error.title = "Cannot Connect to Store"; + session_.error.message = "The network check could not start."; + session_.error.detail.clear(); if (dependencies_.render) dependencies_.render(); } @@ -103,11 +103,9 @@ void SyncController::continue_after_startup_failure(const std::string &detail) session_.sync.status.percent = -1; session_.sync.status.phase = "network"; session_.sync.status.detail = detail.empty() ? "Network unavailable" : detail; - session_.error.title = "NETWORK FAILED"; - session_.error.message = "No registry is reachable."; - session_.error.detail = detail.empty() - ? "Exit Store or open settings to change registry addresses." - : detail; + session_.error.title = "Cannot Connect to Store"; + session_.error.message = detail.empty() ? "No registry could be reached." : detail; + session_.error.detail.clear(); session_.status.value().clear(); session_.screen = Screen::StartupSync; } diff --git a/tests/test_appstore_view_model_factory.cpp b/tests/test_appstore_view_model_factory.cpp index 8ea4a33..6c03438 100644 --- a/tests/test_appstore_view_model_factory.cpp +++ b/tests/test_appstore_view_model_factory.cpp @@ -126,8 +126,26 @@ int main() assert(error.title == "OPERATION FAILED"); assert(error.message == "Package operation failed."); auto initialization = factory.initialization(); - assert(initialization.phase == "REGISTRY"); - assert(initialization.detail == "Connecting to registry..."); + assert(initialization.title == "Connecting…"); + assert(initialization.percent == -1 && !initialization.failed); + session.sync.status.phase = "registry"; + session.sync.status.percent = 40; + session.sync.status.url = "https://example.test/apps/registry.json"; + initialization = factory.initialization(); + assert(initialization.title == "Updating Catalog…"); + assert(initialization.source == "example.test" && initialization.percent == 40); + session.sync.status.cancel_requested = true; + assert(factory.initialization().title == "Cancelling…"); + session.sync.status = {}; + // The alert gives the reason, then what to do about it. + session.sync.startup_failed = true; + session.error.message = "Wi-Fi unavailable"; + initialization = factory.initialization(); + assert(initialization.failed && initialization.error_title == "Cannot Connect to Store"); + assert(initialization.error_message == + "Wi-Fi unavailable. Check Wi\u2011Fi or change registries in Settings."); + session.sync.startup_failed = false; + session.error.clear(); session.registry.entries().push_back( {"https://example.test/registry.json", "Example", "ok", "1", "now", "", "global", true, false}); diff --git a/tests/test_sync_controller.cpp b/tests/test_sync_controller.cpp index 1569fe0..b1abd17 100644 --- a/tests/test_sync_controller.cpp +++ b/tests/test_sync_controller.cpp @@ -134,7 +134,7 @@ int main() controller.poll(1000, 200); assert(session.screen == Screen::StartupSync); assert(session.sync.startup_failed && session.sync.startup_active); - assert(session.error.title == "NETWORK FAILED"); + assert(session.error.title == "Cannot Connect to Store"); assert(summaries == 2); session.sync.startup_active = false; session.screen = Screen::Home; @@ -145,7 +145,7 @@ int main() controller.poll(1200, 200); assert(session.screen == Screen::StartupSync && session.sync.startup_active && session.sync.startup_failed); - assert(session.error.detail == "Wi-Fi unavailable"); + assert(session.error.message == "Wi-Fi unavailable" && session.error.detail.empty()); assert(summaries == 2); assert(controller.cancel() && cancels == 1); From b870560af8474b6a72332e93308189e9530c8548 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Sat, 17 Oct 2026 21:19:24 +0300 Subject: [PATCH 09/19] feat(store): restyle Settings and make the registry editor usable The Settings screen now follows the startup screen's dark Apple look, with a segmented region control and the registry picker bracketed by chevrons. The add/edit screen scrolls its fields to a caret that Fn+Z/C moves, steps Enter through Name and URL before enabling Save, and reports why a save was rejected. The editor also plays key sounds, and held keys keep clicking while their redraw waits. --- README.md | 24 ++- main/ui/appstore.cpp | 7 +- main/ui/appstore_input_controller.cpp | 79 +++++--- main/ui/appstore_input_controller.hpp | 3 + main/ui/appstore_pages.cpp | 220 ++++++++++++++++------- main/ui/appstore_pages.hpp | 1 - main/ui/appstore_presenter.cpp | 7 +- main/ui/appstore_shortcut_bar.cpp | 19 +- main/ui/appstore_shortcut_bar.hpp | 1 + main/ui/appstore_view_model_factory.cpp | 9 +- main/ui/appstore_view_models.hpp | 7 + main/ui/registry_controller.cpp | 12 +- main/ui/registry_ui_state.cpp | 50 ++++++ main/ui/registry_ui_state.hpp | 14 ++ tests/test_appstore_input_controller.cpp | 32 +++- tests/test_registry_ui_state.cpp | 17 ++ 16 files changed, 390 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index db04022..c13526c 100644 --- a/README.md +++ b/README.md @@ -92,11 +92,18 @@ Desktop-entry repair is best effort. Failure to find or rewrite an APPLaunch desktop entry is reported as `WARNING` after a successful package operation and does not change the verified package result. -Multiple registries are supported. On the Registries settings screen, use the -region radio buttons to choose the built-in Default or CN registry. Add another -registry from the same screen or with `--add-registry`; the selected region -registry and all enabled custom registries are synced and merged into one app -list. Apps with the same UUID/share code are de-duplicated, with later registry +Multiple registries are supported. The Settings screen uses the startup +screen's dark look: a centered title, a segmented region control, and the +selected registry in a grouped card. `F/X` (up/down) moves between the region +and the registry; `Z/C` (left/right) changes the focused one. Choose Auto, +Default, or CN. `4` adds a registry; edit, delete, and sync keep their keys. On the +add and edit screen, `Fn+Z/C` moves the cursor through the focused field and +Backspace deletes the character before it. Enter moves from Name to URL, from +URL it confirms the fields and enables the Save tab, and from there it returns +to Name. `8` saves while Save is active; while a field is open, `8` types. +Add another registry from the same screen or with +`--add-registry`; the selected region registry and all enabled custom +registries are synced and merged into one app list. Apps with the same UUID/share code are de-duplicated, with later registry metadata taking precedence. On the home screen, use `Z/C` (left/right) to change category and `F/X` (up/down) to select an app. Installed filters catalog apps by their actual package installation state and refreshes after package operations. @@ -129,8 +136,11 @@ from any screen, including while the hint is open. Keys play the launcher's system sounds: arrows and `F/X/Z/C` play the switch sound on every step, including repeats while held, and Enter, Tab, a short -`Esc`, and shortcut keys play the enter sound. Typing in text fields is -silent. A held key repeats no faster than the screen redraws, so the view +`Esc`, and shortcut keys play the enter sound. Typing in the share-code and +search fields is silent. The registry editor sounds too: typed characters, +Backspace, and switching fields play the enter sound, and `Fn+Z/C` plays the +switch sound. A held key repeats no faster than the screen redraws, and its sound keeps +playing while the redraw waits, so the view keeps up and stops when the key is released. The detail page shows the app name, the same color-coded version, maintainer, diff --git a/main/ui/appstore.cpp b/main/ui/appstore.cpp index aec0861..ccb263f 100644 --- a/main/ui/appstore.cpp +++ b/main/ui/appstore.cpp @@ -388,7 +388,12 @@ void AppStoreApp::handle_key(const AppStoreKeyEvent &key) // Keys are handled back to back while more are queued, so repeats that // come faster than a screen rebuilds would hold off drawing until the key // is released. Skip repeats until the last key's change is on screen. - if (key.repeated && key.code != KEY_ESC && key_frame_pending_) return; + // A held key still clicks while its redraw waits, so the feedback keeps up + // with the repeat instead of going silent. + if (key.repeated && key.code != KEY_ESC && key_frame_pending_) { + input_controller_.play_feedback(key); + return; + } const uint32_t key_start = lv_tick_get(); const Screen before_screen = g_runtime.session.screen; app_tracef("handle_key begin screen=%s code=%u ch=%d release=%d repeat=%d", diff --git a/main/ui/appstore_input_controller.cpp b/main/ui/appstore_input_controller.cpp index cc21799..3d1b2b2 100644 --- a/main/ui/appstore_input_controller.cpp +++ b/main/ui/appstore_input_controller.cpp @@ -8,6 +8,7 @@ #include "appstore_client.hpp" #include "input_keys.h" +#include "keyboard_input.h" #include "startup_network_flow.hpp" #include @@ -47,6 +48,20 @@ bool AppStoreInputController::matches(const AppStoreKeyEvent &key, char ch, return key.ch == ch || key.code == code; } +void AppStoreInputController::play_feedback(const AppStoreKeyEvent &key) +{ + KeySound sound = key_sound(key, appstore_input_context(session_.screen)); + if (session_.screen == Screen::RegistryEdit && sound == KeySound::None) { + const bool fn = (key.mods & KBD_MOD_FN) != 0; + if (fn && (key.code == KEY_Z || key.code == KEY_C || + key.code == KEY_LEFT || key.code == KEY_RIGHT)) + sound = KeySound::Move; + else if (key.ch != 0 || key.code == KEY_BACKSPACE) + sound = KeySound::Select; + } + play(sound); +} + void AppStoreInputController::play(KeySound sound) { if (sound != KeySound::None && actions_.play_sound) actions_.play_sound(sound); @@ -93,7 +108,9 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } if (key.repeated && dismiss_key_ == key.code) return; dismiss_key_ = 0; - play(key_sound(key, appstore_input_context(session_.screen))); + // The registry editor sounds like the other screens, including typed + // characters. Share code and search stay silent while typing. + play_feedback(key); switch (session_.screen) { case Screen::StartupSync: @@ -230,7 +247,9 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } else if (key.code == KEY_UP || key.code == KEY_DOWN) session_.registry.page_focus() = 1 - session_.registry.page_focus(); - else if (matches(key, '5', KEY_5) || matches(key, 'e', KEY_E) || + else if (matches(key, '4', KEY_4) || matches(key, 'a', KEY_A)) { + if (actions_.open_registry_add) actions_.open_registry_add(); + } else if (matches(key, '5', KEY_5) || matches(key, 'e', KEY_E) || (key.code == KEY_ENTER && session_.registry.page_focus() == 1)) { const auto *entry = session_.registry.selected_entry(); if (entry && !entry->builtin) registry_.edit_selected(); @@ -252,27 +271,43 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } break; case Screen::RegistryEdit: { - std::string &field = session_.registry.edit_focus() == 0 ? - session_.registry.name_input() : session_.registry.input_url(); - if (key.code == KEY_BACKSPACE && !field.empty()) - field.pop_back(); - else if (key.code == KEY_ENTER) - registry_.submit_editor(); - else if (key.code == KEY_TAB || key.code == KEY_UP || key.code == KEY_DOWN) + const bool fn = (key.mods & KBD_MOD_FN) != 0; + const size_t limit = session_.registry.edit_focus() == 0 ? 48 : 180; + if (!session_.registry.editing_field()) { + // The fields are confirmed, so 8 saves and Enter loops to Name. + if (matches(key, '8', KEY_8)) { + registry_.submit_editor(); + break; + } + if (key.code == KEY_ENTER) { + session_.registry.edit_focus() = 0; + session_.registry.move_caret(1000); + session_.registry.set_editing_field(true); + break; + } + // Anything else starts editing again, then does what it says. + session_.registry.set_editing_field(true); + } + if (key.code == KEY_BACKSPACE) + session_.registry.erase_before_caret(); + else if (key.code == KEY_ENTER) { + // Name confirms into URL; URL confirms the fields and enables Save. + if (session_.registry.edit_focus() == 0) { + session_.registry.edit_focus() = 1; + session_.registry.move_caret(1000); + } else { + session_.registry.set_editing_field(false); + } + } else if (key.code == KEY_TAB || key.code == KEY_UP || key.code == KEY_DOWN) { session_.registry.edit_focus() = 1 - session_.registry.edit_focus(); - else if (key.ch >= 32 && key.ch <= 126 && - (session_.registry.edit_focus() == 0 ? - session_.registry.name_input().size() < 48 : - session_.registry.input_url().size() < 180)) - field.push_back(key.ch); - else if (key.code == KEY_LEFT && !session_.registry.edit_url().empty() && - !session_.registry.entries().empty()) { - session_.registry.select_adjacent_entry(-1); - registry_.edit_selected(); - } else if (key.code == KEY_RIGHT && !session_.registry.edit_url().empty() && - !session_.registry.entries().empty()) { - session_.registry.select_adjacent_entry(1); - registry_.edit_selected(); + // Land at the end, where the next character will be typed. + session_.registry.move_caret(1000); + } else if (fn && (key.code == KEY_Z || key.code == KEY_LEFT)) { + session_.registry.move_caret(-1); + } else if (fn && (key.code == KEY_C || key.code == KEY_RIGHT)) { + session_.registry.move_caret(1); + } else if (!fn && key.ch >= 32 && key.ch <= 126) { + session_.registry.insert_at_caret(key.ch, limit); } break; } diff --git a/main/ui/appstore_input_controller.hpp b/main/ui/appstore_input_controller.hpp index 6e444b5..0757ba3 100644 --- a/main/ui/appstore_input_controller.hpp +++ b/main/ui/appstore_input_controller.hpp @@ -67,6 +67,9 @@ class AppStoreInputController Actions actions); void handle(const AppStoreKeyEvent &key, uint32_t now); + // The click for a key, without acting on it. Used when a repeat arrives + // before the previous one has been drawn. + void play_feedback(const AppStoreKeyEvent &key); private: static bool matches(const AppStoreKeyEvent &key, char ch, uint32_t code); diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index ca4a112..57c2696 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -403,17 +403,60 @@ void scrolling_status_label(lv_obj_t *root, const std::string &text, int x, int lv_obj_set_style_anim_duration(obj, 4000, LV_PART_MAIN | LV_STATE_DEFAULT); } -void radio_option(lv_obj_t *root, int x, int y, const std::string &text, - bool selected, bool focused) +// A grouped settings card. The focused one is outlined in system blue. +lv_obj_t *settings_group(lv_obj_t *root, int y, int height, bool focused) { - const uint32_t border = focused ? 0xCCCC33 : (selected ? 0x58A6FF : 0x6E7681); - const uint32_t text_color = selected ? 0xFFFFFF : 0x8B949E; - box(root, x, y + 2, 10, 10, 0x0D1117, border, 1, 5); - if (selected) - box(root, x + 3, y + 5, 4, 4, focused ? 0xCCCC33 : 0x58A6FF, - focused ? 0xCCCC33 : 0x58A6FF, 0, 2); - label(root, text, x + 15, y, text == "Default" ? 72 : 44, 18, store_font(text, 12), text_color, - LV_LABEL_LONG_DOT); + return box(root, 12, y, 296, height, 0x1C1C1E, focused ? kSystemBlue : 0x2C2C2E, 1, 12); +} + +// A small chevron, drawn rather than taken from a font so it stays crisp. +void chevron(lv_obj_t *root, int x, int middle, bool left, uint32_t color) +{ + constexpr int arm = 5; + for (int row = 0; row < arm; ++row) { + const int inset = left ? arm - 1 - row : row; + box(root, x + inset, middle - arm + row, 2, 2, color, color, 0); + box(root, x + inset, middle + arm - 2 - row, 2, 2, color, color, 0); + } +} + +// Shows the slice of a field that holds the caret, with the caret drawn in it. +void editor_field(lv_obj_t *root, const std::string &value, size_t caret, int x, int y, + int width, bool blink) +{ + const lv_font_t *font = store_font(value, 13); + lv_obj_t *viewport = lv_obj_create(root); + lv_obj_remove_style_all(viewport); + lv_obj_set_pos(viewport, x, y); + lv_obj_set_size(viewport, width, font->line_height); + lv_obj_clear_flag(viewport, LV_OBJ_FLAG_SCROLLABLE); + + const std::string before = value.substr(0, std::min(caret, value.size())); + const int caret_x = text_width(before, font); + // Keep the caret a few pixels inside the field, scrolling the text to do it. + constexpr int margin = 8; + int scroll = 0; + if (caret_x > width - margin) scroll = caret_x - (width - margin); + const int text_width_px = text_width(value, font); + if (scroll > 0 && text_width_px - scroll < width - margin) + scroll = std::max(0, text_width_px - (width - margin)); + + if (!value.empty()) + label(viewport, value, -scroll, 0, LV_SIZE_CONTENT, font->line_height, font, 0xFFFFFF); + lv_obj_t *caret_bar = box(viewport, caret_x - scroll, 1, 1, font->line_height - 2, kSystemBlue, + kSystemBlue, 0); + if (!blink) return; + lv_anim_t blink_anim; + lv_anim_init(&blink_anim); + lv_anim_set_var(&blink_anim, caret_bar); + lv_anim_set_values(&blink_anim, LV_OPA_COVER, LV_OPA_TRANSP); + lv_anim_set_duration(&blink_anim, 530); + lv_anim_set_playback_duration(&blink_anim, 530); + lv_anim_set_repeat_count(&blink_anim, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_exec_cb(&blink_anim, [](void *obj, int32_t value) { + lv_obj_set_style_bg_opa(static_cast(obj), static_cast(value), 0); + }); + lv_anim_start(&blink_anim); } } // namespace @@ -994,48 +1037,76 @@ void StoreSettingsPage::render(const PageRenderContext &context, context.prepare(); context.draw_system_bar(); lv_obj_t *root = screen(); - box(root, 0, 20, 320, 150, 0x0D1117, 0x0D1117, 0); - box(root, 0, 20, 320, 22, 0x1F6FEB, 0x1F6FEB, 0); - label(root, "Registry Settings", 8, 24, 220, 18, store_font("", 14), 0xFFFFFF); - label(root, "Esc Back", 250, 25, 64, 18, store_font("", 12), 0xAECBFA); + box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0); + + const lv_font_t *title_font = store_font("Settings", 17, true); + center_strong_label(root, "Settings", 12, 26 - glyph_top(title_font, 'S'), 296, + title_font->line_height, title_font, 0xFFFFFF); + + // Region is a segmented control: the chosen segment is filled blue. + constexpr int region_y = 48, region_height = 30; const bool region_focused = model.focus == 0; - label(root, "Region", 24, 46, 48, 18, store_font("", 12), - region_focused ? 0xCCCC33 : 0x58A6FF); - radio_option(root, 76, 46, "Auto", model.region_code == "auto", region_focused); - radio_option(root, 142, 46, "Default", model.region_code == "default", region_focused); - radio_option(root, 234, 46, "CN", model.region_code == "CN", region_focused); + settings_group(root, region_y, region_height, region_focused); + const char *const regions[] = {"Auto", "Default", "CN"}; + const char *const codes[] = {"auto", "default", "CN"}; + constexpr int segment_width = 98; + for (int i = 0; i < 3; ++i) { + const bool selected = model.region_code == codes[i]; + const int x = 13 + i * segment_width; + if (selected) + box(root, x, region_y + 1, segment_width - 2, region_height - 2, kSystemBlue, + kSystemBlue, 0, 11); + const lv_font_t *font = store_font(regions[i], 13); + const int text_y = region_y + region_height / 2 - glyph_middle(font, 'A'); + if (selected) + center_strong_label(root, regions[i], x, text_y, segment_width - 2, + font->line_height, font, 0xFFFFFF); + else + center_label(root, regions[i], x, text_y, segment_width - 2, font->line_height, + font, kSecondaryText); + } + + constexpr int source_y = 84, source_height = 46; + settings_group(root, source_y, source_height, model.focus == 1 && model.has_entry); if (!model.has_entry) { - label(root, model.loading ? "Loading registries..." : "No registries configured.", - 24, 82, 272, 36, store_font("", 12), 0xB8B8B8, LV_LABEL_LONG_WRAP); + const std::string message = + model.loading ? "Loading registries\u2026" : "No registries configured"; + const lv_font_t *font = store_font(message, 13); + center_label(root, message, 24, source_y + (source_height - font->line_height) / 2, 272, + font->line_height, font, kSecondaryText, LV_LABEL_LONG_DOT); } else { const auto &entry = model.entry; const std::string source = model.region_code == "auto" - ? "Source (" + model.active_region + ")" : "Source"; - label(root, source, 24, 68, 210, 18, store_font(source, 12), - model.focus == 1 ? 0xCCCC33 : 0x58A6FF, LV_LABEL_LONG_DOT); - center_label(root, std::to_string(model.selected_index + 1) + "/" + - std::to_string(model.entry_count), 248, 68, 48, 18, - store_font("", 12), 0x8B949E, LV_LABEL_LONG_DOT); - const uint32_t nav = model.focus == 1 ? 0xFF6A3D : 0x6E7681; - label(root, "<", 6, 85, 16, 22, store_font("", 20), nav); - label(root, ">", 302, 85, 16, 22, store_font("", 20), nav); - marquee_label(root, entry.name, 24, 86, 194, 20, store_font(entry.name, 14), - 0xFFFFFF, source_marquee_, entry.url + entry.name); - lv_obj_t *count = label(root, entry.count + " apps", 224, 87, 72, 18, - store_font("", 12), 0xCCCC33, LV_LABEL_LONG_DOT); + ? "Source \xC2\xB7 " + model.active_region : "Source"; + const lv_font_t *caption_font = store_font(source, 11); + label(root, source, 24, source_y + 6, 180, caption_font->line_height, caption_font, + kSecondaryText, LV_LABEL_LONG_DOT); + const std::string summary = entry.count + " apps \xC2\xB7 " + + std::to_string(model.selected_index + 1) + " of " + + std::to_string(model.entry_count); + lv_obj_t *count = label(root, summary, 150, source_y + 6, 146, caption_font->line_height, + caption_font, kSecondaryText, LV_LABEL_LONG_DOT); lv_obj_set_style_text_align(count, LV_TEXT_ALIGN_RIGHT, 0); - label(root, "URL", 24, 111, 32, 18, store_font("", 12), 0x58A6FF); - box(root, 60, 108, 236, 24, 0x111923, 0x2A3A46, 1, 2); - const std::string url = entry.builtin ? model.registry_url : entry.url; - marquee_label(root, url, 66, 112, 224, 18, store_font(url, 12), 0xFFFFFF, - url_marquee_, url); + + const lv_font_t *name_font = store_font(entry.name, 14); + // Chevrons bracket the name, so left/right reads as a choice. + constexpr int name_x = 40, name_right = 280; + const int name_middle = source_y + 21 + name_font->line_height / 2; + const uint32_t arrow = model.focus == 1 ? kSystemBlue : 0x636366; + chevron(root, 24, name_middle, true, arrow); + chevron(root, name_right, name_middle, false, arrow); + marquee_label(root, entry.name, name_x, source_y + 21, name_right - name_x, + name_font->line_height, name_font, 0xFFFFFF, source_marquee_, + entry.url + entry.name, LV_TEXT_ALIGN_CENTER); } + if (!model.status.empty()) { - // Keep the full status readable without taking space from the action row. - lv_obj_t *status = label(root, model.status, 10, 134, 300, 17, - store_font(model.status, 12), - model.status_is_error ? 0xF85149 : 0xCCCC33, - LV_LABEL_LONG_SCROLL_CIRCULAR); + // Above the bookmark tabs, so a long status can scroll without covering them. + lv_obj_t *status = label(root, model.status, 16, 134, 288, 14, + store_font(model.status, 11), + model.status_is_error ? 0xFF453A : kSecondaryText, + LV_LABEL_LONG_SCROLL_CIRCULAR); + lv_obj_set_style_text_align(status, LV_TEXT_ALIGN_CENTER, 0); lv_obj_set_style_anim_duration(status, 8000, LV_PART_MAIN | LV_STATE_DEFAULT); } } @@ -1046,29 +1117,44 @@ void StoreSettingsPage::render_editor(const PageRenderContext &context, context.prepare(); context.draw_system_bar(); lv_obj_t *root = screen(); - box(root, 0, 20, 320, 150, 0x0D1117, 0x0D1117, 0); - box(root, 0, 20, 320, 22, 0x1F6FEB, 0x1F6FEB, 0); - label(root, model.editing ? "Edit Registry" : "Add Registry", - 8, 24, 220, 18, store_font("", 14), 0xFFFFFF); - label(root, "Esc Back", 250, 25, 64, 18, store_font("", 12), 0xAECBFA); - - label(root, "Name", 10, 46, 50, 18, store_font("", 12), - model.focus == 0 ? 0xCCCC33 : 0x58A6FF); - box(root, 10, 65, 300, 24, 0x111923, - model.focus == 0 ? 0xCCCC33 : 0x2A3A46, 1, 2); - label(root, model.name, 16, 68, 288, 18, - store_font(model.name, 12), 0xE6EDF3, LV_LABEL_LONG_DOT); - - label(root, "URL", 10, 92, 50, 18, store_font("", 12), - model.focus == 1 ? 0xCCCC33 : 0x58A6FF); - box(root, 10, 110, 300, 35, 0x111923, - model.focus == 1 ? 0xCCCC33 : 0x2A3A46, 1, 2); - label(root, model.url, 16, 113, 288, 28, store_font(model.url, 12), - 0xE6EDF3, LV_LABEL_LONG_WRAP); - - center_label(root, "Tab Next BS Delete Enter Save", - 10, 152, 300, 18, store_font("", 12), 0xCCCC33, - LV_LABEL_LONG_DOT); + box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0); + + const std::string title = model.editing ? "Edit Registry" : "Add Registry"; + const lv_font_t *title_font = store_font(title, 17, true); + center_strong_label(root, title, 12, 26 - glyph_top(title_font, 'E'), 296, + title_font->line_height, title_font, 0xFFFFFF); + + const char *const captions[] = {"Name", "URL"}; + const std::string values[] = {model.name, model.url}; + // The second field stops above the bookmark tabs. + constexpr int row_y[] = {48, 92}; + for (int i = 0; i < 2; ++i) { + constexpr int height = 40; + const bool focused = model.editing_field && model.focus == i; + settings_group(root, row_y[i], height, focused); + const lv_font_t *caption_font = store_font(captions[i], 11); + label(root, captions[i], 24, row_y[i] + 4, 272, caption_font->line_height, caption_font, + focused ? kSystemBlue : kSecondaryText); + if (!model.editing_field) { + const lv_font_t *font = store_font(values[i], 13); + label(root, values[i], 24, row_y[i] + 19, 272, font->line_height, font, 0xFFFFFF, + LV_LABEL_LONG_DOT); + } else if (!focused && values[i].empty()) { + const lv_font_t *font = store_font("Required", 13); + label(root, "Required", 24, row_y[i] + 19, 272, font->line_height, font, 0x636366); + } else { + // The caret keeps the typed end in view, scrolling the field with it. + editor_field(root, values[i], focused ? model.caret : values[i].size(), 24, + row_y[i] + 19, 272, focused); + } + } + if (!model.status.empty()) { + lv_obj_t *status = label(root, model.status, 16, 136, 240, 14, + store_font(model.status, 11), + model.status_is_error ? 0xFF453A : kSecondaryText, + LV_LABEL_LONG_DOT); + lv_obj_set_style_text_align(status, LV_TEXT_ALIGN_CENTER, 0); + } } } // namespace appstore_ui diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index 12da59f..513d638 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -149,7 +149,6 @@ class StoreSettingsPage : public AppStoreUiPage const RegistryEditorViewModel &model); private: HorizontalMarquee source_marquee_; - HorizontalMarquee url_marquee_; }; } // namespace appstore_ui diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index eb7eaac..6567909 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -312,9 +312,12 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running) !model.region_commit_pending); break; } - case Screen::RegistryEdit: - settings_page_.render_editor(context(settings_page_), view_models_.registry_editor()); + case Screen::RegistryEdit: { + const RegistryEditorViewModel model = view_models_.registry_editor(); + settings_page_.render_editor(context(settings_page_), model); + AppStoreShortcutBar::render_editor(settings_page_.screen(), !model.editing_field); break; + } case Screen::ShareCode: catalog_page_.render_text_entry(context(catalog_page_), view_models_.share_code()); break; diff --git a/main/ui/appstore_shortcut_bar.cpp b/main/ui/appstore_shortcut_bar.cpp index ba72aaf..4a1cf3f 100644 --- a/main/ui/appstore_shortcut_bar.cpp +++ b/main/ui/appstore_shortcut_bar.cpp @@ -15,7 +15,8 @@ constexpr int kScreenHeight = 170; // A bookmark tab: the same tinted chip as the detail fields, but the rounded // bottom continues past the screen, so the page edge cuts it with no border. void shortcut_label(lv_obj_t *root, int center_x, - const std::string &text, uint32_t color, int width = 52) + const std::string &text, uint32_t color, int width = 52, + bool active = true) { constexpr int top = 152, radius = 7; const int x = center_x - width / 2; @@ -27,7 +28,7 @@ void shortcut_label(lv_obj_t *root, int center_x, lv_obj_clear_flag(tab, LV_OBJ_FLAG_SCROLLABLE); lv_obj_set_style_radius(tab, radius, 0); lv_obj_set_style_bg_color(tab, lv_color_hex(color), 0); - lv_obj_set_style_bg_opa(tab, LV_OPA_50, 0); + lv_obj_set_style_bg_opa(tab, active ? LV_OPA_50 : LV_OPA_20, 0); lv_obj_set_style_border_width(tab, 1, 0); lv_obj_set_style_border_color(tab, lv_color_hex(color), 0); lv_obj_set_style_border_opa(tab, LV_OPA_50, 0); @@ -39,7 +40,7 @@ void shortcut_label(lv_obj_t *root, int center_x, lv_obj_set_pos(label, x + 2, top + (visible - font->line_height) / 2); lv_obj_set_size(label, width - 4, font->line_height); lv_obj_set_style_text_font(label, font, 0); - lv_obj_set_style_text_color(label, lv_color_hex(0xFFFFFF), 0); + lv_obj_set_style_text_color(label, lv_color_hex(active ? 0xFFFFFF : 0x8E8E93), 0); lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); lv_label_set_long_mode(label, LV_LABEL_LONG_DOT); lv_label_set_text(label, text.c_str()); @@ -79,11 +80,17 @@ void AppStoreShortcutBar::render_settings(lv_obj_t *root, bool has_entry, bool actions_available) { if (!actions_available) return; + shortcut_label(root, 48, "add", 0x0A84FF); if (has_entry && !builtin_entry) - shortcut_label(root, 104, "edit", 0x168CE5); + shortcut_label(root, 104, "edit", 0x0A84FF); if (has_entry && !builtin_entry) - shortcut_label(root, 216, "delete", 0xFF5B4A); - shortcut_label(root, 272, "sync", 0x58A6FF); + shortcut_label(root, 216, "delete", 0xFF453A); + shortcut_label(root, 272, "sync", 0x30D158); +} + +void AppStoreShortcutBar::render_editor(lv_obj_t *root, bool save_active) +{ + shortcut_label(root, 272, "save", save_active ? 0x30D158 : 0x3A3A3C, 52, save_active); } } // namespace appstore_ui diff --git a/main/ui/appstore_shortcut_bar.hpp b/main/ui/appstore_shortcut_bar.hpp index 0353d69..210ba51 100644 --- a/main/ui/appstore_shortcut_bar.hpp +++ b/main/ui/appstore_shortcut_bar.hpp @@ -21,6 +21,7 @@ class AppStoreShortcutBar const appstore::StoreApp &app); static void render_settings(lv_obj_t *root, bool has_entry, bool builtin_entry, bool actions_available); + static void render_editor(lv_obj_t *root, bool save_active); }; } // namespace appstore_ui diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 27414e4..1dc1d90 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -234,8 +234,13 @@ StoreSettingsViewModel AppStoreViewModelFactory::settings(bool operation_running RegistryEditorViewModel AppStoreViewModelFactory::registry_editor() const { - return {!session_.registry.edit_url().empty(), session_.registry.name_input(), - session_.registry.input_url(), session_.registry.edit_focus()}; + RegistryEditorViewModel model{!session_.registry.edit_url().empty(), + session_.registry.name_input(), session_.registry.input_url(), + session_.registry.edit_focus(), session_.registry.caret(), + session_.registry.editing_field(), {}, false}; + model.status = session_.status.value(); + model.status_is_error = !model.status.empty(); + return model; } TextEntryViewModel AppStoreViewModelFactory::share_code() const diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index 695486c..ecb1c7e 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -8,6 +8,7 @@ #include "appstore_client.hpp" +#include #include #include #include @@ -136,6 +137,12 @@ struct RegistryEditorViewModel { std::string name; std::string url; int focus = 0; + // Byte offset of the caret in the focused field. + size_t caret = 0; + // Save stays inactive until Enter confirms the fields. + bool editing_field = true; + std::string status; + bool status_is_error = false; }; } // namespace appstore_ui diff --git a/main/ui/registry_controller.cpp b/main/ui/registry_controller.cpp index 6333f11..40b584d 100644 --- a/main/ui/registry_controller.cpp +++ b/main/ui/registry_controller.cpp @@ -222,10 +222,18 @@ bool RegistryController::poll_region_debounce(uint32_t now, uint32_t delay_ms) void RegistryController::submit_editor() { if (session_.registry.name_input().empty() || session_.registry.input_url().empty()) { - session_.status.value() = "Name and URL required"; + session_.status.value() = session_.registry.name_input().empty() ? "Name required" + : "URL required"; + // Leave the missing field open, so the rejection is visible and editable. + session_.registry.edit_focus() = session_.registry.name_input().empty() ? 0 : 1; + session_.registry.move_caret(1000); + session_.registry.set_editing_field(true); + return; + } + if (!operation_available()) { + session_.registry.set_editing_field(true); return; } - if (!operation_available()) return; RegistryOpRequest request; request.kind = session_.registry.edit_url().empty() ? RegistryOpKind::AddRegistry : RegistryOpKind::EditRegistry; diff --git a/main/ui/registry_ui_state.cpp b/main/ui/registry_ui_state.cpp index 643fc78..fb6e2f9 100644 --- a/main/ui/registry_ui_state.cpp +++ b/main/ui/registry_ui_state.cpp @@ -7,6 +7,7 @@ #include "registry_ui_state.hpp" #include +#include namespace appstore_ui { namespace { @@ -98,6 +99,8 @@ void RegistryUiState::begin_add() name_input_.clear(); input_url_ = kDefaultRegistryUrl; edit_focus_ = 0; + caret_ = 0; + editing_field_ = true; } bool RegistryUiState::begin_edit_selected() @@ -108,6 +111,8 @@ bool RegistryUiState::begin_edit_selected() input_url_ = entry->url; name_input_ = entry->name; edit_focus_ = 0; + caret_ = name_input_.size(); + editing_field_ = true; return true; } @@ -116,6 +121,51 @@ void RegistryUiState::finish_edit() edit_url_.clear(); } +std::string &RegistryUiState::edited_field() +{ + return edit_focus_ == 0 ? name_input_ : input_url_; +} + +void RegistryUiState::clamp_caret() +{ + caret_ = std::min(caret_, edited_field().size()); +} + +void RegistryUiState::move_caret(int delta) +{ + clamp_caret(); + const std::string &field = edited_field(); + while (delta < 0 && caret_ > 0) { + // Step back over a whole UTF-8 character, not just its last byte. + do { --caret_; } while (caret_ > 0 && (static_cast(field[caret_]) & 0xC0) == 0x80); + ++delta; + } + while (delta > 0 && caret_ < field.size()) { + ++caret_; + while (caret_ < field.size() && (static_cast(field[caret_]) & 0xC0) == 0x80) ++caret_; + --delta; + } +} + +void RegistryUiState::insert_at_caret(char ch, size_t limit) +{ + std::string &field = edited_field(); + clamp_caret(); + if (field.size() >= limit) return; + field.insert(caret_, 1, ch); + ++caret_; +} + +void RegistryUiState::erase_before_caret() +{ + std::string &field = edited_field(); + clamp_caret(); + if (caret_ == 0) return; + const size_t end = caret_; + move_caret(-1); + field.erase(caret_, end - caret_); +} + bool RegistryUiState::schedule_region(const std::string ®ion, uint32_t now) { if (region == region_code_) return false; diff --git a/main/ui/registry_ui_state.hpp b/main/ui/registry_ui_state.hpp index 5f42520..f1fea12 100644 --- a/main/ui/registry_ui_state.hpp +++ b/main/ui/registry_ui_state.hpp @@ -35,6 +35,12 @@ class RegistryUiState bool begin_edit_selected(); void finish_edit(); + // The caret sits on a byte boundary. Typing and deleting happen there, and + // left/right move it by one character. + void move_caret(int delta); + void insert_at_caret(char ch, size_t limit); + void erase_before_caret(); + bool schedule_region(const std::string ®ion, uint32_t now); std::optional take_due_region(uint32_t now, uint32_t delay_ms, bool operation_running); @@ -54,6 +60,10 @@ class RegistryUiState const std::string &name_input() const { return name_input_; } int &edit_focus() { return edit_focus_; } int edit_focus() const { return edit_focus_; } + size_t caret() const { return caret_; } + // Typing is open until Enter confirms the fields, which enables Save. + bool editing_field() const { return editing_field_; } + void set_editing_field(bool editing) { editing_field_ = editing; } const std::string ®ion_code() const { return region_code_; } const std::string ®ion_label() const { return region_label_; } const std::string ®istry_url() const { return registry_url_; } @@ -64,6 +74,8 @@ class RegistryUiState static std::string label_for_region(const std::string ®ion); std::string url_for_region(const std::string ®ion) const; void clamp_selection(); + std::string &edited_field(); + void clamp_caret(); std::vector lines_; std::vector entries_; @@ -73,6 +85,8 @@ class RegistryUiState std::string edit_url_; std::string name_input_; int edit_focus_ = 0; + size_t caret_ = 0; + bool editing_field_ = true; std::string region_code_ = "auto"; std::string region_label_ = "Auto"; std::string registry_url_ = kDefaultRegistryUrl; diff --git a/tests/test_appstore_input_controller.cpp b/tests/test_appstore_input_controller.cpp index 0915917..4878e24 100644 --- a/tests/test_appstore_input_controller.cpp +++ b/tests/test_appstore_input_controller.cpp @@ -8,6 +8,7 @@ #include "appstore_task_service.hpp" #include "detached_worker_launcher.hpp" #include "input_keys.h" +#include "keyboard_input.h" #include #include @@ -194,6 +195,31 @@ int main() input.handle({KEY_X, 0, 'x'}, 162); assert(session.registry.edit_focus() == 1); assert(session.registry.input_url() == url_before_x + "x"); + // Fn+Z/C moves the cursor; typing and Backspace happen at the cursor. + input.handle({KEY_Z, KBD_MOD_FN, 'z'}, 163); + input.handle({KEY_Y, 0, 'y'}, 164); + assert(session.registry.input_url() == url_before_x + "yx"); + input.handle({KEY_C, KBD_MOD_FN, 'c'}, 165); + input.handle({KEY_BACKSPACE}, 166); + assert(session.registry.input_url() == url_before_x + "y"); + // While a field is open, 8 types. Enter steps Name, then URL, then confirms. + input.handle({KEY_8, 0, '8'}, 167); + assert(session.registry.input_url() == url_before_x + "y8"); + assert(session.registry.editing_field()); + session.registry.edit_focus() = 0; + input.handle({KEY_ENTER}, 168); + assert(session.registry.editing_field() && session.registry.edit_focus() == 1); + input.handle({KEY_ENTER}, 168); + assert(!session.registry.editing_field()); + input.handle({KEY_ENTER}, 168); + assert(session.registry.editing_field() && session.registry.edit_focus() == 0); + session.registry.name_input().clear(); + input.handle({KEY_ENTER}, 168); + input.handle({KEY_ENTER}, 168); + input.handle({KEY_8, 0, '8'}, 169); + assert(session.screen == Screen::RegistryEdit); + assert(session.status.value() == "Name required"); + assert(session.registry.input_url() == url_before_x + "y8"); appstore::RegistryData registry_data; registry_data.entries.push_back( @@ -206,9 +232,11 @@ int main() assert(session.registry.name_input() == "Example"); session.screen = Screen::Registry; input.handle({KEY_4}, 180); - assert(session.screen == Screen::Registry && registry_adds == 0); + assert(session.screen == Screen::RegistryEdit && registry_adds == 1); + session.screen = Screen::Registry; input.handle({KEY_A, 0, 'a'}, 181); - assert(session.screen == Screen::Registry && registry_adds == 0); + assert(session.screen == Screen::RegistryEdit && registry_adds == 2); + session.screen = Screen::Registry; session.status.value().clear(); input.handle({KEY_6}, 182); input.handle({KEY_T, 0, 't'}, 183); diff --git a/tests/test_registry_ui_state.cpp b/tests/test_registry_ui_state.cpp index 9d4eba1..0402221 100644 --- a/tests/test_registry_ui_state.cpp +++ b/tests/test_registry_ui_state.cpp @@ -44,6 +44,23 @@ int main() assert(state.edit_url().empty()); assert(state.name_input().empty()); assert(state.input_url() == appstore_ui::RegistryUiState::kDefaultRegistryUrl); + assert(state.caret() == 0); + + // The caret edits in the middle of a field, not only at its end. + state.name_input() = "ac"; + state.move_caret(1000); + state.move_caret(-1); + state.insert_at_caret('b', 48); + assert(state.name_input() == "abc" && state.caret() == 2); + state.erase_before_caret(); + assert(state.name_input() == "ac" && state.caret() == 1); + state.input_url() = "héllo"; + state.edit_focus() = 1; + state.move_caret(1000); + // Three characters back steps over both bytes of é's neighbour, not into it. + state.move_caret(-3); + state.insert_at_caret('X', 180); + assert(state.input_url() == "héXllo"); std::cout << "registry UI state tests passed\n"; } From a1bbc415597d3cce3b3b105dc56ac837826a997b Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 18:55:37 +0300 Subject: [PATCH 10/19] feat(store): restrict the Store to built-in mirrors with reachability fallback --- main/backend/appstore_native.cpp | 364 ++++++++++++++++++------------- tests/test_native_backend.cpp | 268 ++++++++++++++++++++++- tests/test_native_backend.sh | 1 - 3 files changed, 471 insertions(+), 162 deletions(-) diff --git a/main/backend/appstore_native.cpp b/main/backend/appstore_native.cpp index df8c4cd..3abc268 100644 --- a/main/backend/appstore_native.cpp +++ b/main/backend/appstore_native.cpp @@ -317,9 +317,12 @@ int run_bounded(const std::vector &args, int timeout_seconds) return -1; } -int run_cancellable(const std::vector &args, const std::atomic &cancel) +int run_cancellable(const std::vector &args, const std::atomic &cancel, + int timeout_seconds = 900) { if (args.empty()) return -1; + if (cancel.load()) return 130; + const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(timeout_seconds); pid_t pid = fork(); if (pid < 0) return -1; if (pid == 0) { @@ -339,10 +342,18 @@ int run_cancellable(const std::vector &args, const std::atomic= deadline) { + const int result = cancel.load() ? 130 : 124; kill(-pid, SIGTERM); - do { } while (waitpid(pid, &status, 0) < 0 && errno == EINTR); - return 130; + const auto kill_deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(250); + do { + const pid_t terminated = waitpid(pid, &status, WNOHANG); + if (terminated == pid || (terminated < 0 && errno != EINTR)) return result; + std::this_thread::sleep_for(std::chrono::milliseconds(25)); + } while (std::chrono::steady_clock::now() < kill_deadline); + kill(-pid, SIGKILL); + while (waitpid(pid, &status, 0) < 0 && errno == EINTR) {} + return result; } std::this_thread::sleep_for(std::chrono::milliseconds(50)); } @@ -378,14 +389,6 @@ std::pair capture(const std::vector &args, size_t return {WIFEXITED(status) ? WEXITSTATUS(status) : -1, output}; } -std::string normalize_url(std::string value) -{ - while (!value.empty() && std::isspace(static_cast(value.front()))) value.erase(value.begin()); - while (!value.empty() && std::isspace(static_cast(value.back()))) value.pop_back(); - if (!value.empty() && value.find("://") == std::string::npos) value = "https://" + value; - return value; -} - json builtin_registry(const std::string ®ion) { bool cn = region == "CN"; @@ -393,34 +396,59 @@ json builtin_registry(const std::string ®ion) {"enabled", true}, {"builtin", true}, {"region", cn ? "CN" : "default"}}; } -json load_config() +json normalize_config(const json &config) { - json config = read_json(config_path()); - if (!config.is_object()) config = json::object(); - std::string region = config.value("region", "auto"); + auto string_setting = [&](const char *key, const char *fallback) -> std::string { + return config.is_object() && config.contains(key) && config[key].is_string() + ? config[key].get() : fallback; + }; + std::string region = string_setting("region", "auto"); if (region != "auto" && region != "CN" && region != "default") region = "auto"; - std::string active = config.value("active_region", "default"); - if (active != "CN") active = "default"; - json custom = json::array(); - if (config.contains("registries") && config["registries"].is_array()) { - for (const auto &item : config["registries"]) { - if (!item.is_object()) continue; - std::string url = normalize_url(item.value("url", "")); - if (url.empty() || url == kDefaultUrl || url == kCnUrl) continue; - json copy = item; - copy["url"] = url; - copy["name"] = copy.value("name", url); - copy["enabled"] = copy.value("enabled", true); - custom.push_back(copy); + std::string active = string_setting("active_region", "default"); + if (active != "CN" && active != "default") active = "default"; + if (region != "auto") active = region; + return {{"region", region}, {"active_region", active}, + {"registries", json::array({builtin_registry(active)})}}; +} + +json load_config() +{ + return normalize_config(read_json(config_path())); +} + +class RegistryLock { +public: + explicit RegistryLock(const char *name, bool exclusive_sync = false) + { + fd_ = ::open((state_dir() / name).c_str(), O_CREAT | O_RDWR, 0644); + if (fd_ < 0) throw std::runtime_error("unable to open registry lock"); + while (flock(fd_, LOCK_EX | (exclusive_sync ? LOCK_NB : 0)) != 0) { + if (errno == EINTR) continue; + ::close(fd_); + throw std::runtime_error(exclusive_sync ? "catalog sync already running" : "unable to lock registry config"); } } - config = {{"region", region}, {"active_region", active}, {"registries", json::array()}}; - config["registries"].push_back(builtin_registry(active)); - for (auto &item : custom) config["registries"].push_back(item); - return config; + ~RegistryLock() { flock(fd_, LOCK_UN); ::close(fd_); } + RegistryLock(const RegistryLock &) = delete; + RegistryLock &operator=(const RegistryLock &) = delete; +private: + int fd_; +}; + +uint64_t config_revision() +{ + const json config = read_json(config_path()); + return config.is_object() && config.contains("_revision") && config["_revision"].is_number_unsigned() + ? config["_revision"].get() : 0; } -void save_config(const json &config) { write_json(config_path(), config); } +// Callers hold registry-config.lock, including read/modify/write operations. +void save_config(const json &config) +{ + json saved = config; + saved["_revision"] = config_revision() + 1; + write_json(config_path(), saved); +} fs::path registry_cache(const std::string &url) { @@ -468,14 +496,14 @@ void update_status(bool running, const std::string &url, const std::string &deta } void curl_download(const std::string &url, const fs::path &destination, bool resume = false, - const std::atomic *cancel = nullptr) + const std::atomic *cancel = nullptr, int timeout_seconds = 900) { fs::create_directories(destination.parent_path()); - std::vector args = {"curl", "-fL", "--connect-timeout", "10", "--max-time", "900", + std::vector args = {"curl", "-fL", "--connect-timeout", "10", "--max-time", std::to_string(timeout_seconds), "-A", "CardputerZero-AppStore/0.1"}; if (resume) args.insert(args.end(), {"-C", "-"}); args.insert(args.end(), {"-o", destination.string(), url}); - const int result = cancel ? run_cancellable(args, *cancel) : capture(args, 64 * 1024).first; + const int result = cancel ? run_cancellable(args, *cancel, timeout_seconds) : capture(args, 64 * 1024).first; if (result != 0) { if (cancel && cancel->load()) throw std::runtime_error("package operation cancelled"); throw std::runtime_error("download failed (curl " + std::to_string(result) + "): " + url); @@ -521,7 +549,7 @@ void configure_proxy(hv::HttpClient &client) } std::vector hv_download_batch(const std::vector &downloads, - const std::atomic *cancel = nullptr) + const std::atomic *cancel = nullptr, int timeout_seconds = 30) { std::vector succeeded(downloads.size(), false); if (downloads.empty()) return succeeded; @@ -533,14 +561,14 @@ std::vector hv_download_batch(const std::vector &downloads, downloads.begin(), downloads.end(), [](const HttpDownload &download) { return download.url.rfind("https://", 0) == 0; }); - if (proxy_configured || https_without_ssl) { + if (proxy_configured || https_without_ssl || env_or("M5APPSTORE_HTTP_TRANSPORT", "") == "curl") { hv::async::startup(2, 6); std::vector> futures; futures.reserve(downloads.size()); for (const auto &download : downloads) { - futures.push_back(hv::async([download]() { + futures.push_back(hv::async([download, cancel, timeout_seconds]() { try { - curl_download(download.url, download.destination); + curl_download(download.url, download.destination, false, cancel, timeout_seconds); return true; } catch (...) { return false; @@ -548,9 +576,6 @@ std::vector hv_download_batch(const std::vector &downloads, })); } for (size_t i = 0; i < futures.size(); ++i) { - while (futures[i].wait_for(std::chrono::milliseconds(50)) != std::future_status::ready) { - if (cancel && cancel->load()) return succeeded; - } succeeded[i] = futures[i].get(); } return succeeded; @@ -560,14 +585,14 @@ std::vector hv_download_batch(const std::vector &downloads, state->bodies.resize(downloads.size()); state->errors.resize(downloads.size()); hv::HttpClient client; - client.setTimeout(30); + client.setTimeout(timeout_seconds); configure_proxy(client); for (size_t i = 0; i < downloads.size(); ++i) { auto request = std::make_shared(); request->method = HTTP_GET; request->url = downloads[i].url; - request->timeout = 30; + request->timeout = timeout_seconds; request->connect_timeout = 10; request->headers["User-Agent"] = "CardputerZero-AppStore/0.1"; request->headers["Cache-Control"] = "no-cache"; @@ -587,9 +612,10 @@ std::vector hv_download_batch(const std::vector &downloads, } } + const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(timeout_seconds); std::unique_lock lock(state->mutex); while (state->pending > 0) { - if (cancel && cancel->load()) return succeeded; + if ((cancel && cancel->load()) || std::chrono::steady_clock::now() >= deadline) return succeeded; state->changed.wait_for(lock, std::chrono::milliseconds(50)); } lock.unlock(); @@ -616,18 +642,22 @@ std::vector hv_download_batch(const std::vector &downloads, json request_json(const std::string &url) { fs::path temp = cache_dir() / ("request-" + sha1_text(url).substr(0, 16) + ".json.tmp"); - const bool curl_transport = env_or("M5APPSTORE_HTTP_TRANSPORT", "") == "curl"; - if (curl_transport) { - curl_download(url, temp); - } else { - auto result = hv_download_batch({{url, temp}}, &g_sync_cancel); - if (result.empty() || !result[0]) throw std::runtime_error("download failed: " + url); - } - json value = read_json(temp, nullptr); std::error_code ec; fs::remove(temp, ec); - if (!value.is_object()) throw std::runtime_error("invalid JSON response: " + url); - return value; + try { + if (g_sync_cancel) throw std::runtime_error("sync cancelled"); + const int timeout = bounded_seconds("M5APPSTORE_CATALOG_TIMEOUT", 15, 30); + auto result = hv_download_batch({{url, temp}}, &g_sync_cancel, timeout); + if (g_sync_cancel) throw std::runtime_error("sync cancelled"); + if (result.empty() || !result[0]) throw std::runtime_error("download failed: " + url); + json value = read_json(temp, nullptr); + fs::remove(temp, ec); + if (!value.is_object()) throw std::runtime_error("invalid JSON response: " + url); + return value; + } catch (...) { + fs::remove(temp, ec); + throw; + } } std::vector string_list(const json &value) @@ -797,7 +827,40 @@ ArtworkTask artwork_task(const std::string ®istry_url, const std::string &ref return {app, screenshot, {media_url, destination}}; } -json sync_registry(const json &source) +bool usable_catalog(const json &catalog) +{ + if (!catalog.is_object() || !catalog.contains("apps") || !catalog["apps"].is_array()) return false; + for (const auto &app : catalog["apps"]) { + if (!app.is_object()) return false; + bool identified = false; + for (const char *key : {"uuid", "share_code", "id", "title"}) { + if (!app.contains(key)) continue; + if (!app[key].is_string()) return false; + identified = identified || !app[key].get().empty(); + } + if (!identified) return false; + } + return true; +} + +json failed_registry(const json &source, const std::string &error) +{ + const std::string url = source.value("url", ""); + json record = read_json(registry_cache(url)); + if (record.is_object() && usable_catalog(record.value("index", json()))) { + record["status"] = "cached"; + } else { + record = {{"index", json::object()}, {"full", json::object()}, {"status", "error"}}; + } + record["name"] = source.value("name", url); + record["url"] = url; + record["error"] = error; + record["last_attempt_at"] = now_text(); + write_json(registry_cache(url), record); + return record; +} + +json sync_registry(const json &source, const json &index) { std::string url = source.value("url", ""); json record = {{"name", source.value("name", url)}, {"url", url}, {"status", "ok"}, @@ -805,13 +868,15 @@ json sync_registry(const json &source) {"icons", json::object()}, {"screenshots", json::object()}}; try { if (g_sync_cancel) throw std::runtime_error("sync cancelled"); - update_status(true, url, "Downloading registry index", 5, "registry"); - json index = request_json(url + (url.find('?') == std::string::npos ? "?" : "&") + - "_cz_appstore_ts=" + std::to_string(std::time(nullptr))); record["index"] = index; std::string full_url = full_registry_url(url); - try { record["full"] = full_url == url ? index : request_json(full_url); } - catch (...) { record["full"] = json::object(); } + try { + json full = full_url == url ? index : request_json(full_url); + if (!usable_catalog(full)) throw std::runtime_error("invalid full catalog"); + record["full"] = std::move(full); + // Exercise the same merge/sort rules before retaining optional metadata. + merge_apps({record}); + } catch (...) { record["full"] = json::object(); } json apps = record["full"].value("apps", json::array()); if (apps.empty()) apps = index.value("apps", json::array()); @@ -820,8 +885,11 @@ json sync_registry(const json &source) if (g_sync_cancel) throw std::runtime_error("sync cancelled"); const json &app = apps[i]; if (!app.is_object() || app_key(app).empty()) continue; - json assets = app.value("assets", json::object()); - std::string icon = app.value("icon", assets.value("icon", "")); + const json assets = app.contains("assets") && app["assets"].is_object() + ? app["assets"] : json::object(); + std::string icon; + if (app.contains("icon") && app["icon"].is_string()) icon = app["icon"].get(); + else if (assets.contains("icon") && assets["icon"].is_string()) icon = assets["icon"].get(); if (!icon.empty()) { ArtworkTask task = artwork_task(url, icon, app_key(app), false); if (fs::exists(task.download.destination) && fs::file_size(task.download.destination) > 0) @@ -839,16 +907,7 @@ json sync_registry(const json &source) std::vector downloads; for (size_t i = begin; i < end; ++i) downloads.push_back(pending_artwork[i].download); const auto results = hv_download_batch(downloads, &g_sync_cancel); - const bool batch_failed = std::find(results.begin(), results.end(), false) != results.end(); - if (batch_failed) { - if (g_sync_cancel) throw std::runtime_error("sync cancelled"); - try { - request_json(url + (url.find('?') == std::string::npos ? "?" : "&") + - "_cz_appstore_probe=" + std::to_string(std::time(nullptr))); - } catch (...) { - throw std::runtime_error("network lost while caching app artwork"); - } - } + if (g_sync_cancel) throw std::runtime_error("sync cancelled"); for (size_t offset = 0; offset < results.size(); ++offset) { if (!results[offset]) continue; const ArtworkTask &task = pending_artwork[begin + offset]; @@ -857,16 +916,11 @@ json sync_registry(const json &source) } write_json(registry_cache(url), record); } catch (const std::exception &error) { - json cached = read_json(registry_cache(url)); - if (cached.is_object() && cached.contains("index")) { - record = cached; - record["status"] = "cached"; - record["error"] = error.what(); - } else { - record["status"] = "error"; - record["error"] = error.what(); - record["last_attempt_at"] = now_text(); - } + if (g_sync_cancel) return failed_registry(source, "sync cancelled"); + // Catalog retrieval, not optional metadata/artwork, determines source availability. + record["index"] = index; + record["full"] = json::object(); + record["error"] = error.what(); write_json(registry_cache(url), record); } return record; @@ -874,34 +928,64 @@ json sync_registry(const json &source) std::vector sync_all() { + RegistryLock sync_lock("registry-sync.lock", true); g_sync_cancel = false; update_status(true, "", "Loading registry configuration", 0, "config"); - json config = load_config(); - if (config.value("region", "auto") == "auto") { - auto country = capture({"curl", "-fsSL", "--max-time", "5", "https://ipinfo.io/country"}, 128); - std::string code = country.second; - while (!code.empty() && std::isspace(static_cast(code.back()))) code.pop_back(); - std::string active = code == "CN" ? "CN" : "default"; - if (active != config.value("active_region", "default")) { - config["active_region"] = active; - select_region(config, "auto"); - save_config(config); + json config; + uint64_t revision; + { + RegistryLock lock("registry-config.lock"); + config = load_config(); + revision = config_revision(); + } + const json original_config = config; + const std::string mode = config.value("region", "auto"); + const std::vector candidates = mode == "auto" + ? std::vector{"default", "CN"} : std::vector{mode}; + json catalog; + json source; + std::string errors; + for (const auto ®ion : candidates) { + if (g_sync_cancel) break; + const json candidate = builtin_registry(region); + const std::string url = candidate.value("url", ""); + update_status(true, url, "Downloading registry catalog", 5, "registry"); + try { + json fetched = request_json(url + "?_cz_appstore_ts=" + std::to_string(std::time(nullptr))); + if (!usable_catalog(fetched)) throw std::runtime_error("invalid catalog: " + url); + catalog = std::move(fetched); + source = candidate; + config["active_region"] = region; + config = normalize_config(config); + break; + } catch (const std::exception &error) { + if (!errors.empty()) errors += "; "; + errors += error.what(); } } - std::vector records; - size_t enabled = 0; - for (const auto &item : config["registries"]) if (item.value("enabled", true)) ++enabled; - size_t index = 0; - for (const auto &item : config["registries"]) { - if (!item.value("enabled", true)) continue; - update_status(true, item.value("url", ""), "Syncing registry", static_cast(100 * index / std::max(1, enabled)), "registry"); - records.push_back(sync_registry(item)); - ++index; - if (g_sync_cancel) break; + json record; + if (source.is_object() && !g_sync_cancel) record = sync_registry(source, catalog); + { + RegistryLock lock("registry-config.lock"); + if (config_revision() != revision || load_config() != original_config) { + update_status(false, "", "Sync superseded by registry selection", -1, "cancelled"); + throw std::runtime_error("sync superseded by registry selection"); + } + if (g_sync_cancel || !record.is_object()) { + // Cancellation must not abandon the old source for an incomplete replacement. + record = failed_registry(original_config["registries"][0], + g_sync_cancel ? "sync cancelled" : "No registry could be reached: " + errors); + } else if (record.value("status", "") == "ok") { + // Publish the source only after its usable catalog has been persisted. + save_config(config); + } } - update_status(false, "", g_sync_cancel ? "Sync cancelled" : "Catalog synced", - g_sync_cancel ? -1 : 100, g_sync_cancel ? "cancelled" : "complete"); - return records; + record["cancelled"] = g_sync_cancel.load(); + const bool ok = record.value("status", "") == "ok" && !g_sync_cancel; + update_status(false, "", g_sync_cancel ? "Sync cancelled" : + (ok ? "Catalog synced" : "No registry could be reached"), + ok ? 100 : -1, g_sync_cancel ? "cancelled" : (ok ? "complete" : "error")); + return {record}; } std::vector load_records(bool sync_if_empty) @@ -1172,14 +1256,8 @@ std::string regions_output() void select_region(json &config, const std::string ®ion) { - std::string selected = region == "CN" ? "CN" : (region == "auto" ? "auto" : "default"); - std::string active = selected == "auto" ? config.value("active_region", "default") : selected; - if (active != "CN") active = "default"; - json custom = json::array(); - for (const auto &item : config["registries"]) if (!item.value("builtin", false)) custom.push_back(item); - config = {{"region", selected}, {"active_region", active}, {"registries", json::array()}}; - config["registries"].push_back(builtin_registry(active)); - for (const auto &item : custom) config["registries"].push_back(item); + config["region"] = region; + config = normalize_config(config); } std::string config_output(const json &config) @@ -2197,55 +2275,35 @@ std::string dispatch(const std::vector &args, int &rc) if (command == "--sync") { auto records = sync_all(); size_t ok = 0, cached = 0, failed = 0, apps = 0; for (const auto &record : records) { std::string status = record.value("status", ""); if (status == "ok") ++ok; else if (status == "cached") ++cached; else ++failed; apps += record.value("index", json::object()).value("apps", json::array()).size(); } - const std::string message = g_sync_cancel ? "Sync cancelled" : + const bool cancelled = !records.empty() && records[0].value("cancelled", false); + const std::string message = cancelled ? "Sync cancelled" : (ok == 0 ? "No registry could be reached" : "Catalog synced"); emit(out, "SYNC", ok, cached, failed, apps, message); - if (g_sync_cancel) rc = 1; + if (cancelled || ok == 0) rc = 1; return out.str(); } if (command == "--registry-config") return config_output(load_config()); if (command == "--replace-registry-config" && args.size() >= 2) { try { - json incoming = json::parse(args[1]); json config = load_config(); - config["region"] = incoming.value("region", "auto"); config["active_region"] = incoming.value("active_region", "default"); - config["registries"] = incoming.value("registries", json::array()); select_region(config, config.value("region", "auto")); + json incoming = json::parse(args[1]); + if (!incoming.is_object()) throw std::runtime_error("expected an object"); + json config = normalize_config(incoming); + RegistryLock lock("registry-config.lock"); save_config(config); return config_output(config); } catch (const std::exception &error) { emit(out, "ERROR", std::string("invalid registry config: ") + error.what()); rc = 1; return out.str(); } } if (command == "--set-region" && args.size() >= 2) { if (args[1] != "auto" && args[1] != "default" && args[1] != "CN") { emit(out, "ERROR", "unknown region", args[1]); rc = 1; return out.str(); } + RegistryLock lock("registry-config.lock"); json config = load_config(); select_region(config, args[1]); save_config(config); emit(out, "REGION", config.value("region", "auto"), args[1] == "CN" ? "China" : (args[1] == "auto" ? "Auto" : "Default"), config.value("active_region", "default") == "CN" ? kCnUrl : kDefaultUrl, config.value("active_region", "default")); return out.str(); } - if (command == "--add-registry" && args.size() >= 2) { - json config = load_config(); std::string url = normalize_url(args[1]); std::string name = url; - for (size_t i = 2; i + 1 < args.size(); ++i) if (args[i] == "--registry-name") name = args[i + 1]; - if (url == kDefaultUrl || url == kCnUrl) { emit(out, "ERROR", "use region selection for built-in registries", url); rc = 1; return out.str(); } - for (const auto &item : config["registries"]) if (item.value("url", "") == url) { emit(out, "ERROR", "registry already exists", url); rc = 1; return out.str(); } - json record = sync_registry({{"name", name}, {"url", url}, {"enabled", true}}); - if (record.value("status", "") == "error") { emit(out, "ERROR", record.value("error", "registry unavailable"), url); rc = 1; return out.str(); } - config["registries"].push_back({{"name", name}, {"url", url}, {"enabled", true}}); save_config(config); - emit(out, "REGISTRY", "ADDED", url, record.value("status", ""), record.value("index", json::object()).value("apps", json::array()).size(), name); return out.str(); - } - if ((command == "--remove-registry" || command == "--enable-registry" || command == "--disable-registry") && args.size() >= 2) { - json config = load_config(); std::string url = normalize_url(args[1]); bool found = false; json entries = json::array(); - for (auto item : config["registries"]) { - if (item.value("url", "") == url) { found = true; if (item.value("builtin", false)) { emit(out, "ERROR", "registry is managed by region selection", url); rc = 1; return out.str(); } - if (command == "--remove-registry") continue; item["enabled"] = command == "--enable-registry"; } - entries.push_back(item); - } - if (!found) { emit(out, "ERROR", "registry not found", url); rc = 1; return out.str(); } - config["registries"] = entries; save_config(config); emit(out, "REGISTRY", command == "--remove-registry" ? "REMOVED" : (command == "--enable-registry" ? "ENABLED" : "DISABLED"), url); return out.str(); - } - if (command == "--edit-registry" && args.size() >= 3) { - std::string old_url = normalize_url(args[1]), new_url = normalize_url(args[2]), name = new_url; json config = load_config(); bool found = false; - for (size_t i = 3; i + 1 < args.size(); ++i) if (args[i] == "--registry-name") name = args[i + 1]; - json record = sync_registry({{"name", name}, {"url", new_url}, {"enabled", true}}); - if (record.value("status", "") == "error") { emit(out, "ERROR", record.value("error", "registry unavailable"), new_url); rc = 1; return out.str(); } - for (auto &item : config["registries"]) if (item.value("url", "") == old_url && !item.value("builtin", false)) { item["url"] = new_url; item["name"] = name; found = true; } - if (!found) { emit(out, "ERROR", "registry not found", old_url); rc = 1; return out.str(); } - save_config(config); emit(out, "REGISTRY", "UPDATED", old_url, new_url, record.value("status", ""), record.value("index", json::object()).value("apps", json::array()).size(), name); return out.str(); + if (command == "--add-registry" || command == "--edit-registry" || + command == "--remove-registry" || command == "--enable-registry" || command == "--disable-registry") { + emit(out, "ERROR", "custom registries are not supported; use region selection"); + rc = 1; + return out.str(); } if (command == "--plan" && args.size() >= 2) return plan_output(args[1], rc); if (command == "--repair-package-transaction" && args.size() >= 2) @@ -2261,6 +2319,14 @@ std::string dispatch(const std::vector &args, int &rc) } // namespace +#ifdef APPSTORE_NATIVE_IN_PROCESS_TEST +std::string native_test_sync_registry(const std::string &url, const std::string &index) +{ + g_sync_cancel = false; + return sync_registry({{"url", url}, {"name", "Test catalog"}}, json::parse(index)).dump(); +} +#endif + void native_request_sync_cancel() { g_sync_cancel = true; } void native_request_package_cancel() { g_package_cancel = true; } diff --git a/tests/test_native_backend.cpp b/tests/test_native_backend.cpp index 192b208..f3d1d89 100644 --- a/tests/test_native_backend.cpp +++ b/tests/test_native_backend.cpp @@ -5,6 +5,12 @@ */ #include "json.hpp" +#ifdef APPSTORE_NATIVE_IN_PROCESS_TEST +#include "appstore_native.hpp" +#include +namespace appstore { std::string native_test_sync_registry(const std::string &, const std::string &); } +#endif +#include #include #include #include @@ -89,15 +95,32 @@ static void fixture() { text(root/"bin/curl", R"(#!/bin/sh set -eu; out=; url= while [ $# -gt 0 ]; do case "$1" in -o) out=$2;shift 2;; -A|--connect-timeout|--max-time|-C) shift 2;; -*) shift;; *) url=$1;shift;; esac; done +printf '%s\n' "$url" >> "$M5APPSTORE_CACHE_DIR/network.log" [ "${FAKE_CURL_FAIL:-0}" = 0 ] || exit 22 +case "$url" in + https://cardputerzero.github.io/generated/registry.json*) outcome=${FAKE_DEFAULT_OUTCOME:-ok};; + https://cardputer-zero-repo.oss-cn-shenzhen.aliyuncs.com/packages/cn/registry.json*) outcome=${FAKE_CN_OUTCOME:-ok};; + *) outcome=ok;; +esac +case "$outcome" in + fail) exit 7;; + invalid) printf '{invalid' > "$out"; exit 0;; + bad) printf '{"error":"not a catalog"}' > "$out"; exit 0;; + wrong-apps) printf '{"apps":{}}' > "$out"; exit 0;; + bad-app) printf '{"apps":[{"uuid":42}]}' > "$out"; exit 0;; + empty) printf '{"apps":[]}' > "$out"; exit 0;; + slow) sleep 4;; +esac [ -z "${FAKE_CURL_SLEEP:-}" ] || sleep "$FAKE_CURL_SLEEP" marker="$M5APPSTORE_CACHE_DIR/network-drop-marker" if [ "${FAKE_DROP_DURING_ASSETS:-0}" = 1 ] && [ -e "$marker" ]; then exit 7; fi case "$url" in - *ipinfo.io*) echo "${FAKE_COUNTRY:-US}";; + *ipinfo.io*) exit 99;; *demo.deb*) cp "$FAKE_DEB" "$out";; - *.png*) [ "${FAKE_ASSET_FAIL:-0}" = 0 ] || exit 22; printf 'fake icon' > "$out";; - *) cp "$FAKE_REGISTRY" "$out"; if [ "${FAKE_DROP_DURING_ASSETS:-0}" = 1 ]; then touch "$marker"; fi;; + *.png*) [ -z "${FAKE_ASSET_SLEEP:-}" ] || sleep "$FAKE_ASSET_SLEEP" + [ "${FAKE_ASSET_FAIL:-0}" = 0 ] || exit 22; printf 'fake icon' > "$out";; + *) case "$url" in *oss-cn-shenzhen*) cp "${FAKE_CN_REGISTRY:-$FAKE_REGISTRY}" "$out";; *) cp "$FAKE_REGISTRY" "$out";; esac + if [ "${FAKE_DROP_DURING_ASSETS:-0}" = 1 ]; then touch "$marker"; fi;; esac )",0755); text(root/"bin/dpkg-query", R"(#!/bin/sh @@ -127,7 +150,7 @@ static void registry_cases() { CHECK(call({"--clear-registry-cache"}).rc==0); setenv("FAKE_DROP_DURING_ASSETS","1",1); Result dropped=call({"--sync"}); - CHECK(has(dropped,"SYNC\t0\t0\t1\t2\tNo registry could be reached")); + CHECK(has(dropped,"SYNC\t1\t0\t0\t2\tCatalog synced")); unsetenv("FAKE_DROP_DURING_ASSETS"); fs::remove(root/"cache/network-drop-marker"); CHECK(has(call({"--sync"}),"SYNC\t1\t0\t0\t2")); @@ -157,18 +180,233 @@ static void registry_cases() { CHECK(call({"--sync"}).rc==0); CHECK(has(call({"--registries"}),"\tok\t2\t")); setenv("FAKE_CURL_FAIL","1",1); CHECK(has(call({"--sync"}),"SYNC\t0\t1\t0\t2")); CHECK(has(call({"--summary"}),"WARN\tRegistry offline")); unsetenv("FAKE_CURL_FAIL"); - CHECK(call({"--add-registry","example.invalid/registry.json","--registry-name","Extra"}).rc==0); - CHECK(call({"--add-registry","example.invalid/registry.json"}).rc!=0); CHECK(call({"--disable-registry","https://example.invalid/registry.json"}).rc==0); - CHECK(has(call({"--registry-config"}),"Extra\thttps://example.invalid/registry.json\t0")); - CHECK(call({"--enable-registry","https://example.invalid/registry.json"}).rc==0); - CHECK(call({"--edit-registry","https://example.invalid/registry.json","https://new.invalid/registry.json","--registry-name","New"}).rc==0); - CHECK(call({"--remove-registry","https://new.invalid/registry.json"}).rc==0); CHECK(call({"--remove-registry","https://missing.invalid/x"}).rc!=0); + const json original_config = load(root/"state/registries.json"); + text(root/"cache/network.log", ""); + for (const char *command : {"--add-registry", "--edit-registry", "--remove-registry", "--enable-registry", "--disable-registry"}) { + Result rejected = call({command,"https://custom.invalid/registry.json","https://new.invalid/registry.json"}); + CHECK(rejected.rc!=0 && has(rejected,"custom registries are not supported")); + CHECK(load(root/"state/registries.json")==original_config); + } + CHECK(fs::file_size(root/"cache/network.log")==0); CHECK(call({"--remove-registry","https://cardputerzero.github.io/generated/registry.json"}).rc!=0); json cfg={{"region","default"},{"active_region","default"},{"registries",{{{"name","Custom"},{"url","https://custom.invalid/registry.json"},{"enabled",false}}}}}; - CHECK(has(call({"--replace-registry-config",cfg.dump()}),"CONFIG_REG\t1\tCustom")); CHECK(call({"--replace-registry-config","{"}).rc!=0); + Result imported = call({"--replace-registry-config",cfg.dump()}); + CHECK(imported.rc==0 && has(imported,"CONFIG\tdefault\tdefault\t1") && !has(imported,"Custom")); + CHECK(call({"--replace-registry-config","{"}).rc!=0); fs::path c=root/"state/registries.json"; chmod(c.c_str(),0640); CHECK(call({"--set-region","CN"}).rc==0); struct stat st{}; CHECK(!stat(c.c_str(),&st)&&(st.st_mode&0777)==0640); CHECK(call({"--set-region","default"}).rc==0); CHECK(call({"--sync"}).rc==0); } +static std::vector catalog_requests() { + std::ifstream input(root/"cache/network.log"); + std::vector requests; + std::string line; + while (std::getline(input, line)) { + CHECK(line.find("ipinfo") == std::string::npos); + if (line.find("registry.json") != std::string::npos) requests.push_back(line.substr(0, line.find('?'))); + } + return requests; +} +static void source_selection_cases() { + const std::string github="https://cardputerzero.github.io/generated/registry.json"; + const std::string oss="https://cardputer-zero-repo.oss-cn-shenzhen.aliyuncs.com/packages/cn/registry.json"; + auto sync = [&]() { text(root/"cache/network.log", ""); return call({"--sync"}); }; + auto selected = [&](const std::string &mode, const std::string &active) { + Result result=call({"--registry-config"}); + CHECK(result.rc==0 && has(result,"CONFIG\t"+mode+"\t"+active+"\t1\n")); + CHECK(has(result,"CONFIG_REG\t0\tCardputerZero Hub")); + CHECK(has(result,(active=="CN"?oss:github)+"\t1\t1\t"+active)); + CHECK(!has(result,"CONFIG_REG\t1")); + }; + for (const std::string mode : {"auto", "default", "CN"}) { + for (const json &active : {json("CN"), json("default"), json("moon"), json(12), json(nullptr)}) { + json legacy={{"region",mode},{"active_region",active}, + {"registries",json::array({{{"url",github},{"enabled",false},{"name","Spoofed"}}, + {{"url",oss},{"builtin",true}},{{"url","https://custom.invalid/x"},{"enabled",true}},42})}}; + const std::string expected=mode=="auto" ? (active=="CN"?"CN":"default") : mode; + save(root/"state/registries.json",legacy); + selected(mode,expected); + CHECK(call({"--replace-registry-config",legacy.dump()}).rc==0); + selected(mode,expected); + json normalized=load(root/"state/registries.json"); + CHECK(normalized["registries"].size()==1 && normalized["registries"][0]["enabled"]==true); + } + } + for (const json &mode : {json("moon"),json(42),json(nullptr)}) { + json legacy={{"region",mode},{"active_region","moon"},{"registries",nullptr}}; + save(root/"state/registries.json",legacy); selected("auto","default"); + CHECK(call({"--replace-registry-config",legacy.dump()}).rc==0); selected("auto","default"); + } + CHECK(call({"--replace-registry-config","[]"}).rc!=0); + json cn_app=app("cn-only","approved"); cn_app["icon"]=""; + save(root/"cn-registry.json",{{"apps",{cn_app}}}); + setenv("FAKE_CN_REGISTRY",(root/"cn-registry.json").c_str(),1); + CHECK(call({"--set-region","auto"}).rc==0); + CHECK(has(sync(),"SYNC\t1\t0\t0\t2")); + CHECK(catalog_requests()==std::vector{github}); selected("auto","default"); + + setenv("FAKE_DEFAULT_OUTCOME","fail",1); + CHECK(has(sync(),"SYNC\t1\t0\t0\t1")); + CHECK((catalog_requests()==std::vector{github,oss})); selected("auto","CN"); + Result summary=call({"--summary"}); CHECK(has(summary,"APP\tcn-only") && !has(summary,"APP\tapp-id")); + setenv("FAKE_CN_OUTCOME","fail",1); + Result offline=sync(); CHECK(offline.rc!=0 && has(offline,"SYNC\t0\t1\t0\t1\tNo registry could be reached")); + CHECK((catalog_requests()==std::vector{github,oss})); selected("auto","CN"); + CHECK(has(call({"--summary"}),"WARN\tRegistry offline")); + CHECK(call({"--clear-registry-cache"}).rc==0); + CHECK(has(sync(),"SYNC\t0\t0\t1\t0\tNo registry could be reached")); + CHECK(has(sync(),"SYNC\t0\t0\t1\t0\tNo registry could be reached")); + unsetenv("FAKE_CN_OUTCOME"); + for (const char *bad : {"invalid", "bad", "wrong-apps", "bad-app"}) { + setenv("FAKE_DEFAULT_OUTCOME",bad,1); + CHECK(has(sync(),"SYNC\t1\t0\t0\t1")); + CHECK((catalog_requests()==std::vector{github,oss})); selected("auto","CN"); + } + setenv("FAKE_DEFAULT_OUTCOME","empty",1); + CHECK(has(sync(),"SYNC\t1\t0\t0\t0")); selected("auto","default"); + CHECK(catalog_requests()==std::vector{github}); + unsetenv("FAKE_DEFAULT_OUTCOME"); + CHECK(has(sync(),"SYNC\t1\t0\t0\t2")); selected("auto","default"); + CHECK(catalog_requests()==std::vector{github}); + const json original_catalog=load(root/"registry.json"); + json malformed_artwork=original_catalog; + malformed_artwork["apps"][0]["assets"]=42; + malformed_artwork["apps"][0]["icon"]=false; + save(root/"registry.json",malformed_artwork); + CHECK(has(sync(),"SYNC\t1\t0\t0\t2")); selected("auto","default"); + CHECK(catalog_requests()==std::vector{github}); + save(root/"registry.json",original_catalog); + + CHECK(call({"--set-region","default"}).rc==0); + setenv("FAKE_DEFAULT_OUTCOME","fail",1); + CHECK(has(sync(),"SYNC\t0\t1\t0\t2")); + CHECK(catalog_requests()==std::vector{github}); selected("default","default"); + CHECK(call({"--set-region","CN"}).rc==0); + CHECK(has(sync(),"SYNC\t1\t0\t0\t1")); + CHECK(catalog_requests()==std::vector{oss}); selected("CN","CN"); + unsetenv("FAKE_DEFAULT_OUTCOME"); setenv("FAKE_CN_OUTCOME","bad",1); + CHECK(has(sync(),"SYNC\t0\t1\t0\t1")); + CHECK(catalog_requests()==std::vector{oss}); selected("CN","CN"); + unsetenv("FAKE_CN_OUTCOME"); + + CHECK(call({"--set-region","auto"}).rc==0); + setenv("FAKE_DEFAULT_OUTCOME","slow",1); setenv("M5APPSTORE_CATALOG_TIMEOUT","1",1); + const auto started=std::chrono::steady_clock::now(); + CHECK(has(sync(),"SYNC\t1\t0\t0\t1")); + CHECK(std::chrono::steady_clock::now()-started < std::chrono::seconds(4)); + CHECK((catalog_requests()==std::vector{github,oss})); selected("auto","CN"); + unsetenv("FAKE_DEFAULT_OUTCOME"); unsetenv("M5APPSTORE_CATALOG_TIMEOUT"); + CHECK(call({"--clear-registry-cache"}).rc==0); + setenv("FAKE_DROP_DURING_ASSETS","1",1); + CHECK(has(sync(),"SYNC\t1\t0\t0\t2")); + CHECK(catalog_requests()==std::vector{github}); selected("auto","default"); + unsetenv("FAKE_DROP_DURING_ASSETS"); fs::remove(root/"cache/network-drop-marker"); + unsetenv("FAKE_CN_REGISTRY"); + CHECK(call({"--set-region","default"}).rc==0); CHECK(has(sync(),"SYNC\t1\t0\t0\t2")); +} +#ifdef APPSTORE_NATIVE_IN_PROCESS_TEST +static void wait_for_request(const std::string &needle) { + const auto deadline=std::chrono::steady_clock::now()+std::chrono::seconds(2); + while (std::chrono::steady_clock::now()0); + const auto cancelled=std::chrono::steady_clock::now(); + appstore::native_request_sync_cancel(); + sync.join(); + CHECK(std::chrono::steady_clock::now()-cancelled < std::chrono::seconds(2)); + CHECK(result.rc!=0 && has(result,"Sync cancelled")); + CHECK(catalog_requests().size()==1); + CHECK(appstore::native_backend_capture({"--sync-status"},nullptr).find("cancelled")!=std::string::npos); + unsetenv("FAKE_DEFAULT_OUTCOME"); + int rc=1; + CHECK(appstore::native_backend_capture({"--sync"},&rc).find("SYNC\t1\t0\t0\t2")!=std::string::npos && rc==0); + CHECK(call({"--set-region","default"}).rc==0); +} +#endif static void plan_cases() { Result p=call({"--plan","demo"}); CHECK(p.rc==0&&has(p,"PLAN\tapp-id\tDemo Local\t1.2.0\t42K")); CHECK(has(p,"lib-one,lib-two")); CHECK(call({"--plan","blocked"}).rc!=0); CHECK(call({"--plan","missing"}).rc!=0); @@ -266,5 +504,11 @@ static void package_cases() { } int main(int argc,char **argv) { CHECK(argc==2); binary=fs::absolute(argv[1]); char t[]="/tmp/appstore-cpp-parity.XXXXXX"; char *p=mkdtemp(t);CHECK(p);root=p; - fixture();registry_cases();plan_cases();package_cases();fs::remove_all(root);std::cout<<"native C++ parity tests passed: "< Date: Thu, 22 Oct 2026 18:55:41 +0300 Subject: [PATCH 11/19] refactor(store): restore the original app list and limit Settings to three servers --- main/interface/appstore_client.hpp | 2 +- main/interface/shared_registry_store.cpp | 20 +- main/interface/shared_registry_store.hpp | 22 ++ main/ui/appstore.cpp | 25 +-- main/ui/appstore_app.hpp | 1 - main/ui/appstore_image_renderer.cpp | 6 +- main/ui/appstore_input_controller.cpp | 81 +------- main/ui/appstore_input_controller.hpp | 4 +- main/ui/appstore_pages.cpp | 216 ++++---------------- main/ui/appstore_pages.hpp | 27 --- main/ui/appstore_presenter.cpp | 130 ++---------- main/ui/appstore_shortcut_bar.cpp | 51 +---- main/ui/appstore_shortcut_bar.hpp | 4 +- main/ui/appstore_task_coordinator.hpp | 17 -- main/ui/appstore_view_model_factory.cpp | 23 +-- main/ui/appstore_view_model_factory.hpp | 1 - main/ui/appstore_view_models.hpp | 19 -- main/ui/registry_controller.cpp | 135 +----------- main/ui/registry_controller.hpp | 7 - main/ui/registry_persistence_service.cpp | 3 + main/ui/registry_ui_state.cpp | 179 +++------------- main/ui/registry_ui_state.hpp | 55 +---- main/ui/sync_controller.cpp | 10 +- main/ui/sync_controller.hpp | 2 +- tests/test_appstore_input_controller.cpp | 89 ++------ tests/test_appstore_view_model_factory.cpp | 19 +- tests/test_registry_controller.cpp | 29 +-- tests/test_registry_persistence_service.cpp | 26 ++- tests/test_registry_ui_state.cpp | 76 +++---- tests/test_shared_registry_store.cpp | 54 +++-- tests/test_sync_controller.cpp | 5 +- 31 files changed, 313 insertions(+), 1025 deletions(-) diff --git a/main/interface/appstore_client.hpp b/main/interface/appstore_client.hpp index 2e8ae6d..eeb49a9 100644 --- a/main/interface/appstore_client.hpp +++ b/main/interface/appstore_client.hpp @@ -44,7 +44,7 @@ struct StoreApp { uint32_t permissions = 0; }; -// Order matches the selection screen icon row. +// Order matches the app detail permission icon row. enum AppPermission : uint32_t { kPermissionNetwork = 1u << 0, kPermissionMicrophone = 1u << 1, diff --git a/main/interface/shared_registry_store.cpp b/main/interface/shared_registry_store.cpp index 0637449..1568f3b 100644 --- a/main/interface/shared_registry_store.cpp +++ b/main/interface/shared_registry_store.cpp @@ -69,29 +69,23 @@ bool SharedRegistryStore::load(RegistryConfig &config) const { const std::string count_text = get_string_(key("count"), ""); if (count_text.empty()) return false; - int count = std::min(std::atoi(count_text.c_str()), max_entries_); - if (count <= 0) return false; - config = RegistryConfig{}; config.region = get_string_(key("region"), "auto"); config.active_region = get_string_(key("active_region"), "default"); - for (int index = 0; index < count; ++index) { - RegistryEntry entry; - if (unpack_entry(get_string_(key(std::to_string(index) + ".entry"), ""), entry)) - config.entries.push_back(std::move(entry)); - } - return !config.entries.empty(); + config = normalize(std::move(config)); + return true; } bool SharedRegistryStore::save(const RegistryConfig &config) const { - const int count = std::min(static_cast(config.entries.size()), max_entries_); - set_string_(key("region"), config.region.empty() ? "auto" : config.region); - set_string_(key("active_region"), config.active_region.empty() ? "default" : config.active_region); + const RegistryConfig canonical = normalize(config); + const int count = 1; + set_string_(key("region"), canonical.region); + set_string_(key("active_region"), canonical.active_region); set_string_(key("count"), std::to_string(count)); for (int index = 0; index < max_entries_; ++index) set_string_(key(std::to_string(index) + ".entry"), - index < count ? pack_entry(config.entries[index]) : ""); + index < count ? pack_entry(canonical.entries[index]) : ""); save_(); return true; } diff --git a/main/interface/shared_registry_store.hpp b/main/interface/shared_registry_store.hpp index 60849e6..57a2b59 100644 --- a/main/interface/shared_registry_store.hpp +++ b/main/interface/shared_registry_store.hpp @@ -26,6 +26,28 @@ class SharedRegistryStore bool load(RegistryConfig &config) const; bool save(const RegistryConfig &config) const; + static constexpr const char *kDefaultRegistryUrl = + "https://cardputerzero.github.io/generated/registry.json"; + static constexpr const char *kChinaRegistryUrl = + "https://cardputer-zero-repo.oss-cn-shenzhen.aliyuncs.com/packages/cn/registry.json"; + + static RegistryConfig normalize(RegistryConfig config) + { + if (config.region != "auto" && config.region != "default" && config.region != "CN") + config.region = "auto"; + if (config.region != "auto") config.active_region = config.region; + else if (config.active_region != "default" && config.active_region != "CN") + config.active_region = "default"; + RegistryEntry entry; + entry.url = config.active_region == "CN" ? kChinaRegistryUrl : kDefaultRegistryUrl; + entry.name = config.active_region == "CN" ? "CardputerZero Hub CN" : "CardputerZero Hub"; + entry.region = config.active_region; + entry.enabled = true; + entry.builtin = true; + config.entries = {entry}; + return config; + } + static std::string pack_entry(const RegistryEntry &entry); static bool unpack_entry(const std::string &packed, RegistryEntry &entry); diff --git a/main/ui/appstore.cpp b/main/ui/appstore.cpp index ccb263f..16c7ebb 100644 --- a/main/ui/appstore.cpp +++ b/main/ui/appstore.cpp @@ -66,7 +66,6 @@ const char *screen_name(Screen screen) case Screen::Progress: return "Progress"; case Screen::ErrorDialog: return "ErrorDialog"; case Screen::Registry: return "Registry"; - case Screen::RegistryEdit: return "RegistryEdit"; case Screen::ShareCode: return "ShareCode"; case Screen::Search: return "Search"; case Screen::Screenshots: return "Screenshots"; @@ -208,7 +207,7 @@ void AppStoreApp::draw_system_bar() if (sync_component) sync_component->set_sync_active(sync_active, lv_tick_get()); } const uint32_t elapsed = lv_tick_elaps(start); - if (elapsed >= 15 || g_runtime.session.screen == Screen::Registry || g_runtime.session.screen == Screen::RegistryEdit) { + if (elapsed >= 15 || g_runtime.session.screen == Screen::Registry) { app_tracef("draw_system_bar elapsed=%ums status=%ums screen=%s", elapsed, status_ms, screen_name(g_runtime.session.screen)); } @@ -231,7 +230,7 @@ void AppStoreApp::refresh() const bool screenshots = poll_screenshots(); const uint32_t elapsed = lv_tick_elaps(start); if (elapsed >= 20 || result.any() || screenshots || - g_runtime.session.screen == Screen::Registry || g_runtime.session.screen == Screen::RegistryEdit) { + g_runtime.session.screen == Screen::Registry) { app_tracef("refresh_timer elapsed=%ums screen=%s region_debounce=%d registry_refresh=%d registry_op=%d plan=%d summary=%d status_timeout=%d top_status=%d screenshots=%d", elapsed, screen_name(g_runtime.session.screen), result.region_debounce ? 1 : 0, result.registry_refresh ? 1 : 0, result.registry_operation ? 1 : 0, @@ -320,9 +319,6 @@ void AppStoreApp::navigate_back() g_runtime.session.screen = g_runtime.session.sync.startup_active ? Screen::StartupSync : Screen::Home; break; - case Screen::RegistryEdit: - g_runtime.session.screen = Screen::Registry; - break; case Screen::ShareCode: g_runtime.session.screen = Screen::Home; break; @@ -342,18 +338,13 @@ void AppStoreApp::poll_sync() void AppStoreApp::open_registry_screen() { - app_tracef("open_registry_screen begin from=%s entries=%zu loading=%d refresh_running=%d", - screen_name(g_runtime.session.screen), g_runtime.session.registry.entries().size(), g_runtime.session.registry_loading ? 1 : 0, + app_tracef("open_registry_screen begin from=%s loading=%d refresh_running=%d", + screen_name(g_runtime.session.screen), g_runtime.session.registry_loading ? 1 : 0, runtime_.task_service.registry_refresh_running() ? 1 : 0); registry_actions_.open(); app_tracef("open_registry_screen end screen=%s", screen_name(g_runtime.session.screen)); } -void AppStoreApp::open_registry_add_screen() -{ - registry_actions_.open_add(); -} - void AppStoreApp::execute_detail_confirmation() { if (!detail_actions_.execute_confirmation(lv_tick_get())) return; @@ -437,7 +428,7 @@ AppStoreApp::AppStoreApp() [this]() { runtime_.registry_persistence.save_backend(); }, [this]() { request_coordinator_.request_summary(); }, [this](bool refresh) { sync_actions_.start(refresh, lv_tick_get()); }, - []() { stop_backend_service(); }}), + []() { cancel_sync(); }}), catalog_actions_(runtime_.session, share_code_, [this]() { request_coordinator_.request_summary(); }), request_coordinator_( @@ -458,14 +449,13 @@ AppStoreApp::AppStoreApp() []() { // The startup screen animates on its own. return g_runtime.session.screen != Screen::Registry && - g_runtime.session.screen != Screen::RegistryEdit && g_runtime.session.screen != Screen::StartupSync; }}), input_controller_( runtime_.session, runtime_.package_jobs.state(), runtime_.exit, share_code_, catalog_actions_, detail_actions_, registry_actions_, sync_actions_, {[this]() { request_quit(); }, [this]() { navigate_back(); }, - [this]() { open_registry_screen(); }, [this]() { open_registry_add_screen(); }, + [this]() { open_registry_screen(); }, [this]() { execute_detail_confirmation(); }, [this]() { repair_package_error(); }, [this]() { render_current_screen(); }, @@ -611,8 +601,7 @@ void AppStoreApp::activate(Screen screen) case Screen::Home: case Screen::ShareCode: case Screen::Search: set_active_page(catalog_page_); break; - case Screen::Registry: - case Screen::RegistryEdit: set_active_page(settings_page_); break; + case Screen::Registry: set_active_page(settings_page_); break; case Screen::Detail: case Screen::Confirm: case Screen::Progress: diff --git a/main/ui/appstore_app.hpp b/main/ui/appstore_app.hpp index 5afb90e..839cb2f 100644 --- a/main/ui/appstore_app.hpp +++ b/main/ui/appstore_app.hpp @@ -67,7 +67,6 @@ class AppStoreApp : public InitializationProgressPage void set_active_page(AppStoreUiPage &page); void navigate_back(); void open_registry_screen(); - void open_registry_add_screen(); void execute_detail_confirmation(); void repair_package_error(); static void frame_ready(lv_event_t *event); diff --git a/main/ui/appstore_image_renderer.cpp b/main/ui/appstore_image_renderer.cpp index 420bcc9..524ce69 100644 --- a/main/ui/appstore_image_renderer.cpp +++ b/main/ui/appstore_image_renderer.cpp @@ -6,7 +6,6 @@ #include "appstore_image_renderer.hpp" -#include "appstore_pages.hpp" #include "appstore_paths.hpp" #include "cp0_lvgl_app.h" @@ -52,8 +51,7 @@ bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app #if LV_USE_LODEPNG && LV_USE_FS_POSIX const std::string path = icon_file_path(app_dir, app); if (path.empty()) return false; - constexpr int x = catalog_home::kIconX, y = catalog_home::kIconY; - constexpr int width = catalog_home::kIconSize, height = catalog_home::kIconSize; + constexpr int x = 39, y = 65, width = 60, height = 60; lv_obj_t *clip = lv_obj_create(root); lv_obj_remove_style_all(clip); lv_obj_set_pos(clip, x, y); @@ -61,7 +59,7 @@ bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app lv_obj_clear_flag(clip, LV_OBJ_FLAG_SCROLLABLE); lv_obj_set_style_bg_opa(clip, LV_OPA_TRANSP, 0); lv_obj_set_style_border_width(clip, 0, 0); - lv_obj_set_style_radius(clip, width / 6, 0); + lv_obj_set_style_radius(clip, 10, 0); lv_obj_set_style_clip_corner(clip, true, 0); lv_obj_set_style_pad_all(clip, 0, 0); lv_obj_t *icon = lv_image_create(clip); diff --git a/main/ui/appstore_input_controller.cpp b/main/ui/appstore_input_controller.cpp index 3d1b2b2..407d267 100644 --- a/main/ui/appstore_input_controller.cpp +++ b/main/ui/appstore_input_controller.cpp @@ -50,16 +50,7 @@ bool AppStoreInputController::matches(const AppStoreKeyEvent &key, char ch, void AppStoreInputController::play_feedback(const AppStoreKeyEvent &key) { - KeySound sound = key_sound(key, appstore_input_context(session_.screen)); - if (session_.screen == Screen::RegistryEdit && sound == KeySound::None) { - const bool fn = (key.mods & KBD_MOD_FN) != 0; - if (fn && (key.code == KEY_Z || key.code == KEY_C || - key.code == KEY_LEFT || key.code == KEY_RIGHT)) - sound = KeySound::Move; - else if (key.ch != 0 || key.code == KEY_BACKSPACE) - sound = KeySound::Select; - } - play(sound); + play(key_sound(key, appstore_input_context(session_.screen))); } void AppStoreInputController::play(KeySound sound) @@ -108,8 +99,6 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } if (key.repeated && dismiss_key_ == key.code) return; dismiss_key_ = 0; - // The registry editor sounds like the other screens, including typed - // characters. Share code and search stay silent while typing. play_feedback(key); switch (session_.screen) { @@ -242,75 +231,17 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) if (actions_.navigate_back) actions_.navigate_back(); break; case Screen::Registry: - if (matches(key, 'b', KEY_B)) { + if (matches(key, '4', KEY_4) || matches(key, 'b', KEY_B)) { if (actions_.navigate_back) actions_.navigate_back(); - } - else if (key.code == KEY_UP || key.code == KEY_DOWN) - session_.registry.page_focus() = 1 - session_.registry.page_focus(); - else if (matches(key, '4', KEY_4) || matches(key, 'a', KEY_A)) { - if (actions_.open_registry_add) actions_.open_registry_add(); - } else if (matches(key, '5', KEY_5) || matches(key, 'e', KEY_E) || - (key.code == KEY_ENTER && session_.registry.page_focus() == 1)) { - const auto *entry = session_.registry.selected_entry(); - if (entry && !entry->builtin) registry_.edit_selected(); - } else if (matches(key, '7', KEY_7) || matches(key, 'd', KEY_D)) { - const auto *entry = session_.registry.selected_entry(); - if (entry && !entry->builtin) registry_.delete_selected(); } else if (matches(key, '8', KEY_8) || matches(key, 'r', KEY_R)) { - sync_.start(true, now); + if (!session_.registry.region_commit_pending() && registry_.operation_available()) + sync_.start(true, now); } else if (key.code == KEY_LEFT || key.code == KEY_Z || key.ch == 'z' || key.ch == '<') { - if (session_.registry.page_focus() == 0) - registry_.select_region(registry_.adjacent_region(-1), now); - else - session_.registry.select_adjacent_entry(-1); + registry_.select_region(registry_.adjacent_region(-1), now); } else if (key.code == KEY_RIGHT || key.code == KEY_C || key.ch == 'c' || key.ch == '>') { - if (session_.registry.page_focus() == 0) - registry_.select_region(registry_.adjacent_region(1), now); - else - session_.registry.select_adjacent_entry(1); - } - break; - case Screen::RegistryEdit: { - const bool fn = (key.mods & KBD_MOD_FN) != 0; - const size_t limit = session_.registry.edit_focus() == 0 ? 48 : 180; - if (!session_.registry.editing_field()) { - // The fields are confirmed, so 8 saves and Enter loops to Name. - if (matches(key, '8', KEY_8)) { - registry_.submit_editor(); - break; - } - if (key.code == KEY_ENTER) { - session_.registry.edit_focus() = 0; - session_.registry.move_caret(1000); - session_.registry.set_editing_field(true); - break; - } - // Anything else starts editing again, then does what it says. - session_.registry.set_editing_field(true); - } - if (key.code == KEY_BACKSPACE) - session_.registry.erase_before_caret(); - else if (key.code == KEY_ENTER) { - // Name confirms into URL; URL confirms the fields and enables Save. - if (session_.registry.edit_focus() == 0) { - session_.registry.edit_focus() = 1; - session_.registry.move_caret(1000); - } else { - session_.registry.set_editing_field(false); - } - } else if (key.code == KEY_TAB || key.code == KEY_UP || key.code == KEY_DOWN) { - session_.registry.edit_focus() = 1 - session_.registry.edit_focus(); - // Land at the end, where the next character will be typed. - session_.registry.move_caret(1000); - } else if (fn && (key.code == KEY_Z || key.code == KEY_LEFT)) { - session_.registry.move_caret(-1); - } else if (fn && (key.code == KEY_C || key.code == KEY_RIGHT)) { - session_.registry.move_caret(1); - } else if (!fn && key.ch >= 32 && key.ch <= 126) { - session_.registry.insert_at_caret(key.ch, limit); + registry_.select_region(registry_.adjacent_region(1), now); } break; - } case Screen::ShareCode: if (key.code == KEY_BACKSPACE) share_code_.erase_last(); diff --git a/main/ui/appstore_input_controller.hpp b/main/ui/appstore_input_controller.hpp index 0757ba3..1de38f3 100644 --- a/main/ui/appstore_input_controller.hpp +++ b/main/ui/appstore_input_controller.hpp @@ -24,8 +24,7 @@ namespace appstore_ui { constexpr cp0_keyboard_input_context_t appstore_input_context(Screen screen) { - return screen == Screen::Search || screen == Screen::ShareCode || - screen == Screen::RegistryEdit + return screen == Screen::Search || screen == Screen::ShareCode ? KBD_INPUT_CONTEXT_TEXT : KBD_INPUT_CONTEXT_NAVIGATION; } @@ -51,7 +50,6 @@ class AppStoreInputController std::function request_quit; std::function navigate_back; std::function open_registry; - std::function open_registry_add; std::function execute_confirmation; std::function repair_package; std::function render; diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index 57c2696..8ef5913 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -80,7 +80,6 @@ lv_obj_t *box(lv_obj_t *root, int x, int y, int w, int h, uint32_t color, return obj; } -// A field keeps its color on the home and detail pages. constexpr uint32_t kVersionColor = 0x7EE787; constexpr uint32_t kMaintainerColor = 0xFFA657; constexpr uint32_t kSizeColor = 0x79C0FF; @@ -104,20 +103,6 @@ void field_value(lv_obj_t *parent, const std::string &value, int x, int y, int w label(parent, value, x, y, w, font->line_height, font, color, LV_LABEL_LONG_DOT); } -// 12 px values so a full date and a size such as "1023.9 KB" fit their tags. -constexpr uint16_t kHomeChipFontSize = 12; - -void home_field(lv_obj_t *root, const std::string &value, int x, int y, int w, - uint32_t color, HorizontalMarquee *marquee = nullptr, - const std::string &key = {}) -{ - constexpr int pad = 5, height = catalog_home::kTagHeight; - field_chip(root, x, y, w, height, color); - const int line_height = store_font(value, kHomeChipFontSize)->line_height; - field_value(root, value, x + pad, y + (height - line_height) / 2, w - 2 * pad, - color, marquee, key, kHomeChipFontSize); -} - // Top of a glyph's ink, measured from the top of the font's line box. int glyph_top(const lv_font_t *font, uint32_t letter) { @@ -158,9 +143,11 @@ lv_obj_t *edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towa return fade; } +constexpr int kPermissionSize = 14; + void permission_badge(lv_obj_t *parent, int x, int y, uint32_t color) { - constexpr int size = catalog_home::kPermissionSize; + constexpr int size = kPermissionSize; lv_obj_t *badge = box(parent, x, y, size, size, color, color, 1, 4, LV_OPA_20); lv_obj_set_style_border_opa(badge, LV_OPA_40, 0); } @@ -409,56 +396,6 @@ lv_obj_t *settings_group(lv_obj_t *root, int y, int height, bool focused) return box(root, 12, y, 296, height, 0x1C1C1E, focused ? kSystemBlue : 0x2C2C2E, 1, 12); } -// A small chevron, drawn rather than taken from a font so it stays crisp. -void chevron(lv_obj_t *root, int x, int middle, bool left, uint32_t color) -{ - constexpr int arm = 5; - for (int row = 0; row < arm; ++row) { - const int inset = left ? arm - 1 - row : row; - box(root, x + inset, middle - arm + row, 2, 2, color, color, 0); - box(root, x + inset, middle + arm - 2 - row, 2, 2, color, color, 0); - } -} - -// Shows the slice of a field that holds the caret, with the caret drawn in it. -void editor_field(lv_obj_t *root, const std::string &value, size_t caret, int x, int y, - int width, bool blink) -{ - const lv_font_t *font = store_font(value, 13); - lv_obj_t *viewport = lv_obj_create(root); - lv_obj_remove_style_all(viewport); - lv_obj_set_pos(viewport, x, y); - lv_obj_set_size(viewport, width, font->line_height); - lv_obj_clear_flag(viewport, LV_OBJ_FLAG_SCROLLABLE); - - const std::string before = value.substr(0, std::min(caret, value.size())); - const int caret_x = text_width(before, font); - // Keep the caret a few pixels inside the field, scrolling the text to do it. - constexpr int margin = 8; - int scroll = 0; - if (caret_x > width - margin) scroll = caret_x - (width - margin); - const int text_width_px = text_width(value, font); - if (scroll > 0 && text_width_px - scroll < width - margin) - scroll = std::max(0, text_width_px - (width - margin)); - - if (!value.empty()) - label(viewport, value, -scroll, 0, LV_SIZE_CONTENT, font->line_height, font, 0xFFFFFF); - lv_obj_t *caret_bar = box(viewport, caret_x - scroll, 1, 1, font->line_height - 2, kSystemBlue, - kSystemBlue, 0); - if (!blink) return; - lv_anim_t blink_anim; - lv_anim_init(&blink_anim); - lv_anim_set_var(&blink_anim, caret_bar); - lv_anim_set_values(&blink_anim, LV_OPA_COVER, LV_OPA_TRANSP); - lv_anim_set_duration(&blink_anim, 530); - lv_anim_set_playback_duration(&blink_anim, 530); - lv_anim_set_repeat_count(&blink_anim, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_exec_cb(&blink_anim, [](void *obj, int32_t value) { - lv_obj_set_style_bg_opa(static_cast(obj), static_cast(value), 0); - }); - lv_anim_start(&blink_anim); -} - } // namespace int glyph_middle(const lv_font_t *font, uint32_t letter) @@ -653,40 +590,27 @@ void CatalogDisplayPage::render(const PageRenderContext &context, box(root, 0, 20, 320, 150, 0x081010, 0x081010, 0); draw_category(); draw_icon(); - const int details_width = catalog_home::kDetailsRight - catalog_home::kDetailsX; + label(root, "In category: " + std::to_string(model.show_empty ? 0 : model.selected_index + 1) + + "/" + std::to_string(model.app_count), 138, 26, 116, 18, + store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT); + label(root, "All: " + std::to_string(model.total_count), 256, 26, 64, 18, + store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT); if (model.show_empty) { - const lv_font_t *font = store_font(model.empty_message, 14); - label(root, model.empty_message, catalog_home::kDetailsX, - catalog_home::kIconCenterY - font->line_height, details_width, - font->line_height * 2, font, 0xFFFFFF, LV_LABEL_LONG_WRAP); + label(root, model.empty_message, 137, 76, 178, 40, + store_font(model.empty_message, 14), 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - // Fixed rows, whether or not an app declares permissions, so the block - // stays centered on the icon. - const lv_font_t *name_font = store_font(model.name, 20, true); - constexpr int chip_width = 84, column_gap = 4; - marquee_label(root, model.name, catalog_home::kDetailsX, - catalog_home::kTopY - glyph_top(name_font, 'H'), details_width, - name_font->line_height, name_font, 0xFFFFFF, title_marquee_, model.name); - const int value_x = catalog_home::kDetailsX + chip_width + column_gap; - const int value_width = details_width - chip_width - column_gap; - home_field(root, model.version, catalog_home::kDetailsX, catalog_home::kTagRow1Y, - chip_width, kVersionColor); - home_field(root, model.author, value_x, catalog_home::kTagRow1Y, value_width, - kMaintainerColor, &author_marquee_, model.name + model.author); - home_field(root, model.size, catalog_home::kDetailsX, catalog_home::kTagRow2Y, - chip_width, kSizeColor); - home_field(root, model.updated, value_x, catalog_home::kTagRow2Y, value_width, - kDateColor); - permission_icons(root, catalog_home::kDetailsX, catalog_home::kPermissionsY, - model.permissions); - } - if (model.show_status) { - // A status message temporarily takes over the permission row. - box(root, catalog_home::kDetailsX - 2, catalog_home::kPermissionsY - 1, - details_width + 4, 16, 0x081010, 0x081010, 0); - scrolling_status_label(root, model.status, catalog_home::kDetailsX, - catalog_home::kPermissionsY + 1, details_width, 12); + marquee_label(root, model.name, 137, 62, 178, 27, store_font(model.name, 20, true), + 0xFFFFFF, title_marquee_, model.name); + label(root, model.version, 137, 90, 66, 22, + store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); + marquee_label(root, model.author, 207, 90, 108, 22, store_font(model.author, 14), + 0xFFFFFF, author_marquee_, model.name + model.author); + label(root, model.size, 137, 110, 68, 22, + store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); + label(root, model.updated, 207, 110, 110, 22, + store_font(model.updated, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); } + if (model.show_status) scrolling_status_label(root, model.status, 110, 136, 205, 12); draw_shortcuts(); } @@ -802,7 +726,6 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView marquee_label(document, app.name, 10, 4, 300, title_font->line_height, title_font, 0xFFFFFF, title_marquee_, app.id + app.name); int y = 8 + title_font->line_height; - // Same fields, arrangement and colors as the home page. detail_field(document, "VERSION", model.version, 10, y, 146, kVersionColor); detail_field(document, "MAINTAINER", model.author, 164, y, 146, kMaintainerColor, &author_marquee_, app.id + model.author); @@ -817,6 +740,10 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView label(document, model.state, 25, y, 285, 17, store_font(model.state, 14), app.installed ? 0xE6EDF3 : 0xB1BAC4, LV_LABEL_LONG_DOT); y += 23; + if (model.app.permissions != 0) { + permission_icons(document, 10, y, model.app.permissions); + y += kPermissionSize + 7; + } box(document, 10, y, 300, 1, 0x1E2A30, 0x1E2A30, 0); y += 7; lv_obj_t *description = label(document, model.description, 10, y, 300, LV_SIZE_CONTENT, @@ -1045,8 +972,7 @@ void StoreSettingsPage::render(const PageRenderContext &context, // Region is a segmented control: the chosen segment is filled blue. constexpr int region_y = 48, region_height = 30; - const bool region_focused = model.focus == 0; - settings_group(root, region_y, region_height, region_focused); + settings_group(root, region_y, region_height, true); const char *const regions[] = {"Auto", "Default", "CN"}; const char *const codes[] = {"auto", "default", "CN"}; constexpr int segment_width = 98; @@ -1067,41 +993,19 @@ void StoreSettingsPage::render(const PageRenderContext &context, } constexpr int source_y = 84, source_height = 46; - settings_group(root, source_y, source_height, model.focus == 1 && model.has_entry); - if (!model.has_entry) { - const std::string message = - model.loading ? "Loading registries\u2026" : "No registries configured"; - const lv_font_t *font = store_font(message, 13); - center_label(root, message, 24, source_y + (source_height - font->line_height) / 2, 272, - font->line_height, font, kSecondaryText, LV_LABEL_LONG_DOT); - } else { - const auto &entry = model.entry; - const std::string source = model.region_code == "auto" - ? "Source \xC2\xB7 " + model.active_region : "Source"; - const lv_font_t *caption_font = store_font(source, 11); - label(root, source, 24, source_y + 6, 180, caption_font->line_height, caption_font, - kSecondaryText, LV_LABEL_LONG_DOT); - const std::string summary = entry.count + " apps \xC2\xB7 " + - std::to_string(model.selected_index + 1) + " of " + - std::to_string(model.entry_count); - lv_obj_t *count = label(root, summary, 150, source_y + 6, 146, caption_font->line_height, - caption_font, kSecondaryText, LV_LABEL_LONG_DOT); - lv_obj_set_style_text_align(count, LV_TEXT_ALIGN_RIGHT, 0); - - const lv_font_t *name_font = store_font(entry.name, 14); - // Chevrons bracket the name, so left/right reads as a choice. - constexpr int name_x = 40, name_right = 280; - const int name_middle = source_y + 21 + name_font->line_height / 2; - const uint32_t arrow = model.focus == 1 ? kSystemBlue : 0x636366; - chevron(root, 24, name_middle, true, arrow); - chevron(root, name_right, name_middle, false, arrow); - marquee_label(root, entry.name, name_x, source_y + 21, name_right - name_x, - name_font->line_height, name_font, 0xFFFFFF, source_marquee_, - entry.url + entry.name, LV_TEXT_ALIGN_CENTER); - } + settings_group(root, source_y, source_height, false); + const std::string source = "Active server \xC2\xB7 " + + std::string(model.active_region == "CN" ? "CN" : "Default"); + const lv_font_t *caption_font = store_font(source, 11); + label(root, source, 24, source_y + 6, 272, caption_font->line_height, caption_font, + kSecondaryText, LV_LABEL_LONG_DOT); + const lv_font_t *source_font = store_font(model.registry_url, 13); + marquee_label(root, model.registry_url, 24, source_y + 23, 272, + source_font->line_height, source_font, 0xFFFFFF, source_marquee_, + model.registry_url, LV_TEXT_ALIGN_LEFT); if (!model.status.empty()) { - // Above the bookmark tabs, so a long status can scroll without covering them. + // Keep scrolling status text above the fixed shortcut row. lv_obj_t *status = label(root, model.status, 16, 134, 288, 14, store_font(model.status, 11), model.status_is_error ? 0xFF453A : kSecondaryText, @@ -1111,50 +1015,4 @@ void StoreSettingsPage::render(const PageRenderContext &context, } } -void StoreSettingsPage::render_editor(const PageRenderContext &context, - const RegistryEditorViewModel &model) -{ - context.prepare(); - context.draw_system_bar(); - lv_obj_t *root = screen(); - box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0); - - const std::string title = model.editing ? "Edit Registry" : "Add Registry"; - const lv_font_t *title_font = store_font(title, 17, true); - center_strong_label(root, title, 12, 26 - glyph_top(title_font, 'E'), 296, - title_font->line_height, title_font, 0xFFFFFF); - - const char *const captions[] = {"Name", "URL"}; - const std::string values[] = {model.name, model.url}; - // The second field stops above the bookmark tabs. - constexpr int row_y[] = {48, 92}; - for (int i = 0; i < 2; ++i) { - constexpr int height = 40; - const bool focused = model.editing_field && model.focus == i; - settings_group(root, row_y[i], height, focused); - const lv_font_t *caption_font = store_font(captions[i], 11); - label(root, captions[i], 24, row_y[i] + 4, 272, caption_font->line_height, caption_font, - focused ? kSystemBlue : kSecondaryText); - if (!model.editing_field) { - const lv_font_t *font = store_font(values[i], 13); - label(root, values[i], 24, row_y[i] + 19, 272, font->line_height, font, 0xFFFFFF, - LV_LABEL_LONG_DOT); - } else if (!focused && values[i].empty()) { - const lv_font_t *font = store_font("Required", 13); - label(root, "Required", 24, row_y[i] + 19, 272, font->line_height, font, 0x636366); - } else { - // The caret keeps the typed end in view, scrolling the field with it. - editor_field(root, values[i], focused ? model.caret : values[i].size(), 24, - row_y[i] + 19, 272, focused); - } - } - if (!model.status.empty()) { - lv_obj_t *status = label(root, model.status, 16, 136, 240, 14, - store_font(model.status, 11), - model.status_is_error ? 0xFF453A : kSecondaryText, - LV_LABEL_LONG_DOT); - lv_obj_set_style_text_align(status, LV_TEXT_ALIGN_CENTER, 0); - } -} - } // namespace appstore_ui diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index 513d638..f41f54d 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -28,31 +28,6 @@ enum class ArrowKey { Left, Up, Right, Down }; void draw_arrow_key(lv_obj_t *parent, ArrowKey arrow, int center_x, int center_y, int width = 18, int height = 16); -// Home catalog geometry shared by the page and the icon panel. -namespace catalog_home { -// Content edges: the category's left key and the header counters' right end. -constexpr int kLeft = 9; -constexpr int kRight = 312; -// Left rows: the name's capitals, two tag rows and the permission icons, -// centered as one block between the header and the bookmark tabs. -constexpr int kTopY = 54; -constexpr int kTagHeight = 17; -// Clears the 20 px name, including its descenders. -constexpr int kTagRow1Y = kTopY + 23; -constexpr int kTagRow2Y = kTagRow1Y + kTagHeight + 3; -constexpr int kPermissionSize = 14; -constexpr int kPermissionsY = kTagRow2Y + kTagHeight + 6; -// The icon on the right fills the height between the header and the bookmark -// tabs, centered on the left block. -constexpr int kIconSize = 100; -constexpr int kIconX = kRight - kIconSize; -constexpr int kIconCenterY = (kTopY + kPermissionsY + kPermissionSize) / 2; -constexpr int kIconY = kIconCenterY - kIconSize / 2; -constexpr int kDetailsX = kLeft; -constexpr int kDetailsRight = kIconX - 9; -constexpr uint32_t kMuted = 0x8B949E; -} // namespace catalog_home - // One line of text; when it does not fit, it bounces like APPLaunch's // selected title. Text that fits is placed according to align. lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, @@ -145,8 +120,6 @@ class StoreSettingsPage : public AppStoreUiPage public: void render(const PageRenderContext &context, const StoreSettingsViewModel &model); - void render_editor(const PageRenderContext &context, - const RegistryEditorViewModel &model); private: HorizontalMarquee source_marquee_; }; diff --git a/main/ui/appstore_presenter.cpp b/main/ui/appstore_presenter.cpp index 6567909..1bef325 100644 --- a/main/ui/appstore_presenter.cpp +++ b/main/ui/appstore_presenter.cpp @@ -15,10 +15,9 @@ namespace appstore_ui { namespace { -constexpr int kCategoryX = 28; -constexpr int kCategoryY = 24; -constexpr int kCategoryWidth = 86; -constexpr int kCategoryKeyWidth = 18; +constexpr int kHomeIconX = 39; +constexpr int kHomeIconY = 65; +constexpr int kHomeIconSize = 60; constexpr uint32_t kStatusVisibleMs = 6000; lv_obj_t *label(lv_obj_t *parent, const std::string &text, int x, int y, int w, int h, @@ -80,32 +79,6 @@ std::string app_initial(const appstore::StoreApp &app) return "A"; } -constexpr int kCounterIconGap = 4; - -int counter_width(const std::string &text) -{ - lv_point_t size = {}; - lv_text_get_size(&size, text.c_str(), store_font("", 14), 0, 0, LV_COORD_MAX, - LV_TEXT_FLAG_NONE); - return size.x; -} - -// Gray header count at x, centered on `middle`; "..." if it needs more than `width`. -void counter_label(lv_obj_t *root, const std::string &text, int x, int width, int middle) -{ - const lv_font_t *font = store_font("", 14); - label(root, text, x, middle - glyph_middle(font, '0'), width, font->line_height, font, - catalog_home::kMuted, LV_LABEL_LONG_DOT); -} - -// Gray count, right-aligned at `right` and centered on `middle`. Returns its left edge. -int header_count(lv_obj_t *root, const std::string &text, int right, int middle) -{ - const int width = counter_width(text); - counter_label(root, text, right - width, width + 4, middle); - return right - width; -} - // The Store icon scaled into the size x size square at x, y; false if it is missing. bool draw_store_icon(lv_obj_t *root, AppStoreImageRenderer &images, int x, int y, int size) { @@ -119,37 +92,6 @@ bool draw_store_icon(lv_obj_t *root, AppStoreImageRenderer &images, int x, int y return true; } -// Catalog size: Store icon, then the count. Returns the icon's left edge. -int draw_catalog_total(lv_obj_t *root, AppStoreImageRenderer &images, int total, - int right, int middle) -{ - // The Store artwork is a badge with its own padding, so the box has to be - // larger than the category's letter height to look the same size. - constexpr int icon_size = 18; - const int icon_x = header_count(root, std::to_string(total), right, middle) - - kCounterIconGap - icon_size; - if (!draw_store_icon(root, images, icon_x, middle - icon_size / 2, icon_size)) { - const lv_font_t *font = store_font("", 14); - strong_label(root, "*", icon_x, middle - glyph_middle(font, '*'), icon_size, - font->line_height, font, catalog_home::kMuted); - } - return icon_x; -} - -// Selected app within the category: the up/down keys that change it, then "x / y". -// Returns the group's left edge. -int draw_selection_position(lv_obj_t *root, int position, int count, int right, int middle) -{ - constexpr int key = 16, key_gap = 2; - const int text_x = header_count(root, std::to_string(position) + " / " + - std::to_string(count), right, middle); - const int down_x = text_x - kCounterIconGap - key / 2; - const int up_x = down_x - key - key_gap; - draw_arrow_key(root, ArrowKey::Down, down_x, middle, key, key); - draw_arrow_key(root, ArrowKey::Up, up_x, middle, key, key); - return up_x - key / 2; -} - } // namespace AppStorePresenter::AppStorePresenter( @@ -187,55 +129,33 @@ void AppStorePresenter::prepare(AppStoreUiPage &page) void AppStorePresenter::draw_category_selector(lv_obj_t *root) { + if (!images_.draw_packaged(root, "store_arrow_left.png", 14, 27)) + strong_label(root, "<", 14, 24, 14, 18, store_font("", 20), 0xFF6A3D); const std::string category = appstore::upper_ascii(session_.catalog.current_category_name()); - const lv_font_t *font = store_font(category, 14, true); - marquee_label(root, category, kCategoryX, kCategoryY, kCategoryWidth, 20, font, 0xFFFFFF, + marquee_label(root, category, 28, 24, 86, 20, store_font(category, 14, true), 0xFFFFFF, category_marquee_, category, LV_TEXT_ALIGN_CENTER); - // The name is uppercase: center on its capitals, not on the line box, - // which also reserves room below the baseline for descenders. - const int middle = kCategoryY + glyph_middle(font, 'H'); - const int right_key_x = kCategoryX + kCategoryWidth + 10; - draw_arrow_key(root, ArrowKey::Left, kCategoryX - 10, middle, kCategoryKeyWidth); - draw_arrow_key(root, ArrowKey::Right, right_key_x, middle, kCategoryKeyWidth); - - // Header counters, right to left: catalog size, then the selected app's - // position in the category. The category's own position follows its right - // key and gets whatever room is left. - constexpr int counter_gap = 10; - int free_right = draw_catalog_total(root, images_, - static_cast(session_.catalog.apps().size()), - catalog_home::kRight, middle) - counter_gap; - const int selected = session_.catalog.selected_index(); - const int visible = static_cast(session_.catalog.visible().size()); - if (selected >= 0 && selected < visible) - free_right = draw_selection_position(root, selected + 1, visible, free_right, middle) - - counter_gap; - - const auto &categories = session_.catalog.categories(); - const int index = session_.catalog.category_index(); - if (index < 0 || index >= static_cast(categories.size())) return; - const std::string position = std::to_string(index + 1) + " / " + - std::to_string(categories.size()); - const int position_x = right_key_x + kCategoryKeyWidth / 2 + kCounterIconGap; - const int width = std::min(counter_width(position) + 4, free_right - position_x); - if (width > 0) counter_label(root, position, position_x, width, middle); + if (!images_.draw_packaged(root, "store_arrow_right.png", 116, 27)) + strong_label(root, ">", 116, 24, 14, 18, store_font("", 20), 0xFF6A3D); } void AppStorePresenter::draw_home_icon_panel(lv_obj_t *root, const appstore::StoreApp *app) { - using catalog_home::kIconCenterY; - using catalog_home::kIconSize; - using catalog_home::kIconX; - const lv_font_t *font = &lv_font_montserrat_20; + const int arrow_x = kHomeIconX + (kHomeIconSize - 14) / 2; + if (!images_.draw_packaged(root, "store_arrow_up.png", arrow_x, 48)) + center_strong_label(root, "^", kHomeIconX + 16, 46, 28, 18, + &lv_font_montserrat_20, 0xFF6A3D); if (!app) { - center_strong_label(root, "-", kIconX, kIconCenterY - glyph_middle(font, '-'), - kIconSize, font->line_height, font, 0x9A9A9A); + center_strong_label(root, "-", kHomeIconX + 22, kHomeIconY + 24, 24, 22, + &lv_font_montserrat_20, 0x9A9A9A); } else if (!images_.draw_app_icon(root, session_.app_dir, *app)) { - center_strong_label(root, app_initial(*app), kIconX, - kIconCenterY - glyph_middle(font, 'H'), kIconSize, - font->line_height, font, app->installed ? 0x52D05D : 0xFFFFFF); + center_strong_label(root, app_initial(*app), kHomeIconX, kHomeIconY + 21, + kHomeIconSize, 28, &lv_font_montserrat_20, + app->installed ? 0x52D05D : 0xFFFFFF); } + if (!images_.draw_packaged(root, "store_arrow_down.png", arrow_x, 136)) + center_strong_label(root, "v", kHomeIconX + 16, 134, 28, 18, + &lv_font_montserrat_20, 0xFF6A3D); } bool AppStorePresenter::draw_detail_background(lv_obj_t *root, @@ -306,18 +226,10 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running) view_models_.settings(registry_operation_running); settings_page_.render(context(settings_page_), model); AppStoreShortcutBar::render_settings( - settings_page_.screen(), model.has_entry, - model.has_entry && model.entry.builtin, - !model.loading && !model.operation_running && + settings_page_.screen(), !model.loading && !model.operation_running && !model.region_commit_pending); break; } - case Screen::RegistryEdit: { - const RegistryEditorViewModel model = view_models_.registry_editor(); - settings_page_.render_editor(context(settings_page_), model); - AppStoreShortcutBar::render_editor(settings_page_.screen(), !model.editing_field); - break; - } case Screen::ShareCode: catalog_page_.render_text_entry(context(catalog_page_), view_models_.share_code()); break; diff --git a/main/ui/appstore_shortcut_bar.cpp b/main/ui/appstore_shortcut_bar.cpp index 4a1cf3f..0e64382 100644 --- a/main/ui/appstore_shortcut_bar.cpp +++ b/main/ui/appstore_shortcut_bar.cpp @@ -10,37 +10,16 @@ namespace appstore_ui { namespace { -constexpr int kScreenHeight = 170; - -// A bookmark tab: the same tinted chip as the detail fields, but the rounded -// bottom continues past the screen, so the page edge cuts it with no border. void shortcut_label(lv_obj_t *root, int center_x, - const std::string &text, uint32_t color, int width = 52, + const std::string &text, uint32_t color, int width = 56, bool active = true) { - constexpr int top = 152, radius = 7; - const int x = center_x - width / 2; - const int visible = kScreenHeight - top; - lv_obj_t *tab = lv_obj_create(root); - lv_obj_remove_style_all(tab); - lv_obj_set_pos(tab, x, top); - lv_obj_set_size(tab, width, visible + radius); - lv_obj_clear_flag(tab, LV_OBJ_FLAG_SCROLLABLE); - lv_obj_set_style_radius(tab, radius, 0); - lv_obj_set_style_bg_color(tab, lv_color_hex(color), 0); - lv_obj_set_style_bg_opa(tab, active ? LV_OPA_50 : LV_OPA_20, 0); - lv_obj_set_style_border_width(tab, 1, 0); - lv_obj_set_style_border_color(tab, lv_color_hex(color), 0); - lv_obj_set_style_border_opa(tab, LV_OPA_50, 0); - lv_obj_set_style_border_side(tab, static_cast( - LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT), 0); - - const lv_font_t *font = store_font(text, 12); lv_obj_t *label = lv_label_create(root); - lv_obj_set_pos(label, x + 2, top + (visible - font->line_height) / 2); - lv_obj_set_size(label, width - 4, font->line_height); - lv_obj_set_style_text_font(label, font, 0); - lv_obj_set_style_text_color(label, lv_color_hex(active ? 0xFFFFFF : 0x8E8E93), 0); + lv_obj_set_pos(label, center_x - width / 2, 151); + lv_obj_set_size(label, width, 18); + lv_obj_set_style_text_font(label, store_font(text, 12), 0); + lv_obj_set_style_text_color(label, lv_color_hex(active ? color : 0x8E8E93), 0); + lv_obj_set_style_text_letter_space(label, 0, 0); lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); lv_label_set_long_mode(label, LV_LABEL_LONG_DOT); lv_label_set_text(label, text.c_str()); @@ -75,22 +54,10 @@ void AppStoreShortcutBar::render_detail(lv_obj_t *root, const std::string &app_d shortcut_label(root, 272, "remove", 0xFF5B4A); } -void AppStoreShortcutBar::render_settings(lv_obj_t *root, bool has_entry, - bool builtin_entry, - bool actions_available) -{ - if (!actions_available) return; - shortcut_label(root, 48, "add", 0x0A84FF); - if (has_entry && !builtin_entry) - shortcut_label(root, 104, "edit", 0x0A84FF); - if (has_entry && !builtin_entry) - shortcut_label(root, 216, "delete", 0xFF453A); - shortcut_label(root, 272, "sync", 0x30D158); -} - -void AppStoreShortcutBar::render_editor(lv_obj_t *root, bool save_active) +void AppStoreShortcutBar::render_settings(lv_obj_t *root, bool actions_available) { - shortcut_label(root, 272, "save", save_active ? 0x30D158 : 0x3A3A3C, 52, save_active); + shortcut_label(root, 48, "back", 0xF0B429); + shortcut_label(root, 272, "sync", 0x30D158, 52, actions_available); } } // namespace appstore_ui diff --git a/main/ui/appstore_shortcut_bar.hpp b/main/ui/appstore_shortcut_bar.hpp index 210ba51..cf372b0 100644 --- a/main/ui/appstore_shortcut_bar.hpp +++ b/main/ui/appstore_shortcut_bar.hpp @@ -19,9 +19,7 @@ class AppStoreShortcutBar static void render_catalog(lv_obj_t *root, const appstore::StoreApp *app); static void render_detail(lv_obj_t *root, const std::string &app_dir, const appstore::StoreApp &app); - static void render_settings(lv_obj_t *root, bool has_entry, bool builtin_entry, - bool actions_available); - static void render_editor(lv_obj_t *root, bool save_active); + static void render_settings(lv_obj_t *root, bool actions_available); }; } // namespace appstore_ui diff --git a/main/ui/appstore_task_coordinator.hpp b/main/ui/appstore_task_coordinator.hpp index fb145b7..8929825 100644 --- a/main/ui/appstore_task_coordinator.hpp +++ b/main/ui/appstore_task_coordinator.hpp @@ -22,7 +22,6 @@ enum class Screen { Progress, ErrorDialog, Registry, - RegistryEdit, ShareCode, Search, Screenshots, @@ -31,19 +30,11 @@ enum class Screen { enum class RegistryOpKind { None, SetRegion, - AddRegistry, - EditRegistry, - ToggleRegistry, - DeleteRegistry, }; struct RegistryOpRequest { RegistryOpKind kind = RegistryOpKind::None; std::string region; - std::string url; - std::string old_url; - std::string name; - bool enable = false; }; struct RegistryOpResult { @@ -80,14 +71,6 @@ class AppStoreTaskCoordinator { switch (request.kind) { case RegistryOpKind::SetRegion: return {"--set-region", request.region}; - case RegistryOpKind::AddRegistry: - return {"--add-registry", request.url, "--registry-name", request.name}; - case RegistryOpKind::EditRegistry: - return {"--edit-registry", request.old_url, request.url, - "--registry-name", request.name}; - case RegistryOpKind::ToggleRegistry: - return {request.enable ? "--enable-registry" : "--disable-registry", request.url}; - case RegistryOpKind::DeleteRegistry: return {"--remove-registry", request.url}; case RegistryOpKind::None: return {}; } return {}; diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 1dc1d90..5a88111 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -122,7 +122,6 @@ CatalogDisplayViewModel AppStoreViewModelFactory::catalog( model.author = single_line(app->author.empty() ? "-" : app->author); model.size = human_size(app->size); model.updated = app->updated_at.empty() ? "-" : app->updated_at.substr(0, 10); - model.permissions = app->permissions; } return model; } @@ -203,7 +202,7 @@ InitializationProgressViewModel AppStoreViewModelFactory::initialization() const model.error_message = sentence(session_.error.message.empty() ? "No registry could be reached" : session_.error.message) + " " + sentence(session_.error.detail.empty() - ? "Check Wi\u2011Fi or change registries in Settings" : session_.error.detail); + ? "Check Wi\u2011Fi or change server in Settings" : session_.error.detail); return model; } @@ -213,36 +212,20 @@ StoreSettingsViewModel AppStoreViewModelFactory::settings(bool operation_running model.region_code = session_.registry.region_code(); model.active_region = session_.registry.active_region(); model.registry_url = session_.registry.registry_url(); - model.focus = session_.registry.page_focus(); model.loading = session_.registry_loading; - model.selected_index = session_.registry.selected_index(); - model.entry_count = static_cast(session_.registry.entries().size()); - model.has_entry = session_.registry.selected_entry() != nullptr; - if (model.has_entry) model.entry = *session_.registry.selected_entry(); model.operation_running = operation_running; model.region_commit_pending = session_.registry.region_commit_pending(); if (model.region_commit_pending) { model.status = "Region update pending..."; } else if (model.operation_running) { model.status = "Registry operation running..."; - } else if (model.has_entry && !model.entry.error.empty()) { - model.status = single_line(model.entry.error); + } else if (!session_.registry.error().empty()) { + model.status = single_line(session_.registry.error()); model.status_is_error = true; } return model; } -RegistryEditorViewModel AppStoreViewModelFactory::registry_editor() const -{ - RegistryEditorViewModel model{!session_.registry.edit_url().empty(), - session_.registry.name_input(), session_.registry.input_url(), - session_.registry.edit_focus(), session_.registry.caret(), - session_.registry.editing_field(), {}, false}; - model.status = session_.status.value(); - model.status_is_error = !model.status.empty(); - return model; -} - TextEntryViewModel AppStoreViewModelFactory::share_code() const { return {"Share Code", "TYPE SHARE CODE", "share code", share_code_.input(), diff --git a/main/ui/appstore_view_model_factory.hpp b/main/ui/appstore_view_model_factory.hpp index 85a6ba1..c2ea857 100644 --- a/main/ui/appstore_view_model_factory.hpp +++ b/main/ui/appstore_view_model_factory.hpp @@ -29,7 +29,6 @@ class AppStoreViewModelFactory ErrorDialogViewModel error() const; InitializationProgressViewModel initialization() const; StoreSettingsViewModel settings(bool operation_running) const; - RegistryEditorViewModel registry_editor() const; TextEntryViewModel share_code() const; SearchPageViewModel search(); diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index ecb1c7e..c67fb68 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -33,7 +33,6 @@ struct CatalogDisplayViewModel { std::string size; std::string updated; std::string empty_message; - uint32_t permissions = 0; int selected_index = 0; int app_count = 0; int total_count = 0; @@ -120,29 +119,11 @@ struct StoreSettingsViewModel { std::string region_code; std::string active_region; std::string registry_url; - int focus = 0; bool loading = false; - bool has_entry = false; - appstore::RegistryEntry entry; - int selected_index = 0; - int entry_count = 0; bool operation_running = false; bool region_commit_pending = false; std::string status; bool status_is_error = false; }; -struct RegistryEditorViewModel { - bool editing = false; - std::string name; - std::string url; - int focus = 0; - // Byte offset of the caret in the focused field. - size_t caret = 0; - // Save stays inactive until Enter confirms the fields. - bool editing_field = true; - std::string status; - bool status_is_error = false; -}; - } // namespace appstore_ui diff --git a/main/ui/registry_controller.cpp b/main/ui/registry_controller.cpp index 40b584d..a1287c3 100644 --- a/main/ui/registry_controller.cpp +++ b/main/ui/registry_controller.cpp @@ -29,14 +29,6 @@ void RegistryController::open() request_refresh(); } -void RegistryController::open_add() -{ - if (!operation_available()) return; - session_.registry.begin_add(); - session_.status.value().clear(); - session_.screen = Screen::RegistryEdit; -} - void RegistryController::request_refresh() { if (dependencies_.exit_requested && dependencies_.exit_requested()) return; @@ -56,8 +48,12 @@ bool RegistryController::poll_refresh() std::optional deferred; if (!tasks_.take_registry_refresh(request, registries, &deferred)) return false; session_.registry_loading = false; + if (deferred) { + request_refresh(); + return true; + } session_.registry.apply(registries); - if (deferred) request_refresh(); + if (dependencies_.save_config) dependencies_.save_config(); return true; } @@ -129,21 +125,6 @@ void RegistryController::apply_region_output(const std::string &output) } } -std::string RegistryController::count_message(const std::string &output, bool editing) -{ - std::istringstream stream(output); - std::string line; - while (std::getline(stream, line)) { - const auto fields = split_tab(line); - if (fields.size() < 5 || fields[0] != "REGISTRY") continue; - const std::string count = fields[1] == "UPDATED" && fields.size() >= 6 - ? fields[5] : fields[4]; - return (editing ? "Registry updated" : "Registry added") + - (count.empty() ? std::string() : " (" + count + " apps)"); - } - return editing ? "Registry updated" : "Registry added"; -} - bool RegistryController::poll_operation() { RegistryOpRequest request; @@ -152,43 +133,15 @@ bool RegistryController::poll_operation() const bool ok = result.rc == 0 && result.output.find("ERROR") == std::string::npos; if (!ok) { session_.status.value() = one_line(backend_error_message(result.output), 54); + request_refresh(); return true; } + apply_region_output(result.output); if (dependencies_.save_config) dependencies_.save_config(); - - switch (request.kind) { - case RegistryOpKind::SetRegion: - apply_region_output(result.output); - session_.status.value() = "Region: " + session_.registry.region_label(); - request_refresh(); - if (dependencies_.request_summary) dependencies_.request_summary(); - if (dependencies_.sync_catalog) dependencies_.sync_catalog(true); - break; - case RegistryOpKind::AddRegistry: - case RegistryOpKind::EditRegistry: - session_.status.value() = count_message( - result.output, request.kind == RegistryOpKind::EditRegistry); - session_.registry.finish_edit(); - session_.screen = Screen::Registry; - request_refresh(); - if (dependencies_.sync_catalog) dependencies_.sync_catalog(true); - break; - case RegistryOpKind::ToggleRegistry: - session_.status.value() = request.enable ? "Registry enabled" : "Registry disabled"; - request_refresh(); - if (dependencies_.request_summary) dependencies_.request_summary(); - if (request.enable && dependencies_.sync_catalog) dependencies_.sync_catalog(true); - break; - case RegistryOpKind::DeleteRegistry: - session_.status.value() = "Registry deleted"; - session_.registry.finish_edit(); - request_refresh(); - if (dependencies_.request_summary) dependencies_.request_summary(); - break; - case RegistryOpKind::None: - session_.status.value() = "Registry updated"; - request_refresh(); - break; + session_.status.value() = "Region: " + session_.registry.region_label(); + if (!session_.registry.region_commit_pending()) { + if (dependencies_.request_summary) dependencies_.request_summary(); + if (dependencies_.sync_catalog) dependencies_.sync_catalog(true); } return true; } @@ -219,70 +172,4 @@ bool RegistryController::poll_region_debounce(uint32_t now, uint32_t delay_ms) return true; } -void RegistryController::submit_editor() -{ - if (session_.registry.name_input().empty() || session_.registry.input_url().empty()) { - session_.status.value() = session_.registry.name_input().empty() ? "Name required" - : "URL required"; - // Leave the missing field open, so the rejection is visible and editable. - session_.registry.edit_focus() = session_.registry.name_input().empty() ? 0 : 1; - session_.registry.move_caret(1000); - session_.registry.set_editing_field(true); - return; - } - if (!operation_available()) { - session_.registry.set_editing_field(true); - return; - } - RegistryOpRequest request; - request.kind = session_.registry.edit_url().empty() - ? RegistryOpKind::AddRegistry : RegistryOpKind::EditRegistry; - request.old_url = session_.registry.edit_url(); - request.url = session_.registry.input_url(); - request.name = session_.registry.name_input(); - start_operation(request, request.kind == RegistryOpKind::EditRegistry - ? "Updating registry..." : "Adding registry..."); -} - -void RegistryController::toggle_selected() -{ - if (!operation_available()) return; - RegistryEntry *entry = session_.registry.selected_entry(); - if (!entry) return; - RegistryOpRequest request; - request.kind = RegistryOpKind::ToggleRegistry; - request.url = entry->url; - request.enable = !entry->enabled; - start_operation(request, entry->enabled ? "Disabling registry..." : "Enabling registry..."); -} - -void RegistryController::delete_selected() -{ - if (!operation_available()) return; - RegistryEntry *entry = session_.registry.selected_entry(); - if (!entry) return; - if (entry->builtin) { - session_.status.value() = "Use region setting"; - return; - } - RegistryOpRequest request; - request.kind = RegistryOpKind::DeleteRegistry; - request.url = entry->url; - start_operation(request, "Deleting registry..."); -} - -void RegistryController::edit_selected() -{ - if (!operation_available()) return; - RegistryEntry *entry = session_.registry.selected_entry(); - if (!entry) return; - if (entry->builtin) { - session_.status.value() = "Use region setting"; - return; - } - session_.registry.begin_edit_selected(); - session_.status.value().clear(); - session_.screen = Screen::RegistryEdit; -} - } // namespace appstore_ui diff --git a/main/ui/registry_controller.hpp b/main/ui/registry_controller.hpp index e2fadfc..6b44d1e 100644 --- a/main/ui/registry_controller.hpp +++ b/main/ui/registry_controller.hpp @@ -32,7 +32,6 @@ class RegistryController PackageJobState &package_job, Dependencies dependencies); void open(); - void open_add(); void request_refresh(); bool poll_refresh(); bool poll_operation(); @@ -44,16 +43,10 @@ class RegistryController std::string adjacent_region(int delta) const; bool poll_region_debounce(uint32_t now, uint32_t delay_ms); - void submit_editor(); - void toggle_selected(); - void delete_selected(); - void edit_selected(); - private: bool refresh_running(); bool start_operation(const RegistryOpRequest &request, const std::string &status); void apply_region_output(const std::string &output); - static std::string count_message(const std::string &output, bool editing); AppStoreSessionState &session_; AppStoreTaskService &tasks_; diff --git a/main/ui/registry_persistence_service.cpp b/main/ui/registry_persistence_service.cpp index 68f4f78..c54e675 100644 --- a/main/ui/registry_persistence_service.cpp +++ b/main/ui/registry_persistence_service.cpp @@ -21,6 +21,7 @@ RegistryPersistenceService::RegistryPersistenceService( void RegistryPersistenceService::apply_hint(const appstore::RegistryConfig &config) { session_.registry.apply_config_hint(config); + session_.sync.status.url = session_.registry.registry_url(); } void RegistryPersistenceService::log_config( @@ -40,6 +41,7 @@ void RegistryPersistenceService::initialize() apply_hint(shared); if (dependencies_.replace_backend && !dependencies_.replace_backend(shared)) session_.status.value() = "Unable to apply saved registry settings"; + shared_store_.save(shared); return; } @@ -59,6 +61,7 @@ bool RegistryPersistenceService::save_backend() if (dependencies_.log) dependencies_.log("shared_registry save skipped: backend config empty"); return false; } + apply_hint(backend); return shared_store_.save(backend); } diff --git a/main/ui/registry_ui_state.cpp b/main/ui/registry_ui_state.cpp index fb6e2f9..f46967f 100644 --- a/main/ui/registry_ui_state.cpp +++ b/main/ui/registry_ui_state.cpp @@ -7,80 +7,51 @@ #include "registry_ui_state.hpp" #include -#include +#include namespace appstore_ui { -namespace { - -constexpr const char *kChinaRegistryUrl = - "https://cardputer-zero-repo.oss-cn-shenzhen.aliyuncs.com/packages/cn/registry.json"; - -} // namespace void RegistryUiState::apply(const appstore::RegistryData &data) { + if (region_commit_pending_) return; apply_region(data.region); - entries_ = data.entries; - lines_ = data.lines; - clamp_selection(); + error_.clear(); + for (const auto &entry : data.entries) { + if (entry.builtin && entry.url == registry_url_) { + error_ = entry.error; + break; + } + } } void RegistryUiState::apply_config_hint(const appstore::RegistryConfig &config) { - region_code_ = config.region.empty() ? "auto" : config.region; - region_label_ = label_for_region(region_code_); - active_region_ = config.active_region.empty() ? "default" : config.active_region; - for (const auto &entry : config.entries) { - if (entry.builtin || entry.region == active_region_) { - registry_url_ = entry.url; - return; - } - } - if (!config.entries.empty()) registry_url_ = config.entries.front().url; + if (region_commit_pending_) return; + const auto canonical = appstore::SharedRegistryStore::normalize(config); + region_code_ = canonical.region; + region_label_ = region_code_ == "CN" ? "China" : + region_code_ == "default" ? "Default" : "Auto"; + active_region_ = canonical.active_region; + if (registry_url_ != canonical.entries.front().url) error_.clear(); + registry_url_ = canonical.entries.front().url; } void RegistryUiState::apply_region(const appstore::RegionData ®ion) { - region_code_ = region.code.empty() ? "auto" : region.code; - region_label_ = region.label.empty() ? label_for_region(region_code_) : region.label; - registry_url_ = region.registry_url.empty() ? url_for_region(region_code_) : region.registry_url; - active_region_ = region.active.empty() ? "default" : region.active; + appstore::RegistryConfig config; + config.region = region.code; + config.active_region = region.active; + apply_config_hint(config); } void RegistryUiState::apply_local_region(const std::string ®ion) { - region_code_ = region; - region_label_ = label_for_region(region); - registry_url_ = url_for_region(region); - if (region != "auto") active_region_ = region; - for (auto &entry : entries_) { - if (entry.builtin || entry.region == "CN" || entry.region == "default") { - const bool name_follows_url = entry.name.empty() || entry.name == entry.url; - entry.url = registry_url_; - entry.region = region == "auto" ? active_region_ : region; - if (name_follows_url) entry.name = "CardputerZero Hub"; - } - } -} - -appstore::RegistryEntry *RegistryUiState::selected_entry() -{ - return selected_index_ >= 0 && selected_index_ < static_cast(entries_.size()) - ? &entries_[selected_index_] : nullptr; -} - -const appstore::RegistryEntry *RegistryUiState::selected_entry() const -{ - return selected_index_ >= 0 && selected_index_ < static_cast(entries_.size()) - ? &entries_[selected_index_] : nullptr; -} - -void RegistryUiState::select_adjacent_entry(int delta) -{ - if (entries_.empty()) return; - const int count = static_cast(entries_.size()); - selected_index_ = (selected_index_ + delta) % count; - if (selected_index_ < 0) selected_index_ += count; + appstore::RegistryConfig config; + config.region = region; + // Auto always starts with GitHub, regardless of the previously active mirror. + config.active_region = region == "CN" ? "CN" : "default"; + region_commit_pending_ = false; + apply_config_hint(config); } std::string RegistryUiState::adjacent_region(int delta) const @@ -93,84 +64,11 @@ std::string RegistryUiState::adjacent_region(int delta) const return regions[next]; } -void RegistryUiState::begin_add() -{ - edit_url_.clear(); - name_input_.clear(); - input_url_ = kDefaultRegistryUrl; - edit_focus_ = 0; - caret_ = 0; - editing_field_ = true; -} - -bool RegistryUiState::begin_edit_selected() -{ - const auto *entry = selected_entry(); - if (!entry || entry->builtin) return false; - edit_url_ = entry->url; - input_url_ = entry->url; - name_input_ = entry->name; - edit_focus_ = 0; - caret_ = name_input_.size(); - editing_field_ = true; - return true; -} - -void RegistryUiState::finish_edit() -{ - edit_url_.clear(); -} - -std::string &RegistryUiState::edited_field() -{ - return edit_focus_ == 0 ? name_input_ : input_url_; -} - -void RegistryUiState::clamp_caret() -{ - caret_ = std::min(caret_, edited_field().size()); -} - -void RegistryUiState::move_caret(int delta) -{ - clamp_caret(); - const std::string &field = edited_field(); - while (delta < 0 && caret_ > 0) { - // Step back over a whole UTF-8 character, not just its last byte. - do { --caret_; } while (caret_ > 0 && (static_cast(field[caret_]) & 0xC0) == 0x80); - ++delta; - } - while (delta > 0 && caret_ < field.size()) { - ++caret_; - while (caret_ < field.size() && (static_cast(field[caret_]) & 0xC0) == 0x80) ++caret_; - --delta; - } -} - -void RegistryUiState::insert_at_caret(char ch, size_t limit) -{ - std::string &field = edited_field(); - clamp_caret(); - if (field.size() >= limit) return; - field.insert(caret_, 1, ch); - ++caret_; -} - -void RegistryUiState::erase_before_caret() -{ - std::string &field = edited_field(); - clamp_caret(); - if (caret_ == 0) return; - const size_t end = caret_; - move_caret(-1); - field.erase(caret_, end - caret_); -} - bool RegistryUiState::schedule_region(const std::string ®ion, uint32_t now) { if (region == region_code_) return false; apply_local_region(region); - pending_region_ = region; + pending_region_ = region_code_; region_commit_pending_ = true; region_change_tick_ = now; return true; @@ -185,25 +83,4 @@ std::optional RegistryUiState::take_due_region(uint32_t now, uint32 return pending_region_; } -std::string RegistryUiState::label_for_region(const std::string ®ion) -{ - if (region == "CN") return "China"; - if (region == "default") return "Default"; - return "Auto"; -} - -std::string RegistryUiState::url_for_region(const std::string ®ion) const -{ - if (region == "CN" || (region == "auto" && active_region_ == "CN")) - return kChinaRegistryUrl; - return kDefaultRegistryUrl; -} - -void RegistryUiState::clamp_selection() -{ - if (selected_index_ >= static_cast(entries_.size())) - selected_index_ = std::max(0, static_cast(entries_.size()) - 1); - if (selected_index_ < 0) selected_index_ = 0; -} - } // namespace appstore_ui diff --git a/main/ui/registry_ui_state.hpp b/main/ui/registry_ui_state.hpp index f1fea12..eb4ef0f 100644 --- a/main/ui/registry_ui_state.hpp +++ b/main/ui/registry_ui_state.hpp @@ -7,11 +7,11 @@ #pragma once #include "appstore_client.hpp" +#include "shared_registry_store.hpp" #include #include #include -#include namespace appstore_ui { @@ -19,78 +19,31 @@ class RegistryUiState { public: static constexpr const char *kDefaultRegistryUrl = - "https://cardputerzero.github.io/generated/registry.json"; + appstore::SharedRegistryStore::kDefaultRegistryUrl; void apply(const appstore::RegistryData &data); void apply_config_hint(const appstore::RegistryConfig &config); void apply_region(const appstore::RegionData ®ion); void apply_local_region(const std::string ®ion); - - appstore::RegistryEntry *selected_entry(); - const appstore::RegistryEntry *selected_entry() const; - void select_adjacent_entry(int delta); std::string adjacent_region(int delta) const; - void begin_add(); - bool begin_edit_selected(); - void finish_edit(); - - // The caret sits on a byte boundary. Typing and deleting happen there, and - // left/right move it by one character. - void move_caret(int delta); - void insert_at_caret(char ch, size_t limit); - void erase_before_caret(); - bool schedule_region(const std::string ®ion, uint32_t now); std::optional take_due_region(uint32_t now, uint32_t delay_ms, bool operation_running); - std::vector &entries() { return entries_; } - const std::vector &entries() const { return entries_; } - const std::vector &lines() const { return lines_; } - int &selected_index() { return selected_index_; } - int selected_index() const { return selected_index_; } - int &page_focus() { return page_focus_; } - int page_focus() const { return page_focus_; } - std::string &input_url() { return input_url_; } - const std::string &input_url() const { return input_url_; } - std::string &edit_url() { return edit_url_; } - const std::string &edit_url() const { return edit_url_; } - std::string &name_input() { return name_input_; } - const std::string &name_input() const { return name_input_; } - int &edit_focus() { return edit_focus_; } - int edit_focus() const { return edit_focus_; } - size_t caret() const { return caret_; } - // Typing is open until Enter confirms the fields, which enables Save. - bool editing_field() const { return editing_field_; } - void set_editing_field(bool editing) { editing_field_ = editing; } const std::string ®ion_code() const { return region_code_; } const std::string ®ion_label() const { return region_label_; } const std::string ®istry_url() const { return registry_url_; } const std::string &active_region() const { return active_region_; } + const std::string &error() const { return error_; } bool region_commit_pending() const { return region_commit_pending_; } private: - static std::string label_for_region(const std::string ®ion); - std::string url_for_region(const std::string ®ion) const; - void clamp_selection(); - std::string &edited_field(); - void clamp_caret(); - - std::vector lines_; - std::vector entries_; - int selected_index_ = 0; - int page_focus_ = 0; - std::string input_url_ = kDefaultRegistryUrl; - std::string edit_url_; - std::string name_input_; - int edit_focus_ = 0; - size_t caret_ = 0; - bool editing_field_ = true; std::string region_code_ = "auto"; std::string region_label_ = "Auto"; std::string registry_url_ = kDefaultRegistryUrl; std::string active_region_ = "default"; + std::string error_; bool region_commit_pending_ = false; std::string pending_region_; uint32_t region_change_tick_ = 0; diff --git a/main/ui/sync_controller.cpp b/main/ui/sync_controller.cpp index 237ac1c..2dbae21 100644 --- a/main/ui/sync_controller.cpp +++ b/main/ui/sync_controller.cpp @@ -110,7 +110,7 @@ void SyncController::continue_after_startup_failure(const std::string &detail) session_.screen = Screen::StartupSync; } -void SyncController::apply_output(const std::string &output, bool refresh_registries_after) +void SyncController::apply_output(const std::string &output) { const std::string message = sync_status_message(output); if (!message.empty()) session_.status.value() = one_line(message, 54); @@ -120,8 +120,6 @@ void SyncController::apply_output(const std::string &output, bool refresh_regist if (dependencies_.request_summary) dependencies_.request_summary(session_.sync.startup_active ? SummaryPurpose::StartupCatalog : SummaryPurpose::Regular); - if (refresh_registries_after && dependencies_.request_registry_refresh) - dependencies_.request_registry_refresh(); } void SyncController::poll(uint32_t now, uint32_t animation_interval_ms) @@ -150,6 +148,8 @@ void SyncController::poll(uint32_t now, uint32_t animation_interval_ms) return; } if (!done) return; + // Auto may switch mirrors even during startup or a failed sync. + if (dependencies_.request_registry_refresh) dependencies_.request_registry_refresh(); session_.sync.animation_phase = -1; if (session_.sync.startup_active) { std::string error; @@ -168,9 +168,9 @@ void SyncController::poll(uint32_t now, uint32_t animation_interval_ms) session_.sync.status.percent = -1; session_.sync.status.phase = "catalog"; session_.sync.status.detail = "Preparing app catalog..."; - apply_output(output, request.refresh_registries_after); + apply_output(output); } else { - apply_output(output, request.refresh_registries_after); + apply_output(output); } if (dependencies_.render) dependencies_.render(); } diff --git a/main/ui/sync_controller.hpp b/main/ui/sync_controller.hpp index 6bcb861..cac5296 100644 --- a/main/ui/sync_controller.hpp +++ b/main/ui/sync_controller.hpp @@ -39,7 +39,7 @@ class SyncController private: static bool startup_failed(const std::string &output, std::string *message); - void apply_output(const std::string &output, bool refresh_registries_after); + void apply_output(const std::string &output); void set_start_failure(); void continue_after_startup_failure(const std::string &detail); diff --git a/tests/test_appstore_input_controller.cpp b/tests/test_appstore_input_controller.cpp index 4878e24..ac172c3 100644 --- a/tests/test_appstore_input_controller.cpp +++ b/tests/test_appstore_input_controller.cpp @@ -60,8 +60,8 @@ int main() KBD_INPUT_CONTEXT_NAVIGATION); assert(appstore_ui::appstore_input_context(appstore_ui::Screen::Search) == KBD_INPUT_CONTEXT_TEXT); - assert(appstore_ui::appstore_input_context(appstore_ui::Screen::RegistryEdit) == - KBD_INPUT_CONTEXT_TEXT); + assert(appstore_ui::appstore_input_context(appstore_ui::Screen::Registry) == + KBD_INPUT_CONTEXT_NAVIGATION); assert(appstore_ui::appstore_input_context(appstore_ui::Screen::Detail) == KBD_INPUT_CONTEXT_NAVIGATION); using namespace appstore_ui; @@ -105,7 +105,6 @@ int main() int backs = 0; int repairs = 0; int registry_opens = 0; - int registry_adds = 0; int confirmations = 0; int page_moves = 0; bool page_drawn = true; @@ -118,7 +117,6 @@ int main() session.screen = session.sync.startup_active ? Screen::StartupSync : Screen::Home; }, [&]() { ++registry_opens; session.screen = Screen::Registry; }, - [&]() { ++registry_adds; session.screen = Screen::RegistryEdit; }, [&]() { ++confirmations; }, [&]() { ++repairs; }, [&]() { ++renders; }, [&]() { ++page_moves; return page_drawn; }, [&](KeySound sound) { sounds.push_back(sound); }}); @@ -184,75 +182,28 @@ int main() input.handle({KEY_ENTER}, 154); assert(confirmations == 1); - session.screen = Screen::RegistryEdit; - session.registry.edit_focus() = 0; - session.registry.name_input().clear(); - input.handle({0, 0, 'X'}, 160); - assert(session.registry.name_input() == "X"); - input.handle({KEY_TAB}, 161); - assert(session.registry.edit_focus() == 1); - const std::string url_before_x = session.registry.input_url(); - input.handle({KEY_X, 0, 'x'}, 162); - assert(session.registry.edit_focus() == 1); - assert(session.registry.input_url() == url_before_x + "x"); - // Fn+Z/C moves the cursor; typing and Backspace happen at the cursor. - input.handle({KEY_Z, KBD_MOD_FN, 'z'}, 163); - input.handle({KEY_Y, 0, 'y'}, 164); - assert(session.registry.input_url() == url_before_x + "yx"); - input.handle({KEY_C, KBD_MOD_FN, 'c'}, 165); - input.handle({KEY_BACKSPACE}, 166); - assert(session.registry.input_url() == url_before_x + "y"); - // While a field is open, 8 types. Enter steps Name, then URL, then confirms. - input.handle({KEY_8, 0, '8'}, 167); - assert(session.registry.input_url() == url_before_x + "y8"); - assert(session.registry.editing_field()); - session.registry.edit_focus() = 0; - input.handle({KEY_ENTER}, 168); - assert(session.registry.editing_field() && session.registry.edit_focus() == 1); - input.handle({KEY_ENTER}, 168); - assert(!session.registry.editing_field()); - input.handle({KEY_ENTER}, 168); - assert(session.registry.editing_field() && session.registry.edit_focus() == 0); - session.registry.name_input().clear(); - input.handle({KEY_ENTER}, 168); - input.handle({KEY_ENTER}, 168); - input.handle({KEY_8, 0, '8'}, 169); - assert(session.screen == Screen::RegistryEdit); - assert(session.status.value() == "Name required"); - assert(session.registry.input_url() == url_before_x + "y8"); - - appstore::RegistryData registry_data; - registry_data.entries.push_back( - {"https://example.invalid/registry.json", "Example", "ok", "1", - "now", "", "global", true, false}); - session.registry.apply(registry_data); - session.screen = Screen::Registry; - input.handle({KEY_5}, 170); - assert(session.screen == Screen::RegistryEdit); - assert(session.registry.name_input() == "Example"); - session.screen = Screen::Registry; - input.handle({KEY_4}, 180); - assert(session.screen == Screen::RegistryEdit && registry_adds == 1); - session.screen = Screen::Registry; - input.handle({KEY_A, 0, 'a'}, 181); - assert(session.screen == Screen::RegistryEdit && registry_adds == 2); session.screen = Screen::Registry; session.status.value().clear(); - input.handle({KEY_6}, 182); - input.handle({KEY_T, 0, 't'}, 183); + for (const auto code : {KEY_A, KEY_E, KEY_D, KEY_T, KEY_5, KEY_6, KEY_7, KEY_ENTER}) + input.handle({static_cast(code)}, 170); assert(session.screen == Screen::Registry && session.status.value().empty()); - - appstore::RegistryData builtin_registry_data; - builtin_registry_data.entries.push_back( - {"https://example.invalid/builtin.json", "Built in", "ok", "1", - "now", "", "global", true, true}); - session.registry.apply(builtin_registry_data); - session.status.value().clear(); + input.handle({KEY_DOWN}, 171); + input.handle({KEY_RIGHT}, 172); + assert(session.registry.region_code() == "default"); + input.handle({KEY_C, 0, 'c'}, 173); + assert(session.registry.region_code() == "CN"); + input.handle({KEY_Z, 0, 'z'}, 174); + assert(session.registry.region_code() == "default"); + input.handle({KEY_8}, 175); + assert(!sync.running()); + const int backs_before_settings = backs; + input.handle({KEY_4}, 180); + assert(session.screen == Screen::Home && backs == backs_before_settings + 1); session.screen = Screen::Registry; - input.handle({KEY_5}, 184); - assert(session.screen == Screen::Registry && session.status.value().empty()); - input.handle({KEY_7}, 185); - assert(session.screen == Screen::Registry && session.status.value().empty()); + input.handle({KEY_B, 0, 'b'}, 181); + assert(session.screen == Screen::Home && backs == backs_before_settings + 2); + backs = backs_before_settings; + session.status.value().clear(); session.screen = Screen::Detail; const std::string detail_id = session.catalog.selected_app()->id; diff --git a/tests/test_appstore_view_model_factory.cpp b/tests/test_appstore_view_model_factory.cpp index 6c03438..217a797 100644 --- a/tests/test_appstore_view_model_factory.cpp +++ b/tests/test_appstore_view_model_factory.cpp @@ -82,9 +82,11 @@ int main() assert(detail.title == "A very long application name that must stay intact 2.0"); assert(detail.version == "2.0" && detail.author == "-"); + assert(detail.app.permissions == 0); app.permissions = appstore::kPermissionNetwork | appstore::kPermissionCamera; + detail = factory.detail(&app, 100, 6000); + assert(detail.app.permissions == (appstore::kPermissionNetwork | appstore::kPermissionCamera)); catalog = factory.catalog(100, 6000); - assert(catalog.permissions == (appstore::kPermissionNetwork | appstore::kPermissionCamera)); assert(catalog.version == "2.0"); assert(catalog.size == "19.6 MB"); assert(catalog.updated == "2026-07-23"); @@ -143,16 +145,19 @@ int main() initialization = factory.initialization(); assert(initialization.failed && initialization.error_title == "Cannot Connect to Store"); assert(initialization.error_message == - "Wi-Fi unavailable. Check Wi\u2011Fi or change registries in Settings."); + "Wi-Fi unavailable. Check Wi\u2011Fi or change server in Settings."); session.sync.startup_failed = false; session.error.clear(); - session.registry.entries().push_back( - {"https://example.test/registry.json", "Example", "ok", "1", "now", "", "global", true, false}); + appstore::RegistryData registry_data; + registry_data.region = {"auto", "Auto", "", "CN"}; + registry_data.entries.push_back( + {appstore::SharedRegistryStore::kChinaRegistryUrl, "CardputerZero Hub", "ok", "1", + "now", "Registry offline; using cached catalog", "CN", true, true}); + session.registry.apply(registry_data); auto settings = factory.settings(false); - assert(settings.has_entry && settings.entry.name == "Example"); - session.registry.entries()[0].error = "Registry offline; using cached catalog"; - settings = factory.settings(false); + assert(settings.active_region == "CN" && settings.region_code == "auto"); + assert(settings.registry_url == appstore::SharedRegistryStore::kChinaRegistryUrl); assert(settings.status == "Registry offline; using cached catalog"); assert(settings.status_is_error); assert(session.registry.schedule_region("CN", 100)); diff --git a/tests/test_registry_controller.cpp b/tests/test_registry_controller.cpp index 3a5227e..81f1c70 100644 --- a/tests/test_registry_controller.cpp +++ b/tests/test_registry_controller.cpp @@ -42,7 +42,7 @@ int main() *rc = 0; if (!args.empty() && args[0] == "--set-region") return std::string("REGION\tCN\tChina\thttps://cn.example/registry.json\tCN\n"); - return std::string("REGISTRY\tADDED\thttps://extra.example\tExtra\t7\n"); + return std::string{}; }); AppStoreSessionState session; PackageJobState package_job; @@ -75,10 +75,8 @@ int main() assert(session.screen == Screen::Registry && session.registry_loading); wait_for(1); assert(controller.poll_refresh()); - assert(!session.registry_loading && session.registry.entries().size() == 1); - - controller.delete_selected(); - assert(session.status.value() == "Use region setting"); + assert(!session.registry_loading); + assert(session.registry.active_region() == "default" && saved == 1); controller.select_region("CN", 100); assert(session.registry.region_code() == "CN"); @@ -89,21 +87,16 @@ int main() wait_for(2); assert(controller.poll_operation()); assert(session.registry.region_label() == "China"); - assert(saved == 1 && summaries == 1 && syncs == 1 && backend_calls == 1); - wait_for(3); - assert(controller.poll_refresh()); + assert(saved == 2 && summaries == 1 && syncs == 1 && backend_calls == 1); + assert(session.registry.registry_url() == appstore::SharedRegistryStore::kChinaRegistryUrl); - controller.open_add(); - session.registry.name_input() = "Extra"; - session.registry.input_url() = "https://extra.example/registry.json"; - controller.submit_editor(); - wait_for(4); - assert(controller.poll_operation()); - assert(session.status.value() == "Registry added (7 apps)"); - assert(session.screen == Screen::Registry); - assert(saved == 2 && syncs == 2 && backend_calls == 2); - wait_for(5); + controller.request_refresh(); + wait_for(3); assert(controller.poll_refresh()); + assert(saved == 3); + controller.select_region("auto", 2200); + assert(session.registry.active_region() == "default"); + assert(!controller.poll_region_debounce(4199, 2000)); std::cout << "registry controller tests passed\n"; } diff --git a/tests/test_registry_persistence_service.cpp b/tests/test_registry_persistence_service.cpp index 12ecaf3..2416ec4 100644 --- a/tests/test_registry_persistence_service.cpp +++ b/tests/test_registry_persistence_service.cpp @@ -61,6 +61,8 @@ int main() service.initialize(); assert(backend_loads == 0 && backend_replaces == 1); assert(session.registry.region_code() == "CN"); + assert(session.registry.registry_url() == appstore::SharedRegistryStore::kChinaRegistryUrl); + assert(shared_saves == 2); values.clear(); AppStoreSessionState migrated_session; @@ -71,9 +73,11 @@ int main() [](const std::string &) {}}); migration.initialize(); assert(backend_loads == 1); - assert(migrated_session.registry.region_code() == "US"); + assert(migrated_session.registry.region_code() == "auto"); + assert(migrated_session.registry.registry_url() == + appstore::SharedRegistryStore::kDefaultRegistryUrl); appstore::RegistryConfig migrated; - assert(shared_store.load(migrated) && migrated.region == "US"); + assert(shared_store.load(migrated) && migrated.region == "auto"); RegistryPersistenceService empty_backend( migrated_session, shared_store, @@ -82,5 +86,21 @@ int main() [](const std::string &) {}}); assert(!empty_backend.save_backend()); appstore::RegistryConfig unchanged; - assert(shared_store.load(unchanged) && unchanged.region == "US"); + assert(shared_store.load(unchanged) && unchanged.region == "auto"); + + RegistryPersistenceService fallback( + migrated_session, shared_store, + {[]() { + auto value = config("auto", "https://stale.test"); + value.active_region = "CN"; + return value; + }, {}, {}}); + assert(fallback.save_backend()); + assert(migrated_session.registry.region_code() == "auto"); + assert(migrated_session.registry.active_region() == "CN"); + assert(migrated_session.registry.registry_url() == + appstore::SharedRegistryStore::kChinaRegistryUrl); + assert(migrated_session.sync.status.url == migrated_session.registry.registry_url()); + assert(shared_store.load(unchanged) && unchanged.active_region == "CN"); + assert(unchanged.entries.size() == 1 && unchanged.entries[0].builtin); } diff --git a/tests/test_registry_ui_state.cpp b/tests/test_registry_ui_state.cpp index 0402221..1cb3998 100644 --- a/tests/test_registry_ui_state.cpp +++ b/tests/test_registry_ui_state.cpp @@ -11,56 +11,56 @@ int main() { + using appstore::SharedRegistryStore; appstore_ui::RegistryUiState state; assert(state.region_code() == "auto"); - assert(state.registry_url() == appstore_ui::RegistryUiState::kDefaultRegistryUrl); + assert(state.registry_url() == SharedRegistryStore::kDefaultRegistryUrl); - appstore::RegistryData data; - data.region = {"default", "Default", appstore_ui::RegistryUiState::kDefaultRegistryUrl, - "default"}; - data.entries.push_back({appstore_ui::RegistryUiState::kDefaultRegistryUrl, - "CardputerZero Hub", "", "", "", "", "default", true, true}); - data.entries.push_back({"https://example.test/registry.json", "Example", "", "", "", "", - "", true, false}); - state.apply(data); - assert(state.selected_entry()->builtin); - state.select_adjacent_entry(-1); - assert(state.selected_index() == 1); - assert(state.begin_edit_selected()); - assert(state.name_input() == "Example"); - state.select_adjacent_entry(1); - assert(!state.begin_edit_selected()); + appstore::RegistryConfig legacy; + legacy.region = "auto"; + legacy.active_region = "CN"; + legacy.entries.push_back({"https://custom.test", "Custom", "", "", "", "", "", true, false}); + legacy.entries.push_back({SharedRegistryStore::kDefaultRegistryUrl, "Old builtin", + "", "", "", "", "default", true, true}); + state.apply_config_hint(legacy); + assert(state.active_region() == "CN"); + assert(state.registry_url() == SharedRegistryStore::kChinaRegistryUrl); + legacy.region = "invalid"; + legacy.active_region = "invalid"; + state.apply_config_hint(legacy); + assert(state.region_code() == "auto" && state.active_region() == "default"); + assert(state.registry_url() == SharedRegistryStore::kDefaultRegistryUrl); assert(state.schedule_region("CN", 100)); assert(state.region_label() == "China"); - assert(state.registry_url().find("oss-cn-shenzhen") != std::string::npos); + assert(state.registry_url() == SharedRegistryStore::kChinaRegistryUrl); + // A stale refresh must not replace the user's debounced selection. + state.apply(appstore::RegistryData{}); + assert(state.region_code() == "CN"); assert(!state.take_due_region(2099, 2000, false)); assert(!state.take_due_region(2100, 2000, true)); auto due = state.take_due_region(2100, 2000, false); assert(due && *due == "CN"); assert(!state.region_commit_pending()); + assert(state.adjacent_region(1) == "auto"); + assert(state.schedule_region("auto", 2200)); + assert(state.active_region() == "default"); + assert(state.registry_url() == SharedRegistryStore::kDefaultRegistryUrl); + assert(state.take_due_region(4200, 2000, false)); - state.begin_add(); - assert(state.edit_url().empty()); - assert(state.name_input().empty()); - assert(state.input_url() == appstore_ui::RegistryUiState::kDefaultRegistryUrl); - assert(state.caret() == 0); - - // The caret edits in the middle of a field, not only at its end. - state.name_input() = "ac"; - state.move_caret(1000); - state.move_caret(-1); - state.insert_at_caret('b', 48); - assert(state.name_input() == "abc" && state.caret() == 2); - state.erase_before_caret(); - assert(state.name_input() == "ac" && state.caret() == 1); - state.input_url() = "héllo"; - state.edit_focus() = 1; - state.move_caret(1000); - // Three characters back steps over both bytes of é's neighbour, not into it. - state.move_caret(-3); - state.insert_at_caret('X', 180); - assert(state.input_url() == "héXllo"); + appstore::RegistryData data; + data.region = {"auto", "Auto", "https://untrusted.test", "CN"}; + data.entries.push_back({"https://custom.test", "Custom", "", "", "", "Custom error", "", true, false}); + data.entries.push_back({SharedRegistryStore::kChinaRegistryUrl, "Hub", "", "", "", + "Mirror unavailable", "CN", true, true}); + state.apply(data); + assert(state.registry_url() == SharedRegistryStore::kChinaRegistryUrl); + assert(state.error() == "Mirror unavailable"); + data.region = {"default", "Wrong label", "https://untrusted.test", "CN"}; + state.apply(data); + assert(state.active_region() == "default" && state.region_label() == "Default"); + assert(state.registry_url() == SharedRegistryStore::kDefaultRegistryUrl); + assert(state.error().empty()); std::cout << "registry UI state tests passed\n"; } diff --git a/tests/test_shared_registry_store.cpp b/tests/test_shared_registry_store.cpp index 2d53f9b..ba2386c 100644 --- a/tests/test_shared_registry_store.cpp +++ b/tests/test_shared_registry_store.cpp @@ -11,9 +11,10 @@ int main() { + using appstore::SharedRegistryStore; std::map values; bool saved = false; - appstore::SharedRegistryStore store( + SharedRegistryStore store( [&](const std::string &key, const std::string &fallback) { auto found = values.find(key); return found == values.end() ? fallback : found->second; @@ -21,24 +22,43 @@ int main() [&](const std::string &key, const std::string &value) { values[key] = value; }, [&]() { saved = true; }); - appstore::RegistryConfig config; - config.region = "CN"; - config.active_region = "CN"; - appstore::RegistryEntry entry; - entry.name = "Name\twith slash \\"; - entry.url = "https://example.test/a\nb"; - entry.enabled = true; - entry.builtin = false; - entry.region = "CN"; - config.entries.push_back(entry); - assert(store.save(config) && saved); - appstore::RegistryConfig loaded; + assert(!store.load(loaded)); + values["appstore.registry.count"] = "2"; + values["appstore.registry.region"] = "auto"; + values["appstore.registry.active_region"] = "CN"; + values["appstore.registry.0.entry"] = "Custom\thttps://custom.test\t1\t0\tCN"; + values["appstore.registry.1.entry"] = "Spoofed\thttps://spoof.test\t0\t1\tdefault"; assert(store.load(loaded)); - assert(loaded.region == "CN" && loaded.active_region == "CN"); + assert(loaded.region == "auto" && loaded.active_region == "CN"); assert(loaded.entries.size() == 1); - assert(loaded.entries[0].name == entry.name); - assert(loaded.entries[0].url == entry.url); - assert(loaded.entries[0].enabled && !loaded.entries[0].builtin); + assert(loaded.entries[0].name == "CardputerZero Hub CN"); + assert(loaded.entries[0].url == SharedRegistryStore::kChinaRegistryUrl); + assert(loaded.entries[0].enabled && loaded.entries[0].builtin); + assert(store.save(loaded) && saved); + assert(values["appstore.registry.count"] == "1"); + assert(values["appstore.registry.1.entry"].empty()); + + for (const auto &mode : {"auto", "default", "CN", "US", ""}) { + for (const auto &active : {"default", "CN", "custom", ""}) { + appstore::RegistryConfig config; + config.region = mode; + config.active_region = active; + assert(store.save(config)); + assert(store.load(loaded)); + const std::string expected_mode = std::string(mode) == "CN" || + std::string(mode) == "default" ? mode : "auto"; + const std::string expected_active = expected_mode == "auto" + ? (std::string(active) == "CN" ? "CN" : "default") : expected_mode; + assert(loaded.region == expected_mode && loaded.active_region == expected_active); + assert(loaded.entries.size() == 1 && loaded.entries[0].region == expected_active); + assert(loaded.entries[0].url == (expected_active == "CN" + ? SharedRegistryStore::kChinaRegistryUrl : SharedRegistryStore::kDefaultRegistryUrl)); + } + } + values["appstore.registry.count"] = "0"; + values["appstore.registry.region"] = "CN"; + values["appstore.registry.active_region"] = "default"; + assert(store.load(loaded) && loaded.active_region == "CN"); return 0; } diff --git a/tests/test_sync_controller.cpp b/tests/test_sync_controller.cpp index b1abd17..2876ea8 100644 --- a/tests/test_sync_controller.cpp +++ b/tests/test_sync_controller.cpp @@ -107,7 +107,7 @@ int main() assert(session.sync.status.percent == -1); assert(session.status.value() == "Catalog synced"); assert(summaries == 1 && last_summary_purpose == SummaryPurpose::StartupCatalog && - registry_refreshes == 0); + registry_refreshes == 1); session.sync.startup_active = false; session.screen = Screen::Home; @@ -115,7 +115,7 @@ int main() controller.start(true, 500); wait_for(2); controller.poll(600, 200); - assert(summaries == 2 && registry_refreshes == 1); + assert(summaries == 2 && registry_refreshes == 2); controller.initialize_startup("https://registry.example"); controller.start(false, 700); @@ -148,6 +148,7 @@ int main() assert(session.error.message == "Wi-Fi unavailable" && session.error.detail.empty()); assert(summaries == 2); + assert(registry_refreshes == 5); assert(controller.cancel() && cancels == 1); std::cout << "sync controller tests passed\n"; } From fd7ada507b1e0b33949f7afee10e50e18e1366fa Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 18:55:45 +0300 Subject: [PATCH 12/19] docs(store): describe the restored layout and mirror-only Settings --- README.md | 54 +++++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index c13526c..79b747d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ downloads continue to use curl so interrupted downloads can be resumed safely. ./M5CardputerZero-AppStore --registries ./M5CardputerZero-AppStore --regions ./M5CardputerZero-AppStore --set-region CN -./M5CardputerZero-AppStore --add-registry https://example.com/generated/registry.json ./M5CardputerZero-AppStore --sync ./M5CardputerZero-AppStore --plan ./M5CardputerZero-AppStore --install @@ -92,34 +91,29 @@ Desktop-entry repair is best effort. Failure to find or rewrite an APPLaunch desktop entry is reported as `WARNING` after a successful package operation and does not change the verified package result. -Multiple registries are supported. The Settings screen uses the startup -screen's dark look: a centered title, a segmented region control, and the -selected registry in a grouped card. `F/X` (up/down) moves between the region -and the registry; `Z/C` (left/right) changes the focused one. Choose Auto, -Default, or CN. `4` adds a registry; edit, delete, and sync keep their keys. On the -add and edit screen, `Fn+Z/C` moves the cursor through the focused field and -Backspace deletes the character before it. Enter moves from Name to URL, from -URL it confirms the fields and enables the Save tab, and from there it returns -to Name. `8` saves while Save is active; while a field is open, `8` types. -Add another registry from the same screen or with -`--add-registry`; the selected region registry and all enabled custom -registries are synced and merged into one app list. Apps with the same UUID/share code are de-duplicated, with later registry -metadata taking precedence. On the home screen, use `Z/C` (left/right) to change -category and `F/X` (up/down) to select an app. Installed filters catalog apps by +Settings offers three server modes for the same catalog: **Auto**, **Default** +(GitHub), and **CN** (Alibaba Cloud OSS). `Z/C` (left/right) changes the mode; +`4` goes back and `8` syncs after the pending selection is applied. +The screen retains its dark styling, segmented selector, and read-only active +server information. Auto tries GitHub first and falls back to OSS if it cannot +retrieve a usable catalog; explicit Default and CN choices stay pinned to that +server. Cached data does not count as a successful connectivity check. Only one +server supplies the catalog at a time; custom registries and their editor are +not supported. Existing saved custom sources are normalized to the selected +built-in server, and the mode and effective server are persisted across restarts. + +On the home screen, use `Z/C` (left/right) to change category and `F/X` (up/down) +to select an app. Installed filters catalog apps by their actual package installation state and refreshes after package operations. The Installed category is hidden when empty; removing its last app returns the selection to All. Long names bounce like the selected APPLaunch title: they pause for two seconds, scroll horizontally at 40 pixels per second to the end, pause again, and scroll back. Status-bar updates keep the current reading position, and labels never scroll vertically. In search results only the -selected name scrolls; the others end with an ellipsis. The selected app's -version, maintainer, size, and update date are shown in green, orange, blue, -and violet tags. -The category row shows the category name between left and right buttons, -followed by the category's position in the category list (for example -`2 / 5`). On the same row, the selected app's position in the category (for -example `1 / 4`) follows up and down buttons, and the catalog size follows the -Store icon. +selected name scrolls; the others end with an ellipsis. The home screen keeps +its original layout: the app icon on the left, name and metadata on the right, +and plain-text number-key shortcuts along the bottom. Permission icons appear +only on the app details page. Press `4` for settings, `5` for share code, `6` for search, `7` for install/reinstall, and `8` or Enter for details. AppStore syncs the registry automatically when it starts. The startup screen names the current step @@ -137,14 +131,12 @@ from any screen, including while the hint is open. Keys play the launcher's system sounds: arrows and `F/X/Z/C` play the switch sound on every step, including repeats while held, and Enter, Tab, a short `Esc`, and shortcut keys play the enter sound. Typing in the share-code and -search fields is silent. The registry editor sounds too: typed characters, -Backspace, and switching fields play the enter sound, and `Fn+Z/C` plays the -switch sound. A held key repeats no faster than the screen redraws, and its sound keeps -playing while the redraw waits, so the view -keeps up and stops when the key is released. - -The detail page shows the app name, the same color-coded version, maintainer, -size, and update fields as the home screen, the install state, the complete +search fields is silent. A held key repeats no faster than the screen redraws, +and its sound keeps playing while the redraw waits, so the view keeps up and +stops when the key is released. + +The detail page shows the app name, color-coded version, maintainer, size, +and update fields, declared permission icons, the install state, the complete description, 160 x 85 screenshot previews loaded from the registry, and the package and categories. `F/X` scrolls the whole content area with a short glide, 24 pixels per press; holding the key scrolls continuously. The system From e71e7abd45e926c5f20111ee5066f1473dec18a2 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:21:17 +0300 Subject: [PATCH 13/19] feat(store): remove the Recommended category from the catalog --- main/backend/appstore_native.cpp | 5 +++-- main/ui/catalog_controller.cpp | 1 + main/ui/catalog_state.cpp | 3 +-- main/ui/catalog_state.hpp | 2 +- tests/test_catalog_controller.cpp | 25 +++++++++++++++++++++++-- tests/test_catalog_state.cpp | 8 ++++++-- tests/test_native_backend.cpp | 18 ++++++++++++++++-- 7 files changed, 51 insertions(+), 11 deletions(-) diff --git a/main/backend/appstore_native.cpp b/main/backend/appstore_native.cpp index 3abc268..b601bd1 100644 --- a/main/backend/appstore_native.cpp +++ b/main/backend/appstore_native.cpp @@ -1168,9 +1168,10 @@ std::string summary_output() if (pending.is_object() && !pending.empty()) emit(out, "WARN", "Interrupted " + pending.value("action", std::string("package operation")) + " pending; retry it from app details"); - std::vector categories = {"Recommended", "All", "Installed"}; + std::vector categories = {"All", "Installed"}; for (const auto &app : apps) for (const auto &category : string_list(app.value("categories", json::array()))) - if (std::find(categories.begin(), categories.end(), category) == categories.end()) categories.push_back(category); + if (category != "Recommended" && + std::find(categories.begin(), categories.end(), category) == categories.end()) categories.push_back(category); for (const auto &category : categories) emit(out, "CAT", category); for (const auto &app : apps) { const std::vector app_categories = diff --git a/main/ui/catalog_controller.cpp b/main/ui/catalog_controller.cpp index 084c41f..bfa7714 100644 --- a/main/ui/catalog_controller.cpp +++ b/main/ui/catalog_controller.cpp @@ -130,6 +130,7 @@ void CatalogController::apply_summary(const SummaryData &summary) sort_apps(session_.catalog.apps(), session_.catalog.sort_rule()); } auto &categories = session_.catalog.categories(); + categories.erase(std::remove(categories.begin(), categories.end(), "Recommended"), categories.end()); categories.erase(std::remove(categories.begin(), categories.end(), "Installed"), categories.end()); const auto &apps = session_.catalog.apps(); if (std::any_of(apps.begin(), apps.end(), [](const StoreApp &app) { return app.installed; })) { diff --git a/main/ui/catalog_state.cpp b/main/ui/catalog_state.cpp index 531bf02..3ebda14 100644 --- a/main/ui/catalog_state.cpp +++ b/main/ui/catalog_state.cpp @@ -51,8 +51,7 @@ void CatalogState::rebuild_visible() if (app.recommended) ++recommended_count; if (category_match) ++exact_category_count; const bool show = category == "Installed" ? app.installed : - category == "All" || - (category == "Recommended" && app.recommended) || category_match; + category == "All" || category_match; if (show) visible_.push_back(index); } if (selected_index_ >= static_cast(visible_.size())) diff --git a/main/ui/catalog_state.hpp b/main/ui/catalog_state.hpp index 243a80e..db83fbc 100644 --- a/main/ui/catalog_state.hpp +++ b/main/ui/catalog_state.hpp @@ -40,7 +40,7 @@ class CatalogState appstore::SortRule sort_rule() const { return sort_rule_; } private: - std::vector categories_{"Recommended", "All"}; + std::vector categories_{"All"}; std::vector apps_; std::vector visible_; int category_index_ = 0; diff --git a/tests/test_catalog_controller.cpp b/tests/test_catalog_controller.cpp index d7a7741..22cd157 100644 --- a/tests/test_catalog_controller.cpp +++ b/tests/test_catalog_controller.cpp @@ -54,13 +54,15 @@ int main() }; appstore::SummaryData summary; summary.saw_meta = true; - summary.categories = {"Recommended", "All", "Tools"}; + summary.categories = {"All", "Tools"}; summary.apps = {make_app("b-id", "BBBB", "Beta", "Tools"), make_app("a-id", "AAAA", "Alpha", "Tools"), make_app("c-id", "CCCC", "Gamma", "Games")}; summary.repo_status = "3 apps"; controller.apply_summary(summary); assert(session.catalog.current_category_name() == "All"); + assert((session.catalog.categories() == std::vector{"All", "Tools"})); + assert(!session.catalog.select_category_by_name("Recommended")); assert(session.catalog.visible().size() == 3); assert(controller.open_detail() && session.screen == Screen::Detail); @@ -72,7 +74,9 @@ int main() assert(session.catalog.current_category_name() == "Tools"); assert(!session.catalog.select_category_by_name("Installed")); controller.select_adjacent_category(1); - assert(session.catalog.current_category_name() == "Recommended"); + assert(session.catalog.current_category_name() == "All"); + controller.select_adjacent_category(-1); + assert(session.catalog.current_category_name() == "Tools"); session.catalog.select_category_by_name("All"); session.catalog.rebuild_visible(); @@ -105,6 +109,7 @@ int main() summary.apps[1].installed = true; controller.apply_summary(summary); + assert((session.catalog.categories() == std::vector{"All", "Installed", "Tools"})); assert(session.catalog.select_category_by_name("Installed")); session.catalog.rebuild_visible(); assert(session.catalog.current_category_name() == "Installed"); @@ -129,5 +134,21 @@ int main() controller.apply_summary(summary); assert(session.catalog.current_category_name() == "Tools"); + // Older summaries must not restore the retired synthetic category. + summary.categories = {"Recommended", "All", "Installed", "Tools", "Recommended"}; + controller.apply_summary(summary); + assert((session.catalog.categories() == std::vector{"All", "Tools"})); + assert(session.catalog.current_category_name() == "Tools"); + assert(!session.catalog.select_category_by_name("Recommended")); + assert(session.catalog.apps()[0].recommended); + + session.catalog.categories().insert(session.catalog.categories().begin(), "Recommended"); + assert(session.catalog.select_category_by_name("Recommended")); + summary.categories.clear(); + controller.apply_summary(summary); + assert(session.catalog.current_category_name() == "All"); + assert((session.catalog.categories() == std::vector{"All", "Tools"})); + assert(session.catalog.visible().size() == 3); + std::cout << "catalog controller tests passed\n"; } diff --git a/tests/test_catalog_state.cpp b/tests/test_catalog_state.cpp index 996f043..8b3bea9 100644 --- a/tests/test_catalog_state.cpp +++ b/tests/test_catalog_state.cpp @@ -11,7 +11,9 @@ int main() { appstore_ui::CatalogState state; - assert(state.current_category_name() == "Recommended"); + assert(state.current_category_name() == "All"); + assert(state.categories() == std::vector{"All"}); + assert(!state.select_category_by_name("Recommended")); appstore::StoreApp recommended; recommended.id = "recommended"; @@ -24,8 +26,10 @@ int main() state.apps() = {recommended, utility}; state.rebuild_visible(); - assert(state.visible().size() == 1); + assert(state.visible().size() == 2); assert(state.selected_app() && state.selected_app()->id == "recommended"); + assert(state.apps()[0].recommended); + assert(!state.apps()[1].recommended); state.select_default_category(); state.rebuild_visible(); diff --git a/tests/test_native_backend.cpp b/tests/test_native_backend.cpp index f3d1d89..440f99c 100644 --- a/tests/test_native_backend.cpp +++ b/tests/test_native_backend.cpp @@ -142,11 +142,25 @@ static void registry_cases() { CHECK(call({"--set-region","moon"}).rc!=0); CHECK(call({"--set-region","CN"}).rc==0); CHECK(has(call({"--registry-config"}),"CONFIG\tCN\tCN\t1")); CHECK(call({"--set-region","default"}).rc==0); Result s=call({"--sync"}); CHECK(s.rc==0&&has(s,"SYNC\t1\t0\t0\t2")); - Result sum=call({"--summary"}); CHECK(has(sum,"META\t1\t2 apps/1 registries")); CHECK(has(sum,"CAT\tUtilities")); CHECK(has(sum,"CAT\tInstalled")); - CHECK(has(sum,"APP\tapp-id\tDemo Local\t1.2.0\tUtilities")); CHECK(has(sum,"\tTester\thttps://example.invalid/source\t")); + Result sum=call({"--summary"}); CHECK(has(sum,"META\t1\t2 apps/1 registries")); + CHECK(has(sum,"CAT\tAll\nCAT\tInstalled\nCAT\tUtilities\nCAT\tTools\n")); + CHECK(!has(sum,"CAT\tRecommended\n")); + CHECK(has(sum,"APP\tapp-id\tDemo Local\t1.2.0\tUtilities\t0\t1\t")); + CHECK(has(sum,"APP\tblocked-id\tDemo Local\t1.2.0\tUtilities\t0\t0\t")); + CHECK(has(sum,"\tapproved\t1\t")); CHECK(has(sum,"\tpending\t0\t")); + CHECK(has(sum,"\tTester\thttps://example.invalid/source\t")); CHECK(has(sum,"Localized summary\\nFull detailed description")); // Screenshot count, then the permissions bit set: network (1) and camera (4). CHECK(has(sum,"\tdemo-package\t0\t5")); + const json original_registry = load(root/"registry.json"); + json legacy_categories = original_registry; + legacy_categories["apps"][0]["categories"].push_back("Recommended"); + save(root/"registry.json", legacy_categories); + CHECK(call({"--sync"}).rc==0); + Result legacy_summary=call({"--summary"}); + CHECK(!has(legacy_summary,"CAT\tRecommended\n")); + CHECK(has(legacy_summary,"\tUtilities\x1fTools\x1fRecommended\t")); + save(root/"registry.json", original_registry); CHECK(call({"--clear-registry-cache"}).rc==0); setenv("FAKE_DROP_DURING_ASSETS","1",1); Result dropped=call({"--sync"}); From bfed173691069d41ad97b25f2e856ddff77ca69c Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:21:20 +0300 Subject: [PATCH 14/19] feat(store): update apps from the list and page details with the labeled keys --- main/ui/appstore.cpp | 3 +- main/ui/appstore_input_controller.cpp | 28 +++++-- main/ui/appstore_shortcut_bar.cpp | 5 +- main/ui/appstore_view_model_factory.cpp | 1 + main/ui/appstore_view_models.hpp | 1 + main/ui/detail_action_controller.cpp | 11 ++- main/ui/detail_action_controller.hpp | 2 + main/ui/detail_media_state.cpp | 7 +- main/ui/detail_media_state.hpp | 1 + tests/test_appstore_input_controller.cpp | 89 ++++++++++++++++++++-- tests/test_appstore_view_model_factory.cpp | 15 ++++ tests/test_detail_action_controller.cpp | 29 +++++++ tests/test_detail_media_state.cpp | 4 + 13 files changed, 177 insertions(+), 19 deletions(-) diff --git a/main/ui/appstore.cpp b/main/ui/appstore.cpp index 16c7ebb..1c88765 100644 --- a/main/ui/appstore.cpp +++ b/main/ui/appstore.cpp @@ -285,8 +285,7 @@ void AppStoreApp::navigate_back() g_runtime.session.screen = Screen::Home; break; case Screen::Confirm: - g_runtime.session.screen = Screen::Detail; - g_runtime.session.confirmation.reset(); + detail_actions_.cancel_confirmation(); break; case Screen::Progress: if (g_runtime.package_jobs.state().running || g_runtime.package_jobs.state().pending_start) { diff --git a/main/ui/appstore_input_controller.cpp b/main/ui/appstore_input_controller.cpp index 407d267..33939dd 100644 --- a/main/ui/appstore_input_controller.cpp +++ b/main/ui/appstore_input_controller.cpp @@ -11,6 +11,7 @@ #include "keyboard_input.h" #include "startup_network_flow.hpp" +#include #include namespace appstore_ui { @@ -75,6 +76,8 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) } else if (session_.screen == Screen::Home || session_.screen == Screen::StartupSync) { session_.exit_hint_visible = true; + } else if (session_.screen == Screen::Confirm) { + detail_.cancel_confirmation(); } else if (actions_.navigate_back) { actions_.navigate_back(); } @@ -140,7 +143,9 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) catalog_.open_search(); else if (matches(key, '7', KEY_7)) { appstore::StoreApp *app = session_.catalog.selected_app(); - if (app && appstore::can_install_app(*app)) + if (app && appstore::can_upgrade_app(*app)) + detail_.upgrade(app); + else if (app && appstore::can_install_app(*app)) detail_.start_confirmation(app->installed ? "reinstall" : "install"); else session_.status.value() = app ? "Only approved apps can install" : "No selected app"; @@ -155,17 +160,26 @@ void AppStoreInputController::handle(const AppStoreKeyEvent &key, uint32_t now) case Screen::Detail: { appstore::StoreApp *app = catalog_.ensure_selected(); const bool up = key.code == KEY_UP || key.code == KEY_F || key.ch == 'f'; - if (up || key.code == KEY_DOWN || key.code == KEY_X || key.ch == 'x') { + const bool page_up = key.ch == 'z' || key.ch == 'l' || key.code == KEY_PAGEUP; + const bool page_down = key.ch == 'c' || key.ch == 'm' || key.code == KEY_PAGEDOWN; + const bool home = key.ch == 'k' || key.code == KEY_HOME; + const bool end = key.ch == 'n' || key.code == KEY_END; + if (up || key.code == KEY_DOWN || key.code == KEY_X || key.ch == 'x' || + page_up || page_down || home || end) { // Rebuilding the page takes longer than the key repeat interval, // so move the drawn page unless a status toast has to be cleared. const bool toast = !session_.status.value().empty(); - detail_.scroll_page(up ? -1 : 1, now); + if (home) detail_.scroll_to(0, now); + else if (end) detail_.scroll_to(INT_MAX, now); + else if (page_up || page_down) { + constexpr int viewport_height = 129; + const int steps = (page_up ? -1 : 1) * + ((viewport_height + DetailMediaState::kPageStep - 1) / + DetailMediaState::kPageStep); + detail_.scroll_page(steps, now); + } else detail_.scroll_page(up ? -1 : 1, now); if (!toast && actions_.scroll_detail && actions_.scroll_detail()) return; } - else if (key.code == KEY_LEFT || key.code == KEY_Z || key.ch == 'z') - detail_.cycle_screenshot(-1, now); - else if (key.code == KEY_RIGHT || key.code == KEY_C || key.ch == 'c') - detail_.cycle_screenshot(1, now); else if (matches(key, '4', KEY_4) || matches(key, 'b', KEY_B)) session_.screen = Screen::Home; else if (matches(key, '5', KEY_5)) diff --git a/main/ui/appstore_shortcut_bar.cpp b/main/ui/appstore_shortcut_bar.cpp index 0e64382..4742ff4 100644 --- a/main/ui/appstore_shortcut_bar.cpp +++ b/main/ui/appstore_shortcut_bar.cpp @@ -34,7 +34,8 @@ void AppStoreShortcutBar::render_catalog(lv_obj_t *root, shortcut_label(root, 104, "share", 0x168CE5); shortcut_label(root, 160, "search", 0x7ED957); if (app && appstore::can_install_app(*app)) - shortcut_label(root, 216, app->installed ? "reinstall" : "install", 0xB069FF); + shortcut_label(root, 216, appstore::can_upgrade_app(*app) ? "update" : + (app->installed ? "reinstall" : "install"), 0xB069FF); if (app) shortcut_label(root, 272, "detail", 0xFF8A2A); } @@ -49,7 +50,7 @@ void AppStoreShortcutBar::render_detail(lv_obj_t *root, const std::string &app_d if (appstore::can_reinstall_app(app)) shortcut_label(root, 160, "reinstall", 0xB069FF); if (appstore::can_upgrade_app(app)) - shortcut_label(root, 216, "upgrade", 0xB069FF); + shortcut_label(root, 216, "update", 0xB069FF); if (app.installed) shortcut_label(root, 272, "remove", 0xFF5B4A); } diff --git a/main/ui/appstore_view_model_factory.cpp b/main/ui/appstore_view_model_factory.cpp index 5a88111..6ddfb29 100644 --- a/main/ui/appstore_view_model_factory.cpp +++ b/main/ui/appstore_view_model_factory.cpp @@ -117,6 +117,7 @@ CatalogDisplayViewModel AppStoreViewModelFactory::catalog( model.empty_message = session_.catalog.current_category_name() == "Installed" ? "No installed apps" : "No apps"; if (const auto *app = session_.catalog.selected_app()) { + model.update_available = can_upgrade_app(*app); model.name = single_line(app->name); model.version = single_line(app->version.empty() ? "-" : app->version); model.author = single_line(app->author.empty() ? "-" : app->author); diff --git a/main/ui/appstore_view_models.hpp b/main/ui/appstore_view_models.hpp index c67fb68..916aec3 100644 --- a/main/ui/appstore_view_models.hpp +++ b/main/ui/appstore_view_models.hpp @@ -36,6 +36,7 @@ struct CatalogDisplayViewModel { int selected_index = 0; int app_count = 0; int total_count = 0; + bool update_available = false; bool show_empty = false; bool show_status = false; std::string status; diff --git a/main/ui/detail_action_controller.cpp b/main/ui/detail_action_controller.cpp index 7292c26..a476ada 100644 --- a/main/ui/detail_action_controller.cpp +++ b/main/ui/detail_action_controller.cpp @@ -43,6 +43,7 @@ void DetailActionController::start_confirmation(const std::string &action) session_.status.value() = "Plan check already running"; return; } + confirmation_origin_ = session_.screen == Screen::Home ? Screen::Home : Screen::Detail; session_.confirmation.begin(action, app->id); if (action == "uninstall") { session_.confirmation.lines() = {"Delete " + app->name, @@ -88,7 +89,8 @@ void DetailActionController::remove(StoreApp *app) void DetailActionController::cancel_confirmation() { - session_.screen = Screen::Detail; + session_.screen = confirmation_origin_; + confirmation_origin_ = Screen::Detail; session_.confirmation.reset(); } @@ -140,6 +142,7 @@ bool DetailActionController::apply_plan_result(const std::string &action, return false; } if (rc == 0 && apply_plan(output)) { + confirmation_origin_ = origin_screen == Screen::Home ? Screen::Home : Screen::Detail; session_.status.value().clear(); session_.screen = Screen::Confirm; return true; @@ -206,4 +209,10 @@ void DetailActionController::scroll_page(int delta, uint32_t now) session_.status.value().clear(); } +void DetailActionController::scroll_to(int target, uint32_t now) +{ + session_.detail_media.scroll_to(target, now); + session_.status.value().clear(); +} + } // namespace appstore_ui diff --git a/main/ui/detail_action_controller.hpp b/main/ui/detail_action_controller.hpp index e1f4ce0..99f56be 100644 --- a/main/ui/detail_action_controller.hpp +++ b/main/ui/detail_action_controller.hpp @@ -43,6 +43,7 @@ class DetailActionController bool open_screenshots(uint32_t now); void ensure_screenshots(); void scroll_page(int delta, uint32_t now); + void scroll_to(int target, uint32_t now); private: appstore::StoreApp *selected_app(); @@ -53,6 +54,7 @@ class DetailActionController PlanStarter start_plan_; PlanRunning plan_running_; ScreenshotStarter start_screenshots_; + Screen confirmation_origin_ = Screen::Detail; }; } // namespace appstore_ui diff --git a/main/ui/detail_media_state.cpp b/main/ui/detail_media_state.cpp index c0f0802..b861ed5 100644 --- a/main/ui/detail_media_state.cpp +++ b/main/ui/detail_media_state.cpp @@ -51,7 +51,12 @@ void DetailMediaState::normalize_page(const std::string &app_id, int content_hei void DetailMediaState::scroll_page(int delta, uint32_t now) { - const int target = std::clamp(page_scroll_ + delta * kPageStep, 0, page_max_scroll_); + scroll_to(page_scroll_ + delta * kPageStep, now); +} + +void DetailMediaState::scroll_to(int target, uint32_t now) +{ + target = std::clamp(target, 0, page_max_scroll_); if (target == page_scroll_) return; // Start from the drawn position so key repeat keeps one continuous motion. page_scroll_from_ = page_scroll_at(now); diff --git a/main/ui/detail_media_state.hpp b/main/ui/detail_media_state.hpp index f23eca2..8e2939e 100644 --- a/main/ui/detail_media_state.hpp +++ b/main/ui/detail_media_state.hpp @@ -21,6 +21,7 @@ class DetailMediaState void cycle_image(int delta, int image_count); void normalize_page(const std::string &app_id, int content_height, int viewport_height); void scroll_page(int delta, uint32_t now); + void scroll_to(int target, uint32_t now); // Target offset; the page glides there from where it was drawn. int page_scroll() const { return page_scroll_; } int page_max_scroll() const { return page_max_scroll_; } diff --git a/tests/test_appstore_input_controller.cpp b/tests/test_appstore_input_controller.cpp index ac172c3..e360b7e 100644 --- a/tests/test_appstore_input_controller.cpp +++ b/tests/test_appstore_input_controller.cpp @@ -88,8 +88,15 @@ int main() AppStoreTaskService tasks(coordinator, workers, [](const std::vector &, int *rc) { *rc = 0; return std::string{}; }); CatalogController catalog(session, share_code, []() {}); - DetailActionController detail(session, package_job, [](const std::string &, const std::string &) {}, - []() { return false; }); + std::string planned_action; + std::string planned_app; + int plans = 0; + DetailActionController detail(session, package_job, + [&](const std::string &action, const std::string &app_id) { + planned_action = action; + planned_app = app_id; + ++plans; + }, []() { return false; }); RegistryController registry( session, tasks, package_job, {[](const std::string &) { return appstore::RegistryData{}; }, @@ -227,12 +234,28 @@ int main() assert(page_moves == 3 && renders == renders_before_scroll + 2); page_drawn = true; session.catalog.selected_app()->images = "icon,one,two"; - input.handle({KEY_C, 0, 'c'}, 188); - assert(session.detail_media.image_index() == 1 && session.screen == Screen::Detail); - input.handle({KEY_Z, 0, 'z'}, 189); - assert(session.detail_media.image_index() == 0); + session.screen = Screen::Detail; + session.detail_media.normalize_page(detail_id, 1000, 129); + input.handle({0, 0, 'c'}, 200); + const int page = ((129 + 24 - 1) / 24) * 24; + assert(session.detail_media.page_scroll() == page && session.screen == Screen::Detail); + input.handle({0, 0, 'z'}, 400); + assert(session.detail_media.page_scroll() == 0); + input.handle({0, 0, 'm'}, 600); + assert(session.detail_media.page_scroll() == page); + input.handle({0, 0, 'l'}, 800); + assert(session.detail_media.page_scroll() == 0); + input.handle({0, 0, 'k'}, 1000); + assert(session.detail_media.page_scroll() == 0); + input.handle({0, 0, 'n'}, 1200); + assert(session.detail_media.page_scroll() == session.detail_media.page_max_scroll() && + session.detail_media.image_index() == 0); input.handle({KEY_5}, 190); assert(session.screen == Screen::Screenshots); + input.handle({KEY_C, 0, 'c'}, 191); + assert(session.detail_media.image_index() == 1); + input.handle({KEY_Z, 0, 'z'}, 192); + assert(session.detail_media.image_index() == 0); session.screen = Screen::Detail; const size_t sounds_before_back = sounds.size(); input.handle({KEY_ESC}, 200); @@ -269,6 +292,60 @@ int main() input.handle({KEY_B}, 510); assert(backs == 3); + auto *selected = session.catalog.selected_app(); + selected->installable = true; + selected->installed = true; + selected->version = "2.0"; + selected->installed_version = "1.0"; + const std::string plan = "PLAN\t" + selected->id + "\tDemo\t2.0\t12 MB\t80 MB\tlibfoo\t\n"; + const int backs_before_confirm = backs; + uint32_t tick = 600; + for (const auto origin : {Screen::Home, Screen::Detail}) { + for (const auto cancel : {KEY_B, KEY_N, KEY_ENTER, KEY_ESC}) { + session.screen = origin; + const int plans_before = plans; + input.handle({KEY_7}, tick++); + assert(plans == plans_before + 1); + assert(planned_action == "upgrade" && planned_app == selected->id); + assert(session.screen == origin); + assert(detail.apply_plan_result(planned_action, planned_app, origin, 0, plan)); + assert(session.screen == Screen::Confirm); + session.confirmation.focus() = 1; + input.handle({static_cast(cancel)}, tick++); + if (cancel == KEY_ESC) + input.handle({KEY_ESC, 0, 0, true}, tick++); + assert(session.screen == origin); + assert(session.confirmation.action().empty()); + assert(!session.exit_hint_visible && backs == backs_before_confirm); + } + } + session.screen = Screen::Detail; + input.handle({KEY_6}, tick++); + assert(planned_action == "reinstall"); + detail.cancel_confirmation(); + assert(session.screen == Screen::Detail); + + session.screen = Screen::Home; + selected->installed_version = selected->version; + input.handle({KEY_7}, tick++); + assert(planned_action == "reinstall"); + detail.cancel_confirmation(); + assert(session.screen == Screen::Home); + selected->installed = false; + input.handle({KEY_7}, tick++); + assert(planned_action == "install"); + detail.cancel_confirmation(); + assert(session.screen == Screen::Home); + selected->installable = false; + const int plans_before_blocked = plans; + input.handle({KEY_7}, tick++); + assert(plans == plans_before_blocked); + assert(session.status.value() == "Only approved apps can install"); + session.catalog.visible().clear(); + input.handle({KEY_7}, tick++); + assert(plans == plans_before_blocked && session.status.value() == "No selected app"); + session.catalog.rebuild_visible(); + // Root Esc opens a modal; dismissing it must not trigger the key's action. session.screen = Screen::Home; input.handle({KEY_ESC}, 1000); diff --git a/tests/test_appstore_view_model_factory.cpp b/tests/test_appstore_view_model_factory.cpp index 217a797..9018f3e 100644 --- a/tests/test_appstore_view_model_factory.cpp +++ b/tests/test_appstore_view_model_factory.cpp @@ -24,6 +24,10 @@ std::vector wrap_display_text(std::string text, int) } bool can_install_app(const StoreApp &app) { return app.installable; } +bool can_upgrade_app(const StoreApp &app) +{ + return app.installable && app.installed && app.version != app.installed_version; +} std::string review_label(const StoreApp &app) { return app.review_status; } std::string job_action_label(const std::string &action) { @@ -90,6 +94,16 @@ int main() assert(catalog.version == "2.0"); assert(catalog.size == "19.6 MB"); assert(catalog.updated == "2026-07-23"); + assert(catalog.update_available); + app.installed_version = app.version; + assert(!factory.catalog(100, 6000).update_available); + app.installed_version = "1.0"; + app.installable = false; + assert(!factory.catalog(100, 6000).update_available); + app.installable = true; + app.installed = false; + assert(!factory.catalog(100, 6000).update_available); + app.installed = true; session.catalog.categories().push_back("Installed"); session.catalog.select_category_by_name("Installed"); session.catalog.rebuild_visible(); @@ -99,6 +113,7 @@ int main() session.catalog.rebuild_visible(); catalog = factory.catalog(100, 6000); assert(catalog.show_empty && catalog.empty_message == "No installed apps"); + assert(!catalog.update_available); app.installed = true; app.name = "Line one\nLine two"; diff --git a/tests/test_detail_action_controller.cpp b/tests/test_detail_action_controller.cpp index 3236618..e5971f8 100644 --- a/tests/test_detail_action_controller.cpp +++ b/tests/test_detail_action_controller.cpp @@ -102,6 +102,35 @@ int main() controller.cancel_confirmation(); assert(session.screen == Screen::Detail && session.confirmation.action().empty()); + for (const auto origin : {Screen::Home, Screen::Detail}) { + session.screen = origin; + controller.upgrade(session.catalog.selected_app()); + assert(started_action == "upgrade" && started_app == "demo"); + assert(session.screen == origin); + assert(controller.apply_plan_result("upgrade", "demo", origin, 0, plan)); + controller.cancel_confirmation(); + assert(session.screen == origin && session.confirmation.action().empty()); + controller.upgrade(session.catalog.selected_app()); + assert(controller.apply_plan_result("upgrade", "demo", origin, 0, plan)); + assert(controller.execute_confirmation(1500)); + assert(package_job.action == "upgrade" && package_job.app_id == "demo"); + assert(package_job.running && package_job.pending_start); + assert(session.screen == Screen::Progress); + package_job.reset(); + } + + session.screen = Screen::Home; + controller.upgrade(session.catalog.selected_app()); + assert(!controller.apply_plan_result("upgrade", "demo", Screen::Home, 1, "Plan failed")); + assert(session.screen == Screen::Home && session.status.value() == "Plan failed"); + session.catalog.selected_app()->id = "other"; + assert(!controller.apply_plan_result("upgrade", "demo", Screen::Home, 0, plan)); + assert(session.screen == Screen::Home && session.confirmation.action().empty()); + session.catalog.selected_app()->id = "demo"; + session.screen = Screen::Detail; + assert(!controller.apply_plan_result("upgrade", "demo", Screen::Home, 0, plan)); + assert(session.screen == Screen::Detail && session.confirmation.action().empty()); + session.screen = Screen::Home; assert(!controller.apply_plan_result("upgrade", "demo", Screen::Detail, 0, plan)); assert(session.status.value() == "Install plan expired"); diff --git a/tests/test_detail_media_state.cpp b/tests/test_detail_media_state.cpp index 8038aea..afd6424 100644 --- a/tests/test_detail_media_state.cpp +++ b/tests/test_detail_media_state.cpp @@ -37,6 +37,10 @@ int main() state.scroll_page(10, 5000); assert(state.page_scroll() == 0 && state.page_glide_remaining(5000) == 0); state.normalize_page("c", 400, 129); + state.scroll_to(140, 6000); + assert(state.page_scroll() == 140); + state.scroll_to(0, 6100); + assert(state.page_scroll() == 0); state.scroll_page(1, 0xffffffa0U); assert(state.page_glide_remaining(0x14U) == 64 && state.page_scroll_at(0x14U) == 23); assert(state.needs_loading("a")); From a5691f7ae4b18429c6214d4ae6952f75cc8cba3d Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:21:24 +0300 Subject: [PATCH 15/19] feat(store): stack full-width screenshots and label the permissions row --- main/ui/appstore_image_renderer.cpp | 22 +-- main/ui/appstore_image_renderer.hpp | 7 +- main/ui/appstore_pages.cpp | 210 ++++++++++++++++------------ main/ui/appstore_pages.hpp | 8 +- 4 files changed, 135 insertions(+), 112 deletions(-) diff --git a/main/ui/appstore_image_renderer.cpp b/main/ui/appstore_image_renderer.cpp index 524ce69..b93760c 100644 --- a/main/ui/appstore_image_renderer.cpp +++ b/main/ui/appstore_image_renderer.cpp @@ -16,7 +16,6 @@ namespace appstore_ui { void AppStoreImageRenderer::begin_frame() { sources_.clear(); - sources_.reserve(12); } const char *AppStoreImageRenderer::retain_source(std::string source) @@ -80,15 +79,15 @@ bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app #endif } -bool AppStoreImageRenderer::draw_thumbnail(lv_obj_t *root, const std::string &path, int x, int y) +int AppStoreImageRenderer::draw_thumbnail(lv_obj_t *root, const std::string &path, int x, int y) { #if LV_USE_LODEPNG && LV_USE_FS_POSIX - if (path.empty()) return false; - constexpr int width = 160, height = 85; + if (path.empty()) return 0; + constexpr int width = 300; lv_obj_t *clip = lv_obj_create(root); lv_obj_remove_style_all(clip); lv_obj_set_pos(clip, x, y); - lv_obj_set_size(clip, width, height); + lv_obj_set_width(clip, width); lv_obj_clear_flag(clip, LV_OBJ_FLAG_SCROLLABLE); lv_obj_set_style_bg_color(clip, lv_color_hex(0x000000), 0); lv_obj_set_style_bg_opa(clip, LV_OPA_COVER, 0); @@ -99,15 +98,18 @@ bool AppStoreImageRenderer::draw_thumbnail(lv_obj_t *root, const std::string &pa const int image_height = lv_obj_get_height(image); if (image_width <= 0 || image_height <= 0) { lv_obj_delete(clip); - return false; + return 0; } - const int scale = std::max(1, std::min(width * 256 / image_width, height * 256 / image_height)); + const int scale = std::clamp(width * 256 / image_width, 1, 65535); + const int height = std::max(1, (image_height * scale + 255) / 256); + lv_obj_set_height(clip, height); + lv_image_set_pivot(image, 0, 0); lv_image_set_scale(image, static_cast(scale)); - lv_obj_set_pos(image, (width - image_width) / 2, (height - image_height) / 2); - return true; + lv_obj_set_pos(image, (width - image_width * scale / 256) / 2, 0); + return height; #else (void)root; (void)path; (void)x; (void)y; - return false; + return 0; #endif } diff --git a/main/ui/appstore_image_renderer.hpp b/main/ui/appstore_image_renderer.hpp index e0bc5a9..efa5735 100644 --- a/main/ui/appstore_image_renderer.hpp +++ b/main/ui/appstore_image_renderer.hpp @@ -10,7 +10,7 @@ #include "lvgl/lvgl.h" #include -#include +#include namespace appstore_ui { @@ -23,11 +23,12 @@ class AppStoreImageRenderer bool draw_app_icon(lv_obj_t *root, const std::string &app_dir, const appstore::StoreApp &app); bool draw_screenshot(lv_obj_t *root, const std::string &path); - bool draw_thumbnail(lv_obj_t *root, const std::string &path, int x, int y); + // Returns the aspect-preserving row height, or zero when decoding fails. + int draw_thumbnail(lv_obj_t *root, const std::string &path, int x, int y); private: const char *retain_source(std::string source); - std::vector sources_; + std::deque sources_; }; } // namespace appstore_ui diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index 8ef5913..f7baf76 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -143,25 +143,35 @@ lv_obj_t *edge_fade(lv_obj_t *root, int y, int height, uint32_t color, bool towa return fade; } -constexpr int kPermissionSize = 14; +constexpr int kPermissionDesignSize = 14; -void permission_badge(lv_obj_t *parent, int x, int y, uint32_t color) +// The marks are drawn on a 14 px grid and scaled to the label's line height. +int permission_px(int value, int size) { - constexpr int size = kPermissionSize; - lv_obj_t *badge = box(parent, x, y, size, size, color, color, 1, 4, LV_OPA_20); + return value * size / kPermissionDesignSize; +} + +int permission_span(int value, int size) +{ + return std::max(1, permission_px(value, size)); +} + +void permission_badge(lv_obj_t *parent, int x, int y, int size, uint32_t color) +{ + lv_obj_t *badge = box(parent, x, y, size, size, color, color, 1, + permission_span(4, size), LV_OPA_20); lv_obj_set_style_border_opa(badge, LV_OPA_40, 0); } -// Filled mark, so the glyph stays readable inside a 14 px badge. void permission_fill(lv_obj_t *parent, int x, int y, int w, int h, uint32_t color, int radius = 0) { box(parent, x, y, w, h, color, color, 0, radius); } // One badge per declared permission, in the registry's order. -void permission_icons(lv_obj_t *parent, int x, int y, uint32_t permissions) +void permission_icons(lv_obj_t *parent, int x, int y, int size, uint32_t permissions) { - constexpr int step = 18; + const int step = size + 4; constexpr uint32_t color = 0x8B949E; using appstore::kPermissionBackground; using appstore::kPermissionCamera; @@ -170,55 +180,83 @@ void permission_icons(lv_obj_t *parent, int x, int y, uint32_t permissions) using appstore::kPermissionImu; using appstore::kPermissionMicrophone; using appstore::kPermissionNetwork; - struct Item { uint32_t bit; void (*draw)(lv_obj_t *, int, int); }; + struct Item { uint32_t bit; void (*draw)(lv_obj_t *, int, int, int); }; const Item items[] = { - {kPermissionNetwork, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 6, y + 2, 2, 3, color); - permission_fill(parent, x + 4, y + 4, 6, 2, color); - permission_fill(parent, x + 6, y + 6, 2, 6, color); + {kPermissionNetwork, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(6, size), y + permission_px(2, size), + permission_span(2, size), permission_span(3, size), color); + permission_fill(parent, x + permission_px(4, size), y + permission_px(4, size), + permission_span(6, size), permission_span(2, size), color); + permission_fill(parent, x + permission_px(6, size), y + permission_px(6, size), + permission_span(2, size), permission_span(6, size), color); }}, - {kPermissionMicrophone, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 5, y + 2, 4, 6, color, 2); - permission_fill(parent, x + 3, y + 6, 2, 3, color); - permission_fill(parent, x + 9, y + 6, 2, 3, color); - permission_fill(parent, x + 3, y + 8, 8, 2, color); - permission_fill(parent, x + 6, y + 10, 2, 2, color); + {kPermissionMicrophone, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(5, size), y + permission_px(2, size), + permission_span(4, size), permission_span(6, size), color, + permission_span(2, size)); + permission_fill(parent, x + permission_px(3, size), y + permission_px(6, size), + permission_span(2, size), permission_span(3, size), color); + permission_fill(parent, x + permission_px(9, size), y + permission_px(6, size), + permission_span(2, size), permission_span(3, size), color); + permission_fill(parent, x + permission_px(3, size), y + permission_px(8, size), + permission_span(8, size), permission_span(2, size), color); + permission_fill(parent, x + permission_px(6, size), y + permission_px(10, size), + permission_span(2, size), permission_span(2, size), color); }}, - {kPermissionCamera, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 2, y + 5, 10, 6, color, 1); - permission_fill(parent, x + 4, y + 3, 3, 2, color); - box(parent, x + 5, y + 6, 4, 4, 0x081010, 0x081010, 0, 2); + {kPermissionCamera, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(2, size), y + permission_px(5, size), + permission_span(10, size), permission_span(6, size), color, + permission_span(1, size)); + permission_fill(parent, x + permission_px(4, size), y + permission_px(3, size), + permission_span(3, size), permission_span(2, size), color); + box(parent, x + permission_px(5, size), y + permission_px(6, size), + permission_span(4, size), permission_span(4, size), 0x081010, 0x081010, 0, + permission_span(2, size)); }}, - {kPermissionImu, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 3, y + 3, 8, 8, color, 4); - box(parent, x + 5, y + 5, 4, 4, 0x081010, 0x081010, 0, 2); + {kPermissionImu, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(3, size), y + permission_px(3, size), + permission_span(8, size), permission_span(8, size), color, + permission_span(4, size)); + box(parent, x + permission_px(5, size), y + permission_px(5, size), + permission_span(4, size), permission_span(4, size), 0x081010, 0x081010, 0, + permission_span(2, size)); }}, - {kPermissionHardware, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 3, y + 5, 8, 6, color, 1); - permission_fill(parent, x + 5, y + 2, 1, 3, color); - permission_fill(parent, x + 8, y + 2, 1, 3, color); + {kPermissionHardware, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(3, size), y + permission_px(5, size), + permission_span(8, size), permission_span(6, size), color, + permission_span(1, size)); + permission_fill(parent, x + permission_px(5, size), y + permission_px(2, size), + permission_span(1, size), permission_span(3, size), color); + permission_fill(parent, x + permission_px(8, size), y + permission_px(2, size), + permission_span(1, size), permission_span(3, size), color); }}, - {kPermissionBackground, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 3, y + 3, 8, 2, color); - permission_fill(parent, x + 6, y + 5, 2, 6, color); + {kPermissionBackground, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(3, size), y + permission_px(3, size), + permission_span(8, size), permission_span(2, size), color); + permission_fill(parent, x + permission_px(6, size), y + permission_px(5, size), + permission_span(2, size), permission_span(6, size), color); }}, - {kPermissionDisplay, [](lv_obj_t *parent, int x, int y) { - permission_badge(parent, x, y, color); - permission_fill(parent, x + 2, y + 3, 10, 6, color, 1); - permission_fill(parent, x + 6, y + 9, 2, 2, color); - permission_fill(parent, x + 4, y + 11, 6, 1, color); + {kPermissionDisplay, [](lv_obj_t *parent, int x, int y, int size) { + permission_badge(parent, x, y, size, color); + permission_fill(parent, x + permission_px(2, size), y + permission_px(3, size), + permission_span(10, size), permission_span(6, size), color, + permission_span(1, size)); + permission_fill(parent, x + permission_px(6, size), y + permission_px(9, size), + permission_span(2, size), permission_span(2, size), color); + permission_fill(parent, x + permission_px(4, size), y + permission_px(11, size), + permission_span(6, size), permission_span(1, size), color); }}, }; int drawn = 0; for (const auto &item : items) { if ((permissions & item.bit) == 0) continue; - item.draw(parent, x + drawn * step, y); + item.draw(parent, x + drawn * step, y, size); ++drawn; } } @@ -406,28 +444,6 @@ int glyph_middle(const lv_font_t *font, uint32_t letter) return font->line_height - font->base_line - glyph.ofs_y - glyph.box_h / 2; } -void draw_arrow_key(lv_obj_t *parent, ArrowKey arrow, int center_x, int center_y, - int width, int height) -{ - const int x = center_x - width / 2; - // Raised look: a lighter top fading to a darker bottom, with a hairline edge. - lv_obj_t *button = box(parent, x, center_y - height / 2, width, height, 0x34424D, - 0x4E5D69, 1, 5); - lv_obj_set_style_bg_grad_color(button, lv_color_hex(0x182127), 0); - lv_obj_set_style_bg_grad_dir(button, LV_GRAD_DIR_VER, 0); - - // Solid triangles, in ArrowKey order: left, up, right, down. - static const char *const glyphs[] = {"\xE2\x97\x80", "\xE2\x96\xB2", "\xE2\x96\xB6", - "\xE2\x96\xBC"}; - static constexpr uint32_t codepoints[] = {0x25C0, 0x25B2, 0x25B6, 0x25BC}; - const int index = static_cast(arrow); - const lv_font_t *font = store_font(glyphs[index], 10); - lv_obj_t *glyph = label(parent, glyphs[index], x, - center_y - glyph_middle(font, codepoints[index]), width, - font->line_height, font, 0xFF7A45); - lv_obj_set_style_text_align(glyph, LV_TEXT_ALIGN_CENTER, 0); -} - lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, int width, int height, const lv_font_t *font, uint32_t color, HorizontalMarquee &state, const std::string &key, @@ -599,18 +615,21 @@ void CatalogDisplayPage::render(const PageRenderContext &context, label(root, model.empty_message, 137, 76, 178, 40, store_font(model.empty_message, 14), 0xFFFFFF, LV_LABEL_LONG_WRAP); } else { - marquee_label(root, model.name, 137, 62, 178, 27, store_font(model.name, 20, true), + marquee_label(root, model.name, 137, 58, 178, 27, store_font(model.name, 20, true), 0xFFFFFF, title_marquee_, model.name); - label(root, model.version, 137, 90, 66, 22, + label(root, model.version, 137, 86, 66, 20, store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - marquee_label(root, model.author, 207, 90, 108, 22, store_font(model.author, 14), + marquee_label(root, model.author, 207, 86, 108, 20, store_font(model.author, 14), 0xFFFFFF, author_marquee_, model.name + model.author); - label(root, model.size, 137, 110, 68, 22, + label(root, model.size, 137, 105, 68, 20, store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); - label(root, model.updated, 207, 110, 110, 22, + label(root, model.updated, 207, 105, 110, 20, store_font(model.updated, 14), 0xFFFFFF, LV_LABEL_LONG_DOT); + if (model.update_available) + label(root, "UPDATE AVAILABLE", 137, 126, 178, 11, + &lv_font_montserrat_10, 0xF0B429); } - if (model.show_status) scrolling_status_label(root, model.status, 110, 136, 205, 12); + if (model.show_status) scrolling_status_label(root, model.status, 110, 138, 205, 12); draw_shortcuts(); } @@ -690,7 +709,7 @@ void CatalogDisplayPage::render_search(const PageRenderContext &context, void AppDetailPage::render(const PageRenderContext &context, const AppDetailViewModel &model, DetailMediaState &media, const std::vector &screenshots, - const std::function &draw_thumbnail, + const std::function &draw_thumbnail, const std::function &draw_shortcuts) { context.prepare(); @@ -740,10 +759,6 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView label(document, model.state, 25, y, 285, 17, store_font(model.state, 14), app.installed ? 0xE6EDF3 : 0xB1BAC4, LV_LABEL_LONG_DOT); y += 23; - if (model.app.permissions != 0) { - permission_icons(document, 10, y, model.app.permissions); - y += kPermissionSize + 7; - } box(document, 10, y, 300, 1, 0x1E2A30, 0x1E2A30, 0); y += 7; lv_obj_t *description = label(document, model.description, 10, y, 300, LV_SIZE_CONTENT, @@ -755,26 +770,37 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView media.normalize_images(app.id, static_cast(screenshots.size())); if (!screenshots.empty()) { - const int index = media.image_index(); label(document, "SCREENSHOTS", 10, y, 150, 12, &lv_font_montserrat_10, 0x8B949E); - if (screenshots.size() > 1) { - lv_obj_t *count = label(document, std::to_string(index + 1) + "/" + - std::to_string(screenshots.size()), 250, y, 60, 12, - &lv_font_montserrat_10, 0x8B949E); - lv_obj_set_style_text_align(count, LV_TEXT_ALIGN_RIGHT, 0); + y += 16; + for (const auto &path : screenshots) { + const int height = draw_thumbnail(document, path, 10, y); + if (height > 0) { + y += height + 10; + } else { + label(document, "Screenshot unavailable", 10, y, 300, 14, + store_font("", 12), 0x8B949E); + y += 24; + } } - const int shot_y = y + 16; - // One complete 160 x 85 preview and a glimpse of the next image. - draw_thumbnail(document, screenshots[index], 20, shot_y); - if (screenshots.size() > 1) { - draw_thumbnail(document, screenshots[(index + 1) % screenshots.size()], 185, shot_y); - draw_arrow_key(document, ArrowKey::Left, 10, shot_y + 42); - draw_arrow_key(document, ArrowKey::Right, 311, shot_y + 42); - } - y = shot_y + 85 + 10; } y = detail_info_row(document, "PACKAGE", app.package.empty() ? "-" : app.package, y); y = detail_info_row(document, "CATEGORY", model.categories, y); + if (model.app.permissions != 0) { + // Match the info-row captions: same font, colour, and height. + const lv_font_t *permission_font = &lv_font_montserrat_10; + constexpr uint32_t caption_color = 0x8B949E; + constexpr int caption_height = 12; + const int size = permission_font->line_height; + lv_point_t caption_size = {}; + lv_text_get_size(&caption_size, "PERMISSIONS", permission_font, 0, 0, + LV_COORD_MAX, LV_TEXT_FLAG_NONE); + label(document, "PERMISSIONS", 10, y + 2, caption_size.x, caption_height, + permission_font, caption_color); + permission_icons(document, std::max(76, 10 + caption_size.x + 6), + y + 2 + glyph_middle(permission_font, 'P') - size / 2, + size, model.app.permissions); + y += std::max(caption_height, size) + 4; + } y += 6; lv_obj_set_height(document, y); media.normalize_page(app.id, y, viewport_height); diff --git a/main/ui/appstore_pages.hpp b/main/ui/appstore_pages.hpp index f41f54d..ae0639b 100644 --- a/main/ui/appstore_pages.hpp +++ b/main/ui/appstore_pages.hpp @@ -22,12 +22,6 @@ void render_exit_hint(lv_obj_t *root); // Middle of a glyph's ink, measured from the top of the font's line box. int glyph_middle(const lv_font_t *font, uint32_t letter); -enum class ArrowKey { Left, Up, Right, Down }; - -// A small raised button with a solid arrow, for on-screen navigation hints. -void draw_arrow_key(lv_obj_t *parent, ArrowKey arrow, int center_x, int center_y, - int width = 18, int height = 16); - // One line of text; when it does not fit, it bounces like APPLaunch's // selected title. Text that fits is placed according to align. lv_obj_t *marquee_label(lv_obj_t *parent, const std::string &text, int x, int y, @@ -90,7 +84,7 @@ class AppDetailPage : public AppStoreUiPage void render(const PageRenderContext &context, const AppDetailViewModel &model, DetailMediaState &media, const std::vector &screenshots, - const std::function &draw_thumbnail, + const std::function &draw_thumbnail, const std::function &draw_shortcuts); // Glides the drawn page to the media's scroll target without rebuilding // it. False when no detail page is drawn. From af254e1546be77e1dfdd17c80b494da5deea9862 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:21:24 +0300 Subject: [PATCH 16/19] docs(store): document list updates, category changes, and details navigation --- README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 79b747d..649fd41 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,8 @@ not supported. Existing saved custom sources are normalized to the selected built-in server, and the mode and effective server are persisted across restarts. On the home screen, use `Z/C` (left/right) to change category and `F/X` (up/down) -to select an app. Installed filters catalog apps by +to select an app. Categories include All, Installed, and the registry's app +categories; there is no Recommended category. Installed filters catalog apps by their actual package installation state and refreshes after package operations. The Installed category is hidden when empty; removing its last app returns the selection to All. Long names bounce like the selected APPLaunch title: they @@ -115,7 +116,10 @@ its original layout: the app icon on the left, name and metadata on the right, and plain-text number-key shortcuts along the bottom. Permission icons appear only on the app details page. Press `4` for settings, `5` for share code, `6` for search, `7` for -install/reinstall, and `8` or Enter for details. AppStore syncs the registry +install/reinstall, and `8` or Enter for details. When an installed app has an +available update, the list indicates it and shortcut `7` becomes **update**, +opening the upgrade confirmation directly without visiting details. +AppStore syncs the registry automatically when it starts. The startup screen names the current step (connecting, updating the catalog, loading artwork, preparing apps) above a progress bar with the registry's host, and `Tab` opens settings. If no @@ -136,16 +140,20 @@ and its sound keeps playing while the redraw waits, so the view keeps up and stops when the key is released. The detail page shows the app name, color-coded version, maintainer, size, -and update fields, declared permission icons, the install state, the complete -description, 160 x 85 screenshot previews loaded from the registry, and the -package and categories. `F/X` scrolls the whole content area with a short -glide, 24 pixels per press; holding the key scrolls continuously. The system +and update fields, the install state, and the complete description. Screenshots +follow the description in vertical rows, one image per row at nearly full screen +width (300 pixels), with aspect ratio preserved. Package and category information +follow the screenshots, then a matching PERMISSIONS caption and permission icons. +`F/X` scrolls the whole content area with a short glide, 24 pixels per press; +`Z/C` and `K/L` page up and down, and `N/M` jump to the start and end. Holding +a key scrolls continuously. The system bar and bottom actions stay fixed, and status messages appear just above the actions at any scroll position. Descriptions wrap without a height limit or -automatic scrolling. `Z/C` cycles screenshots; apps without screenshots have -no screenshot area. Detail actions are `4` back, -`6` install/reinstall, `7` upgrade, and `8` remove, shown when applicable. -The existing full-screen screenshot viewer remains accessible through `5`. +automatic scrolling. Apps without screenshots have no screenshot area. Detail actions are `4` back, +`6` install/reinstall, `7` update, and `8` remove, shown when applicable. +The existing full-screen screenshot viewer remains accessible through `5`, where +`Z/C` cycles images. On the details page itself those keys page through the +content. Registry entries must provide a Debian package download: From a2791cd97f814e4cb476020a830431564a308a14 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:33:03 +0300 Subject: [PATCH 17/19] fix(store): return to the home list after removing an app --- README.md | 1 + main/ui/package_operation_controller.cpp | 5 ++++- tests/test_package_operation_controller.cpp | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 649fd41..9b00bac 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ bar and bottom actions stay fixed, and status messages appear just above the actions at any scroll position. Descriptions wrap without a height limit or automatic scrolling. Apps without screenshots have no screenshot area. Detail actions are `4` back, `6` install/reinstall, `7` update, and `8` remove, shown when applicable. +After a successful removal the Store returns to the home list. The existing full-screen screenshot viewer remains accessible through `5`, where `Z/C` cycles images. On the details page itself those keys page through the content. diff --git a/main/ui/package_operation_controller.cpp b/main/ui/package_operation_controller.cpp index d438d54..5c65a8e 100644 --- a/main/ui/package_operation_controller.cpp +++ b/main/ui/package_operation_controller.cpp @@ -169,7 +169,10 @@ void PackageOperationController::finish(const std::string &output, int result_co job_.reset(); if (!dependencies_.exit_requested || !dependencies_.exit_requested()) { if (dependencies_.request_summary) dependencies_.request_summary(); - session_.screen = ok ? Screen::Detail : Screen::ErrorDialog; + const bool removed = action == "uninstall" || + output.find("UNINSTALLED") != std::string::npos; + session_.screen = !ok ? Screen::ErrorDialog : + (removed ? Screen::Home : Screen::Detail); } } diff --git a/tests/test_package_operation_controller.cpp b/tests/test_package_operation_controller.cpp index d03d93e..a32efe4 100644 --- a/tests/test_package_operation_controller.cpp +++ b/tests/test_package_operation_controller.cpp @@ -129,6 +129,7 @@ int main() controller.finish("PACKAGE_RESULT\tUNINSTALLED\tdemo\tDemo\t\n", 0); assert(!session.catalog.apps()[0].installed); assert(session.status.value() == "Deleted"); + assert(session.screen == Screen::Home); service.state().begin("upgrade", "demo", "Demo", 400); controller.finish("ERROR\tbroken\n", 1); From 28c4bde9a9f5c42b158771d403c825173291d3e7 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:33:03 +0300 Subject: [PATCH 18/19] fix(store): centre the install-state dot on its label --- main/ui/appstore_pages.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main/ui/appstore_pages.cpp b/main/ui/appstore_pages.cpp index f7baf76..4a84528 100644 --- a/main/ui/appstore_pages.cpp +++ b/main/ui/appstore_pages.cpp @@ -755,8 +755,12 @@ void AppDetailPage::render(const PageRenderContext &context, const AppDetailView const uint32_t state_color = !app.installed ? 0x6E7681 : (appstore::can_upgrade_app(app) ? 0xF0B429 : 0x52D05D); - box(document, 11, y + 5, 8, 8, state_color, state_color, 0, 4); - label(document, model.state, 25, y, 285, 17, store_font(model.state, 14), + const lv_font_t *state_font = store_font(model.state, 14); + // Centre the dot on the state label's capitals instead of its line box. + constexpr int state_dot = 8; + box(document, 11, y + glyph_middle(state_font, 'I') - state_dot / 2, + state_dot, state_dot, state_color, state_color, 0, state_dot / 2); + label(document, model.state, 25, y, 285, 17, state_font, app.installed ? 0xE6EDF3 : 0xB1BAC4, LV_LABEL_LONG_DOT); y += 23; box(document, 10, y, 300, 1, 0x1E2A30, 0x1E2A30, 0); From 7bb7cd2bc196c15988e97a0204cb20869047ab21 Mon Sep 17 00:00:00 2001 From: d4rkmen Date: Thu, 22 Oct 2026 23:51:09 +0300 Subject: [PATCH 19/19] feat(store): show the screens shortcut on app details --- README.md | 5 +++-- main/ui/appstore_shortcut_bar.cpp | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b00bac..9b6c5f8 100644 --- a/README.md +++ b/README.md @@ -150,8 +150,9 @@ a key scrolls continuously. The system bar and bottom actions stay fixed, and status messages appear just above the actions at any scroll position. Descriptions wrap without a height limit or automatic scrolling. Apps without screenshots have no screenshot area. Detail actions are `4` back, -`6` install/reinstall, `7` update, and `8` remove, shown when applicable. -After a successful removal the Store returns to the home list. +`5` screens (the full-screen viewer), `6` install/reinstall, `7` update, and +`8` remove, shown when applicable. After a successful removal the Store returns +to the home list. The existing full-screen screenshot viewer remains accessible through `5`, where `Z/C` cycles images. On the details page itself those keys page through the content. diff --git a/main/ui/appstore_shortcut_bar.cpp b/main/ui/appstore_shortcut_bar.cpp index 4742ff4..128341d 100644 --- a/main/ui/appstore_shortcut_bar.cpp +++ b/main/ui/appstore_shortcut_bar.cpp @@ -45,6 +45,9 @@ void AppStoreShortcutBar::render_detail(lv_obj_t *root, const std::string &app_d { (void)app_dir; shortcut_label(root, 48, "back", 0xF0B429); + // Unknown counts (-1) may still have cached images, so hide only a known zero. + if (app.screenshot_count != 0) + shortcut_label(root, 104, "screens", 0x168CE5); if (!app.installed && appstore::can_install_app(app)) shortcut_label(root, 160, "install", 0xB069FF); if (appstore::can_reinstall_app(app))