From 90b333b088e2a257f3b8164c6827d842b5f61875 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 23 Mar 2023 22:23:32 +0000 Subject: [PATCH] Lock menu save settings at exit (fix lag) --- .../desktop/scenes/desktop_scene_lock_menu.c | 15 ++- .../desktop/views/desktop_view_lock_menu.c | 111 +++++++++--------- .../desktop/views/desktop_view_lock_menu.h | 3 + 3 files changed, 74 insertions(+), 55 deletions(-) diff --git a/applications/services/desktop/scenes/desktop_scene_lock_menu.c b/applications/services/desktop/scenes/desktop_scene_lock_menu.c index f9d9008e7..77c956ff1 100644 --- a/applications/services/desktop/scenes/desktop_scene_lock_menu.c +++ b/applications/services/desktop/scenes/desktop_scene_lock_menu.c @@ -30,6 +30,10 @@ void desktop_scene_lock_menu_on_enter(void* context) { desktop_lock_menu_set_pin_state(desktop->lock_menu, desktop->settings.pin_code.length > 0); desktop_lock_menu_set_idx(desktop->lock_menu, 3); + desktop->lock_menu->save_notification = false; + desktop->lock_menu->save_xtreme = false; + desktop->lock_menu->save_bt = false; + view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu); } @@ -120,5 +124,14 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) { } void desktop_scene_lock_menu_on_exit(void* context) { - UNUSED(context); + Desktop* desktop = (Desktop*)context; + if(desktop->lock_menu->save_notification) { + notification_message_save_settings(desktop->lock_menu->notification); + } + if(desktop->lock_menu->save_xtreme) { + XTREME_SETTINGS_SAVE(); + } + if(desktop->lock_menu->save_bt) { + bt_settings_save(&desktop->lock_menu->bt->bt_settings); + } } diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index b92b5981c..c84fdd868 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -205,66 +205,69 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) { UNUSED(idx); if(event->key == InputKeyBack) { consumed = false; - } else if(event->type == InputTypeShort) { - if(event->key == InputKeyOk) { - DesktopEvent event = 0; + } else if(event->key == InputKeyOk && event->type == InputTypeShort) { + DesktopEvent event = 0; + switch(idx) { + case DesktopLockMenuIndexLefthandedMode: + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient)) { + furi_hal_rtc_reset_flag(FuriHalRtcFlagHandOrient); + } else { + furi_hal_rtc_set_flag(FuriHalRtcFlagHandOrient); + } + break; + case DesktopLockMenuIndexSettings: + event = DesktopLockMenuEventSettings; + break; + case DesktopLockMenuIndexDarkMode: + XTREME_SETTINGS()->dark_mode = !XTREME_SETTINGS()->dark_mode; + lock_menu->save_xtreme = true; + break; + case DesktopLockMenuIndexLock: + event = DesktopLockMenuEventLock; + break; + case DesktopLockMenuIndexBluetooth: + lock_menu->bt->bt_settings.enabled = !lock_menu->bt->bt_settings.enabled; + if(lock_menu->bt->bt_settings.enabled) { + furi_hal_bt_start_advertising(); + } else { + furi_hal_bt_stop_advertising(); + } + lock_menu->save_bt = true; + break; + case DesktopLockMenuIndexXtreme: + event = DesktopLockMenuEventXtreme; + break; + default: + break; + } + if(event) { + lock_menu->callback(event, lock_menu->context); + } + } else if(idx >= 6 && (event->type == InputTypeShort || event->type == InputTypeRepeat)) { + int8_t offset = 0; + if(event->key == InputKeyUp) { + offset = 1; + } else if(event->key == InputKeyDown) { + offset = -1; + } + if(offset) { + float value; switch(idx) { - case DesktopLockMenuIndexLefthandedMode: - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient)) { - furi_hal_rtc_reset_flag(FuriHalRtcFlagHandOrient); - } else { - furi_hal_rtc_set_flag(FuriHalRtcFlagHandOrient); - } + case DesktopLockMenuIndexBrightness: + value = lock_menu->notification->settings.display_brightness + 0.05 * offset; + lock_menu->notification->settings.display_brightness = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value); + lock_menu->save_notification = true; + notification_message(lock_menu->notification, &sequence_display_backlight_on); break; - case DesktopLockMenuIndexSettings: - event = DesktopLockMenuEventSettings; - break; - case DesktopLockMenuIndexDarkMode: - XTREME_SETTINGS()->dark_mode = !XTREME_SETTINGS()->dark_mode; - XTREME_SETTINGS_SAVE(); - break; - case DesktopLockMenuIndexLock: - event = DesktopLockMenuEventLock; - break; - case DesktopLockMenuIndexBluetooth: - lock_menu->bt->bt_settings.enabled = !lock_menu->bt->bt_settings.enabled; - bt_settings_save(&lock_menu->bt->bt_settings); - break; - case DesktopLockMenuIndexXtreme: - event = DesktopLockMenuEventXtreme; + case DesktopLockMenuIndexVolume: + value = lock_menu->notification->settings.speaker_volume + 0.05 * offset; + lock_menu->notification->settings.speaker_volume = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value); + lock_menu->save_notification = true; + notification_message(lock_menu->notification, &sequence_note_c); break; default: break; } - if(event) { - lock_menu->callback(event, lock_menu->context); - } - } else if(idx >= 6) { - int8_t offset = 0; - if(event->key == InputKeyUp) { - offset = 1; - } else if(event->key == InputKeyDown) { - offset = -1; - } - if(offset) { - float value; - switch(idx) { - case DesktopLockMenuIndexBrightness: - value = lock_menu->notification->settings.display_brightness + 0.05 * offset; - lock_menu->notification->settings.display_brightness = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value); - notification_message_save_settings(lock_menu->notification); - notification_message(lock_menu->notification, &sequence_display_backlight_on); - break; - case DesktopLockMenuIndexVolume: - value = lock_menu->notification->settings.speaker_volume + 0.05 * offset; - lock_menu->notification->settings.speaker_volume = value < 0.00f ? 0.00f : (value > 1.00f ? 1.00f : value); - notification_message_save_settings(lock_menu->notification); - notification_message(lock_menu->notification, &sequence_note_c); - break; - default: - break; - } - } } } diff --git a/applications/services/desktop/views/desktop_view_lock_menu.h b/applications/services/desktop/views/desktop_view_lock_menu.h index f0548b2b1..1c0840c13 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.h +++ b/applications/services/desktop/views/desktop_view_lock_menu.h @@ -16,6 +16,9 @@ struct DesktopLockMenuView { DesktopLockMenuViewCallback callback; NotificationApp* notification; Bt* bt; + bool save_notification; + bool save_xtreme; + bool save_bt; void* context; };