From 7fc34db57b40b58404910a0eeef87dffbea40729 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:04:34 +0300 Subject: [PATCH] use event system --- applications/services/desktop/desktop.c | 12 ++++++++---- applications/services/desktop/views/desktop_events.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index abe7d69bc..d77be68a0 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -156,7 +156,11 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { if(!desktop->app_running && !desktop->locked) { desktop_lock(desktop); } - + } else if(event == DesktopGlobalAutoPowerOff) { + if(!desktop->app_running) { + Power* power = furi_record_open(RECORD_POWER); + power_off(power); + } } else if(event == DesktopGlobalSaveSettings) { desktop_settings_save(&desktop->settings); desktop_apply_settings(desktop); @@ -232,9 +236,9 @@ static void desktop_auto_lock_inhibit(Desktop* desktop) { //--- auto_power_off_timer static void desktop_auto_poweroff_timer_callback(void* context) { - UNUSED(context); - Power* power = furi_record_open(RECORD_POWER); - power_off(power); + furi_assert(context); + Desktop* desktop = context; + view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAutoPowerOff); } static void desktop_start_auto_poweroff_timer(Desktop* desktop) { diff --git a/applications/services/desktop/views/desktop_events.h b/applications/services/desktop/views/desktop_events.h index ba91a30cc..57cc0fdaa 100644 --- a/applications/services/desktop/views/desktop_events.h +++ b/applications/services/desktop/views/desktop_events.h @@ -62,4 +62,5 @@ typedef enum { DesktopGlobalApiUnlock, DesktopGlobalSaveSettings, DesktopGlobalReloadSettings, + DesktopGlobalAutoPowerOff, } DesktopEvent;