[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>
This commit is contained in:
@@ -80,6 +80,14 @@ void desktop_locked_reset_counter(DesktopLockedView* locked_view) {
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_with_pin(DesktopLockedView* locked_view, bool locked) {
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
model->pin_lock = locked;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void desktop_locked_render(Canvas* canvas, void* model) {
|
||||
DesktopLockedViewModel* m = model;
|
||||
uint32_t now = osKernelGetTickCount();
|
||||
@@ -100,7 +108,7 @@ void desktop_locked_render(Canvas* canvas, void* model) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_framed(canvas, 42, 30, "Locked");
|
||||
|
||||
} else {
|
||||
} else if(!m->pin_lock) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_icon(canvas, 13, 5, &I_LockPopup_100x49);
|
||||
elements_multiline_text(canvas, 65, 20, "To unlock\npress:");
|
||||
@@ -116,27 +124,49 @@ View* desktop_locked_get_view(DesktopLockedView* locked_view) {
|
||||
bool desktop_locked_input(InputEvent* event, void* context) {
|
||||
furi_assert(event);
|
||||
furi_assert(context);
|
||||
|
||||
DesktopLockedView* locked_view = context;
|
||||
|
||||
uint32_t press_time = 0;
|
||||
bool locked_with_pin = false;
|
||||
|
||||
with_view_model(
|
||||
locked_view->view, (DesktopLockedViewModel * model) {
|
||||
locked_with_pin = model->pin_lock;
|
||||
return false;
|
||||
});
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
desktop_locked_update_hint_timeout(locked_view);
|
||||
if(locked_with_pin) {
|
||||
press_time = osKernelGetTickCount();
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
uint32_t press_time = osKernelGetTickCount();
|
||||
// check if pressed sequentially
|
||||
if(press_time - locked_view->lock_lastpress > UNLOCK_RST_TIMEOUT) {
|
||||
if(press_time - locked_view->lock_lastpress > UNLOCK_RST_TIMEOUT * 3) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count = 0;
|
||||
} else if(press_time - locked_view->lock_lastpress < UNLOCK_RST_TIMEOUT) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count++;
|
||||
locked_view->callback(DesktopLockedEventInputReset, locked_view->context);
|
||||
}
|
||||
|
||||
if(locked_view->lock_count == UNLOCK_CNT) {
|
||||
locked_view->lock_count = 0;
|
||||
locked_view->callback(DesktopLockedEventUnlock, locked_view->context);
|
||||
locked_view->callback(event->key, locked_view->context);
|
||||
} else {
|
||||
desktop_locked_update_hint_timeout(locked_view);
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
press_time = osKernelGetTickCount();
|
||||
// check if pressed sequentially
|
||||
if(press_time - locked_view->lock_lastpress < UNLOCK_RST_TIMEOUT) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count++;
|
||||
}
|
||||
|
||||
if(locked_view->lock_count == UNLOCK_CNT) {
|
||||
locked_view->lock_count = 0;
|
||||
locked_view->callback(DesktopLockedEventUnlock, locked_view->context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(press_time - locked_view->lock_lastpress > UNLOCK_RST_TIMEOUT) {
|
||||
locked_view->lock_lastpress = press_time;
|
||||
locked_view->lock_count = 0;
|
||||
}
|
||||
}
|
||||
// All events consumed
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user