flipperzero-firmware/applications/desktop/scenes/desktop_scene_lock_menu.c
its your bedtime fae8d8f23c
[FL-1968] Pin code locking (#788)
* Gui: code input module
* Gui: fix size to fit frame
* Desktop: PIN config and lock option
* Gui: code input: cleanup, offset input fields if no header present
* Desktop: move code unlock to desktop_locked scene
* Desktop: fix unlock with back key
* Desktop: bump settings version
* Desktop: correct scene usage.

Co-authored-by: あく <alleteam@gmail.com>
2021-10-26 21:34:31 +03:00

61 lines
2.2 KiB
C

#include "../desktop_i.h"
#include "../views/desktop_lock_menu.h"
void desktop_scene_lock_menu_callback(DesktopLockMenuEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
void desktop_scene_lock_menu_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_settings_load(&desktop->settings);
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
desktop_lock_menu_pin_set(desktop->lock_menu, desktop->settings.pincode.length > 0);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewLockMenu);
}
bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopLockMenuEventLock:
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneLocked, DesktopLockedNoPin);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
consumed = true;
break;
case DesktopLockMenuEventPinLock:
if(desktop->settings.pincode.length > 0) {
desktop->settings.locked = true;
desktop_settings_save(&desktop->settings);
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneLocked, DesktopLockedWithPin);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
} else {
scene_manager_next_scene(desktop->scene_manager, DesktopScenePinSetup);
}
consumed = true;
break;
case DesktopLockMenuEventExit:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
void desktop_scene_lock_menu_on_exit(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_lock_menu_reset_idx(desktop->lock_menu);
}