From a9c2b4d6a0dc0f890351763ffd94f6a904833191 Mon Sep 17 00:00:00 2001 From: Kowalski Dragon Date: Tue, 20 Dec 2022 14:57:58 +0100 Subject: [PATCH] Desktop: dummy mode improvements. Fixes: correct scrolling text, correct AM/PM in Clock. (#2160) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Show passport instead of app if SD/app is missing * Desktop: cleanup dummy mode code and add more apps * Gui: fix incorrect trimming in scrollable text Signed-off-by: Kowalski Dragon (kowalski7cc) Co-authored-by: あく --- applications/plugins/clock/clock_app.c | 2 +- .../desktop/scenes/desktop_scene_main.c | 33 +++++++++++++++---- .../services/desktop/views/desktop_events.h | 4 ++- .../desktop/views/desktop_view_main.c | 6 ++-- applications/services/gui/elements.c | 7 ++-- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/applications/plugins/clock/clock_app.c b/applications/plugins/clock/clock_app.c index e196f0d2..9d87ff95 100644 --- a/applications/plugins/clock/clock_app.c +++ b/applications/plugins/clock/clock_app.c @@ -56,7 +56,7 @@ static void clock_render_callback(Canvas* canvas, void* ctx) { 31, AlignLeft, AlignCenter, - (data->datetime.hour > 12) ? "AM" : "PM"); + (data->datetime.hour > 12) ? "PM" : "AM"); } canvas_set_font(canvas, FontSecondary); diff --git a/applications/services/desktop/scenes/desktop_scene_main.c b/applications/services/desktop/scenes/desktop_scene_main.c index 4f01ad5b..befcf399 100644 --- a/applications/services/desktop/scenes/desktop_scene_main.c +++ b/applications/services/desktop/scenes/desktop_scene_main.c @@ -12,6 +12,10 @@ #define TAG "DesktopSrv" +#define MUSIC_PLAYER_APP EXT_PATH("/apps/Misc/music_player.fap") +#define SNAKE_GAME_APP EXT_PATH("/apps/Games/snake_game.fap") +#define CLOCK_APP EXT_PATH("/apps/Tools/clock.fap") + static void desktop_scene_main_new_idle_animation_callback(void* context) { furi_assert(context); Desktop* desktop = context; @@ -60,6 +64,19 @@ static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* fl } #endif +static void desktop_scene_main_open_app_or_profile(Desktop* desktop, const char* path) { + do { + LoaderStatus status = loader_start(desktop->loader, FAP_LOADER_APP_NAME, path); + if(status == LoaderStatusOk) break; + FURI_LOG_E(TAG, "loader_start failed: %d", status); + + status = loader_start(desktop->loader, "Passport", NULL); + if(status != LoaderStatusOk) { + FURI_LOG_E(TAG, "loader_start failed: %d", status); + } + } while(false); +} + void desktop_scene_main_callback(DesktopEvent event, void* context) { Desktop* desktop = (Desktop*)context; view_dispatcher_send_custom_event(desktop->view_dispatcher, event); @@ -181,12 +198,16 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { } break; } - case DesktopMainEventOpenGameMenu: { - LoaderStatus status = loader_start( - desktop->loader, FAP_LOADER_APP_NAME, EXT_PATH("/apps/Games/snake_game.fap")); - if(status != LoaderStatusOk) { - FURI_LOG_E(TAG, "loader_start failed: %d", status); - } + case DesktopMainEventOpenGame: { + desktop_scene_main_open_app_or_profile(desktop, SNAKE_GAME_APP); + break; + } + case DesktopMainEventOpenClock: { + desktop_scene_main_open_app_or_profile(desktop, CLOCK_APP); + break; + } + case DesktopMainEventOpenMusicPlayer: { + desktop_scene_main_open_app_or_profile(desktop, MUSIC_PLAYER_APP); break; } case DesktopLockedEventUpdate: diff --git a/applications/services/desktop/views/desktop_events.h b/applications/services/desktop/views/desktop_events.h index a7e610ff..666d179b 100644 --- a/applications/services/desktop/views/desktop_events.h +++ b/applications/services/desktop/views/desktop_events.h @@ -10,7 +10,9 @@ typedef enum { DesktopMainEventOpenPassport, DesktopMainEventOpenPowerOff, - DesktopMainEventOpenGameMenu, + DesktopMainEventOpenGame, + DesktopMainEventOpenClock, + DesktopMainEventOpenMusicPlayer, DesktopLockedEventUnlocked, DesktopLockedEventUpdate, diff --git a/applications/services/desktop/views/desktop_view_main.c b/applications/services/desktop/views/desktop_view_main.c index 0edc0b70..cbf4a20f 100644 --- a/applications/services/desktop/views/desktop_view_main.c +++ b/applications/services/desktop/views/desktop_view_main.c @@ -72,13 +72,13 @@ bool desktop_main_input_callback(InputEvent* event, void* context) { } else { if(event->type == InputTypeShort) { if(event->key == InputKeyOk) { - main_view->callback(DesktopMainEventOpenGameMenu, main_view->context); + main_view->callback(DesktopMainEventOpenGame, main_view->context); } else if(event->key == InputKeyUp) { main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); } else if(event->key == InputKeyDown) { - main_view->callback(DesktopMainEventOpenPassport, main_view->context); + main_view->callback(DesktopMainEventOpenMusicPlayer, main_view->context); } else if(event->key == InputKeyLeft) { - main_view->callback(DesktopMainEventOpenPassport, main_view->context); + main_view->callback(DesktopMainEventOpenClock, main_view->context); } // Right key is handled by animation manager } diff --git a/applications/services/gui/elements.c b/applications/services/gui/elements.c index 955e1fbd..6b796ed5 100644 --- a/applications/services/gui/elements.c +++ b/applications/services/gui/elements.c @@ -564,7 +564,7 @@ void elements_scrollable_text_line( } // Calculate scroll size - size_t scroll_size = furi_string_size(string); + size_t scroll_size = furi_string_size(line); size_t right_width = 0; for(size_t i = scroll_size; i > 0; i--) { right_width += canvas_glyph_width(canvas, furi_string_get_char(line, i)); @@ -579,10 +579,11 @@ void elements_scrollable_text_line( furi_string_right(line, scroll); } - do { + len_px = canvas_string_width(canvas, furi_string_get_cstr(line)); + while(len_px > width) { furi_string_left(line, furi_string_size(line) - 1); len_px = canvas_string_width(canvas, furi_string_get_cstr(line)); - } while(len_px > width); + } if(ellipsis) { furi_string_cat(line, "...");