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.
This commit is contained in:
Kevin Wallace 2022-06-10 06:29:25 -07:00 committed by GitHub
parent b3186e29e2
commit d378ca6fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 5 deletions

View File

@ -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) {

View File

@ -8,6 +8,7 @@ typedef enum {
DesktopMainEventOpenMenu,
DesktopMainEventOpenDebug,
DesktopMainEventOpenPassport, /**< Broken, don't use it */
DesktopMainEventOpenPowerOff,
DesktopLockedEventUnlocked,
DesktopLockedEventUpdate,

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);
}