From d378ca6fdad775404176b64cd47ba5e3718b673a Mon Sep 17 00:00:00 2001 From: Kevin Wallace <184975+kevinwallace@users.noreply.github.com> Date: Fri, 10 Jun 2022 06:29:25 -0700 Subject: [PATCH] desktop: prompt to power off on back button long press (#1279) * desktop: prompt to power off on back button long press Implemented by launching Power Settings app, passing "off" as arg to directly jump to "power off" scene. --- applications/desktop/scenes/desktop_scene_main.c | 9 +++++++++ applications/desktop/views/desktop_events.h | 1 + applications/desktop/views/desktop_view_main.c | 2 ++ .../power/power_settings_app/power_settings_app.c | 11 +++++++---- .../scenes/power_settings_scene_power_off.c | 5 ++++- 5 files changed, 23 insertions(+), 5 deletions(-) mode change 100755 => 100644 applications/power/power_settings_app/power_settings_app.c mode change 100755 => 100644 applications/power/power_settings_app/scenes/power_settings_scene_power_off.c diff --git a/applications/desktop/scenes/desktop_scene_main.c b/applications/desktop/scenes/desktop_scene_main.c index da31c1717..bc4101ffd 100644 --- a/applications/desktop/scenes/desktop_scene_main.c +++ b/applications/desktop/scenes/desktop_scene_main.c @@ -103,6 +103,15 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) { consumed = true; break; + case DesktopMainEventOpenPowerOff: { + LoaderStatus status = loader_start(desktop->loader, "Power", "off"); + if(status != LoaderStatusOk) { + FURI_LOG_E(TAG, "loader_start failed: %d", status); + } + consumed = true; + break; + } + case DesktopMainEventOpenFavoritePrimary: LOAD_DESKTOP_SETTINGS(&desktop->settings); if(desktop->settings.favorite_primary < FLIPPER_APPS_COUNT) { diff --git a/applications/desktop/views/desktop_events.h b/applications/desktop/views/desktop_events.h index 54ee635dc..bbb6ff62d 100644 --- a/applications/desktop/views/desktop_events.h +++ b/applications/desktop/views/desktop_events.h @@ -8,6 +8,7 @@ typedef enum { DesktopMainEventOpenMenu, DesktopMainEventOpenDebug, DesktopMainEventOpenPassport, /**< Broken, don't use it */ + DesktopMainEventOpenPowerOff, DesktopLockedEventUnlocked, DesktopLockedEventUpdate, diff --git a/applications/desktop/views/desktop_view_main.c b/applications/desktop/views/desktop_view_main.c index b3a071fb8..4e7260b0e 100644 --- a/applications/desktop/views/desktop_view_main.c +++ b/applications/desktop/views/desktop_view_main.c @@ -53,6 +53,8 @@ bool desktop_main_input(InputEvent* event, void* context) { main_view->callback(DesktopMainEventOpenDebug, main_view->context); } else if(event->key == InputKeyLeft) { main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context); + } else if(event->key == InputKeyBack) { + main_view->callback(DesktopMainEventOpenPowerOff, main_view->context); } } diff --git a/applications/power/power_settings_app/power_settings_app.c b/applications/power/power_settings_app/power_settings_app.c old mode 100755 new mode 100644 index 822c51bcc..3edf38371 --- a/applications/power/power_settings_app/power_settings_app.c +++ b/applications/power/power_settings_app/power_settings_app.c @@ -18,7 +18,7 @@ static void power_settings_tick_event_callback(void* context) { scene_manager_handle_tick_event(app->scene_manager); } -PowerSettingsApp* power_settings_app_alloc() { +PowerSettingsApp* power_settings_app_alloc(uint32_t first_scene) { PowerSettingsApp* app = malloc(sizeof(PowerSettingsApp)); // Records @@ -52,7 +52,7 @@ PowerSettingsApp* power_settings_app_alloc() { app->view_dispatcher, PowerSettingsAppViewDialog, dialog_ex_get_view(app->dialog)); // Set first scene - scene_manager_next_scene(app->scene_manager, PowerSettingsAppSceneStart); + scene_manager_next_scene(app->scene_manager, first_scene); return app; } @@ -75,8 +75,11 @@ void power_settings_app_free(PowerSettingsApp* app) { } int32_t power_settings_app(void* p) { - UNUSED(p); - PowerSettingsApp* app = power_settings_app_alloc(); + uint32_t first_scene = PowerSettingsAppSceneStart; + if(p && !strcmp(p, "off")) { + first_scene = PowerSettingsAppScenePowerOff; + } + PowerSettingsApp* app = power_settings_app_alloc(first_scene); view_dispatcher_run(app->view_dispatcher); power_settings_app_free(app); return 0; diff --git a/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c b/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c old mode 100755 new mode 100644 index 2c79bcfe3..83046743b --- a/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c +++ b/applications/power/power_settings_app/scenes/power_settings_scene_power_off.c @@ -28,7 +28,10 @@ bool power_settings_scene_power_off_on_event(void* context, SceneManagerEvent ev if(event.type == SceneManagerEventTypeCustom) { if(event.event == DialogExResultLeft) { - scene_manager_previous_scene(app->scene_manager); + if(!scene_manager_previous_scene(app->scene_manager)) { + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } } else if(event.event == DialogExResultRight) { power_off(app->power); }