Skip to content

Commit

Permalink
Desktop: Poweroff fallback when app unavailable (Next-Flip#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Sep 6, 2024
1 parent bf7f38c commit f438199
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- RFID:
- 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)
- Desktop: Poweroff fallback when app unavailable (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: RPC: Broken file interaction fixes (by @RebornedBrain)
Expand Down
23 changes: 23 additions & 0 deletions applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,29 @@ void desktop_unlock(Desktop* desktop) {
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) {
desktop->in_transition = true;

Expand Down
1 change: 1 addition & 0 deletions applications/services/desktop/desktop_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ struct Desktop {

void desktop_lock(Desktop* desktop, bool pin_lock);
void desktop_unlock(Desktop* desktop);
int32_t desktop_shutdown(void* context);
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled);
3 changes: 2 additions & 1 deletion applications/services/desktop/scenes/desktop_scene_locked.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gui/scene_manager.h>
#include <gui/view_stack.h>
#include <stdint.h>
#include <toolbox/run_parallel.h>

#include "../desktop.h"
#include "../desktop_i.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
switch(event.event) {
case DesktopLockedEventOpenPowerOff: {
if(momentum_settings.lockscreen_poweroff) {
loader_start_detached_with_gui_error(desktop->loader, "Power", "off");
run_parallel(desktop_shutdown, desktop, 512);
}
consumed = true;
break;
Expand Down
3 changes: 2 additions & 1 deletion applications/services/desktop/scenes/desktop_scene_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <applications.h>
#include <assets_icons.h>
#include <loader/loader.h>
#include <toolbox/run_parallel.h>

#include "../desktop_i.h"
#include "../views/desktop_events.h"
Expand Down Expand Up @@ -119,7 +120,7 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
break;

case DesktopMainEventOpenPowerOff: {
loader_start_detached_with_gui_error(desktop->loader, "Power", "off");
run_parallel(desktop_shutdown, desktop, 512);
consumed = true;
break;
}
Expand Down

0 comments on commit f438199

Please sign in to comment.