Desktop: Poweroff fallback when app unavailable (#208)

This commit is contained in:
Willy-JL
2024-09-06 03:19:49 +02:00
parent bf7f38ca9d
commit f438199c4a
5 changed files with 29 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
- RFID: - RFID:
- OFW: Fix detection of GProx II cards and false detection of other cards (by @Astrrra) - OFW: Fix detection of GProx II cards and false detection of other cards (by @Astrrra)
- OFW: Fix Guard GProxII False Positive and 36-bit Parsing (by @zinongli) - OFW: Fix Guard GProxII False Positive and 36-bit Parsing (by @zinongli)
- Desktop: Poweroff fallback when app unavailable (by @Willy-JL)
- Loader: Warn about missing SD card for main apps (by @Willy-JL) - Loader: Warn about missing SD card for main apps (by @Willy-JL)
- OFW: NFC: Fix crash on Ultralight unlock (by @Astrrra) - OFW: NFC: Fix crash on Ultralight unlock (by @Astrrra)
- OFW: RPC: Broken file interaction fixes (by @RebornedBrain) - OFW: RPC: Broken file interaction fixes (by @RebornedBrain)

View File

@@ -440,6 +440,29 @@ void desktop_unlock(Desktop* desktop) {
desktop->locked = false; desktop->locked = false;
} }
int32_t desktop_shutdown(void* context) {
Desktop* desktop = context;
LoaderStatus result = loader_start(desktop->loader, "Power", "off", NULL);
if(result != LoaderStatusOk) {
// Mimic applications/settings/power_settings_app/scenes/power_settings_scene_power_off.c
DialogMessage* message = dialog_message_alloc();
dialog_message_set_header(message, "Turn Off Device?", 64, 0, AlignCenter, AlignTop);
dialog_message_set_text(
message, " I will be\nwaiting for\n you here...", 78, 14, AlignLeft, AlignTop);
dialog_message_set_icon(message, &I_dolph_cry_49x54, 14, 10);
dialog_message_set_buttons(message, "Cancel", NULL, "Power Off");
DialogMessageButton res = dialog_message_show(furi_record_open(RECORD_DIALOGS), message);
furi_record_close(RECORD_DIALOGS);
dialog_message_free(message);
if(res == DialogMessageButtonRight) {
Power* power = furi_record_open(RECORD_POWER);
power_off(power);
furi_record_close(RECORD_POWER);
}
}
return 0;
}
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) { void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
desktop->in_transition = true; desktop->in_transition = true;

View File

@@ -93,4 +93,5 @@ struct Desktop {
void desktop_lock(Desktop* desktop, bool pin_lock); void desktop_lock(Desktop* desktop, bool pin_lock);
void desktop_unlock(Desktop* desktop); void desktop_unlock(Desktop* desktop);
int32_t desktop_shutdown(void* context);
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled); void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled);

View File

@@ -3,6 +3,7 @@
#include <gui/scene_manager.h> #include <gui/scene_manager.h>
#include <gui/view_stack.h> #include <gui/view_stack.h>
#include <stdint.h> #include <stdint.h>
#include <toolbox/run_parallel.h>
#include "../desktop.h" #include "../desktop.h"
#include "../desktop_i.h" #include "../desktop_i.h"
@@ -83,7 +84,7 @@ bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
switch(event.event) { switch(event.event) {
case DesktopLockedEventOpenPowerOff: { case DesktopLockedEventOpenPowerOff: {
if(momentum_settings.lockscreen_poweroff) { if(momentum_settings.lockscreen_poweroff) {
loader_start_detached_with_gui_error(desktop->loader, "Power", "off"); run_parallel(desktop_shutdown, desktop, 512);
} }
consumed = true; consumed = true;
break; break;

View File

@@ -3,6 +3,7 @@
#include <applications.h> #include <applications.h>
#include <assets_icons.h> #include <assets_icons.h>
#include <loader/loader.h> #include <loader/loader.h>
#include <toolbox/run_parallel.h>
#include "../desktop_i.h" #include "../desktop_i.h"
#include "../views/desktop_events.h" #include "../views/desktop_events.h"
@@ -119,7 +120,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
break; break;
case DesktopMainEventOpenPowerOff: { case DesktopMainEventOpenPowerOff: {
loader_start_detached_with_gui_error(desktop->loader, "Power", "off"); run_parallel(desktop_shutdown, desktop, 512);
consumed = true; consumed = true;
break; break;
} }