Desktop new full keybind system + fix settng logic

This commit is contained in:
Willy-JL
2023-06-29 04:22:29 +02:00
parent 0c3a8a3ca1
commit b68dc9087a
20 changed files with 399 additions and 247 deletions
+45 -5
View File
@@ -153,12 +153,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
return true;
case DesktopGlobalAfterAppFinished:
animation_manager_load_and_continue_animation(desktop->animation_manager);
// TODO: Implement a message mechanism for loading settings and (optionally)
// locking and unlocking
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_clock_toggle_view(desktop, XTREME_SETTINGS()->statusbar_clock);
desktop_auto_lock_arm(desktop);
return true;
case DesktopGlobalAutoLock:
@@ -450,6 +445,43 @@ FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance) {
return instance->status_pubsub;
}
static const KeybindType keybind_types[] = {
[InputTypeShort] = KeybindTypePress,
[InputTypeLong] = KeybindTypeHold,
};
static const KeybindKey keybind_keys[] = {
[InputKeyUp] = KeybindKeyUp,
[InputKeyDown] = KeybindKeyDown,
[InputKeyRight] = KeybindKeyRight,
[InputKeyLeft] = KeybindKeyLeft,
};
void desktop_run_keybind(Desktop* instance, InputType _type, InputKey _key) {
if(_type != InputTypeShort && _type != InputTypeLong) return;
if(_key != InputKeyUp && _key != InputKeyDown && _key != InputKeyRight && _key != InputKeyLeft)
return;
KeybindType type = keybind_types[_type];
KeybindKey key = keybind_keys[_key];
const char* keybind = instance->settings.keybinds[type][key].data;
if(!strnlen(keybind, MAX_KEYBIND_LENGTH)) return;
if(!strncmp(keybind, "Archive", MAX_KEYBIND_LENGTH)) {
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopMainEventOpenArchive);
} else if(!strncmp(keybind, "Device Info", MAX_KEYBIND_LENGTH)) {
loader_start_with_gui_error(instance->loader, "Power", "about_battery");
} else if(!strncmp(keybind, "Lock Menu", MAX_KEYBIND_LENGTH)) {
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopMainEventOpenLockMenu);
} else if(!strncmp(keybind, "Lock Keypad", MAX_KEYBIND_LENGTH)) {
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopMainEventLockKeypad);
} else if(!strncmp(keybind, "Lock with PIN", MAX_KEYBIND_LENGTH)) {
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopMainEventLockWithPin);
} else {
loader_start_with_gui_error(instance->loader, keybind, NULL);
}
}
int32_t desktop_srv(void* p) {
UNUSED(p);
@@ -466,6 +498,14 @@ int32_t desktop_srv(void* p) {
}
if(!ok) {
memset(&desktop->settings, 0, sizeof(desktop->settings));
strcpy(desktop->settings.keybinds[KeybindTypePress][KeybindKeyUp].data, "Lock Menu");
strcpy(desktop->settings.keybinds[KeybindTypePress][KeybindKeyDown].data, "Archive");
strcpy(desktop->settings.keybinds[KeybindTypePress][KeybindKeyRight].data, "Passport");
strcpy(
desktop->settings.keybinds[KeybindTypePress][KeybindKeyLeft].data,
EXT_PATH("apps/Misc/nightstand.fap"));
strcpy(desktop->settings.keybinds[KeybindTypeHold][KeybindKeyRight].data, "Device Info");
strcpy(desktop->settings.keybinds[KeybindTypeHold][KeybindKeyLeft].data, "Lock with PIN");
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
furi_hal_rtc_set_pin_fails(0);
}
+3
View File
@@ -1,6 +1,7 @@
#pragma once
#include <furi.h>
#include <input/input.h>
typedef struct Desktop Desktop;
@@ -15,3 +16,5 @@ typedef struct {
} DesktopStatus;
FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance);
void desktop_run_keybind(Desktop* instance, InputType _type, InputKey _key);
@@ -5,9 +5,8 @@
#include <stdbool.h>
#include <toolbox/saved_struct.h>
#include <storage/storage.h>
#include <loader/loader.h>
#define DESKTOP_SETTINGS_VER (9)
#define DESKTOP_SETTINGS_VER (11)
#define DESKTOP_SETTINGS_OLD_PATH CFG_PATH("desktop.settings")
#define DESKTOP_SETTINGS_PATH INT_PATH(".desktop.settings")
@@ -18,7 +17,7 @@
#define MAX_PIN_SIZE 10
#define MIN_PIN_SIZE 4
#define MAX_APP_LENGTH 128
#define MAX_KEYBIND_LENGTH 64
typedef struct {
InputKey data[MAX_PIN_SIZE];
@@ -26,16 +25,28 @@ typedef struct {
} PinCode;
typedef struct {
bool is_external;
char name_or_path[MAX_APP_LENGTH];
} FavoriteApp;
char data[MAX_KEYBIND_LENGTH];
} Keybind;
typedef enum {
KeybindTypePress,
KeybindTypeHold,
KeybindTypeCount,
} KeybindType;
typedef enum {
KeybindKeyUp,
KeybindKeyDown,
KeybindKeyRight,
KeybindKeyLeft,
KeybindKeyCount,
} KeybindKey;
typedef struct {
FavoriteApp favorite_primary;
FavoriteApp favorite_secondary;
PinCode pin_code;
uint32_t auto_lock_delay_ms;
bool auto_lock_with_pin;
Keybind keybinds[KeybindTypeCount][KeybindKeyCount];
} DesktopSettings;
bool DESKTOP_SETTINGS_SAVE(DesktopSettings* x);
@@ -23,7 +23,6 @@ void desktop_scene_lock_menu_callback(DesktopEvent event, void* context) {
void desktop_scene_lock_menu_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
DESKTOP_SETTINGS_LOAD(&desktop->settings);
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
desktop_lock_menu_set_pin_state(
@@ -62,7 +61,6 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
int check_pin_changed =
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
if(check_pin_changed) {
DESKTOP_SETTINGS_LOAD(&desktop->settings);
if(desktop_pin_is_valid(&desktop->settings.pin_code)) {
desktop_lock_menu_set_pin_state(desktop->lock_menu, true);
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
@@ -54,7 +54,6 @@ void desktop_scene_locked_on_enter(void* context) {
furi_record_close(RECORD_GUI);
if(pin_locked) {
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_view_locked_lock(desktop->locked_view, true);
uint32_t pin_timeout = desktop_pin_lock_get_fail_timeout();
if(pin_timeout > 0) {
@@ -61,12 +61,6 @@ static void
}
#endif
static void desktop_scene_main_start_favorite(Desktop* desktop, FavoriteApp* application) {
if(strlen(application->name_or_path) > 0) {
loader_start_with_gui_error(desktop->loader, application->name_or_path, NULL);
}
}
void desktop_scene_main_callback(DesktopEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
if(desktop->in_transition) return;
@@ -113,7 +107,12 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
case DesktopMainEventLock:
case DesktopMainEventLockKeypad:
desktop_lock(desktop, false);
consumed = true;
break;
case DesktopMainEventLockWithPin:
desktop_lock(desktop, true);
consumed = true;
break;
@@ -130,16 +129,6 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
}
case DesktopMainEventOpenFavoritePrimary:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_primary);
consumed = true;
break;
case DesktopMainEventOpenFavoriteSecondary:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_secondary);
consumed = true;
break;
case DesktopAnimationEventCheckAnimation:
animation_manager_check_blocking_process(desktop->animation_manager);
consumed = true;
@@ -150,15 +139,10 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
break;
case DesktopAnimationEventInteractAnimation:
if(!animation_manager_interact_process(desktop->animation_manager)) {
loader_start(desktop->loader, "Passport", NULL, NULL);
desktop_run_keybind(desktop, InputTypeShort, InputKeyRight);
}
consumed = true;
break;
case DesktopMainEventOpenClock: {
loader_start_with_gui_error(
desktop->loader, EXT_PATH("apps/Misc/Nightstand.fap"), NULL);
break;
}
case DesktopLockedEventUpdate:
desktop_view_locked_update(desktop->locked_view);
consumed = true;
@@ -3,14 +3,11 @@
typedef enum {
DesktopMainEventOpenLockMenu,
DesktopMainEventOpenArchive,
DesktopMainEventOpenFavoritePrimary,
DesktopMainEventOpenFavoriteSecondary,
DesktopMainEventOpenMenu,
DesktopMainEventOpenDebug,
DesktopMainEventOpenPowerOff,
DesktopMainEventLock,
DesktopMainEventOpenClock,
DesktopMainEventLockKeypad,
DesktopMainEventLockWithPin,
DesktopLockedEventOpenPowerOff,
DesktopLockedEventUnlocked,
@@ -36,34 +36,15 @@ bool desktop_main_input_callback(InputEvent* event, void* context) {
DesktopMainView* main_view = context;
if(event->type == InputTypeShort) {
// DesktopMainEventOpenDebug
if(event->type == InputTypeShort || event->type == InputTypeLong) {
if(event->key == InputKeyOk) {
main_view->callback(DesktopMainEventOpenMenu, main_view->context);
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenArchive, main_view->context);
} else if(event->key == InputKeyRight) {
Loader* loader = furi_record_open(RECORD_LOADER);
loader_start(loader, "Passport", NULL, NULL);
furi_record_close(RECORD_LOADER);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenClock, main_view->context);
}
// Right key is handled by animation manager
} else if(event->type == InputTypeLong) {
if(event->key == InputKeyOk) {
main_view->callback(DesktopAnimationEventNewIdleAnimation, main_view->context);
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenFavoritePrimary, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context);
} else if(event->key == InputKeyRight) {
Loader* loader = furi_record_open(RECORD_LOADER);
loader_start(loader, "Power", "about_battery", NULL);
furi_record_close(RECORD_LOADER);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventLock, main_view->context);
main_view->callback(
event->type == InputTypeShort ? DesktopMainEventOpenMenu :
DesktopAnimationEventNewIdleAnimation,
main_view->context);
} else {
desktop_run_keybind((Desktop*)main_view->context, event->type, event->key);
}
}