Desktop favorites pt1

This commit is contained in:
gid9798
2023-08-17 13:04:40 +03:00
parent 4d5a900352
commit 3990c93013
9 changed files with 256 additions and 183 deletions

View File

@@ -8,7 +8,7 @@
#include <toolbox/saved_struct.h>
#include <storage/storage.h>
#define DESKTOP_SETTINGS_VER (12)
#define DESKTOP_SETTINGS_VER (13)
#define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME)
#define DESKTOP_SETTINGS_MAGIC (0x17)
@@ -43,6 +43,24 @@
#define DISPLAY_BATTERY_RETRO_5 4
#define DISPLAY_BATTERY_BAR_PERCENT 5
typedef enum {
FavoriteAppLeftShort = 0,
FavoriteAppLeftLong,
FavoriteAppRightShort,
FavoriteAppRightLong,
FavoriteAppNumber,
} FavoriteAppShortcut;
typedef enum {
DummyAppLeft = 0,
DummyAppRight,
DummyAppDown,
DummyAppOk,
DummyAppNumber,
} DummyAppShortcut;
typedef struct {
InputKey data[MAX_PIN_SIZE];
uint8_t length;
@@ -53,12 +71,11 @@ typedef struct {
} FavoriteApp;
typedef struct {
FavoriteApp favorite_primary;
FavoriteApp favorite_secondary;
FavoriteApp favorite_tertiary;
PinCode pin_code;
uint32_t auto_lock_delay_ms;
uint8_t displayBatteryPercentage;
uint8_t dummy_mode;
uint8_t display_clock;
FavoriteApp favorite_apps[FavoriteAppNumber];
FavoriteApp dummy_apps[DummyAppNumber];
} DesktopSettings;

View File

@@ -87,6 +87,10 @@ bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
desktop_unlock(desktop);
consumed = true;
break;
case DesktopLockedEventDoorsClosed:
notification_message(desktop->notification, &sequence_display_backlight_off);
consumed = true;
break;
case DesktopLockedEventUpdate:
if(desktop_view_locked_is_locked_hint_visible(desktop->locked_view)) {
notification_message(desktop->notification, &sequence_display_backlight_off);

View File

@@ -61,17 +61,23 @@ static void
}
#endif
static void desktop_scene_main_open_app_or_profile(Desktop* desktop, const char* path) {
if(loader_start_with_gui_error(desktop->loader, path, NULL) != LoaderStatusOk) {
static void desktop_scene_main_open_app_or_profile(Desktop* desktop, FavoriteApp* application) {
bool load_ok = false;
if(strlen(application->name_or_path) > 0) {
if(loader_start(desktop->loader, application->name_or_path, NULL, NULL) ==
LoaderStatusOk) {
load_ok = true;
}
}
if(!load_ok) {
loader_start(desktop->loader, "Passport", NULL, NULL);
}
}
static void desktop_scene_main_start_favorite(Desktop* desktop, FavoriteApp* application) {
if(strlen(application->name_or_path) > 2) {
if(strlen(application->name_or_path) > 0) {
loader_start_with_gui_error(desktop->loader, application->name_or_path, NULL);
} else if(
(strlen(application->name_or_path) < 2) && (strcmp(application->name_or_path, "d") != 0)) {
} else {
loader_start(desktop->loader, LOADER_APPLICATIONS_NAME, NULL, NULL);
}
}
@@ -112,6 +118,12 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
consumed = true;
} break;
case DesktopMainEventLock:
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock(desktop);
consumed = true;
break;
case DesktopMainEventOpenLockMenu:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLockMenu);
consumed = true;
@@ -122,12 +134,6 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
consumed = true;
break;
case DesktopMainEventLock:
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
desktop_lock(desktop);
consumed = true;
break;
case DesktopMainEventOpenArchive:
#ifdef APP_ARCHIVE
desktop_switch_to_app(desktop, &FLIPPER_ARCHIVE);
@@ -141,21 +147,31 @@ bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
break;
}
case DesktopMainEventOpenFavoritePrimary:
case DesktopMainEventOpenFavoriteLeftShort:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_primary);
desktop_scene_main_start_favorite(
desktop, &desktop->settings.favorite_apps[FavoriteAppLeftShort]);
consumed = true;
break;
case DesktopMainEventOpenFavoriteSecondary:
case DesktopMainEventOpenFavoriteLeftLong:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_secondary);
desktop_scene_main_start_favorite(
desktop, &desktop->settings.favorite_apps[FavoriteAppLeftLong]);
consumed = true;
break;
case DesktopMainEventOpenFavoriteTertiary:
case DesktopMainEventOpenFavoriteRightShort:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(desktop, &desktop->settings.favorite_tertiary);
desktop_scene_main_start_favorite(
desktop, &desktop->settings.favorite_apps[FavoriteAppRightShort]);
consumed = true;
break;
case DesktopMainEventOpenFavoriteRightLong:
DESKTOP_SETTINGS_LOAD(&desktop->settings);
desktop_scene_main_start_favorite(
desktop, &desktop->settings.favorite_apps[FavoriteAppRightLong]);
consumed = true;
break;
case DesktopAnimationEventCheckAnimation:
animation_manager_check_blocking_process(desktop->animation_manager);
consumed = true;
@@ -166,39 +182,31 @@ 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_SETTINGS_LOAD(&desktop->settings);
if(!desktop->settings.dummy_mode) {
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.favorite_apps[FavoriteAppRightShort]);
} else {
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.dummy_apps[DummyAppRight]);
}
}
consumed = true;
break;
case DesktopMainEventOpenPassport: {
loader_start(desktop->loader, "Passport", NULL, NULL);
break;
}
case DesktopMainEventOpenGameMenu: {
desktop_scene_main_open_app_or_profile(desktop, EXT_PATH("/apps/Games/snake.fap"));
break;
}
case DesktopMainEventOpenTetris: {
desktop_scene_main_open_app_or_profile(desktop, EXT_PATH("/apps/Games/tetris.fap"));
break;
}
case DesktopMainEventOpenArkanoid: {
desktop_scene_main_open_app_or_profile(desktop, EXT_PATH("/apps/Games/arkanoid.fap"));
break;
}
case DesktopMainEventOpenDOOM: {
desktop_scene_main_open_app_or_profile(desktop, EXT_PATH("/apps/Games/doom.fap"));
break;
}
case DesktopMainEventOpenZombiez: {
desktop_scene_main_open_app_or_profile(desktop, EXT_PATH("/apps/Games/zombiez.fap"));
break;
}
case DesktopMainEventOpenHeap: {
case DesktopDummyEventOpenLeft:
desktop_scene_main_open_app_or_profile(
desktop, EXT_PATH("/apps/Games/heap_defence.fap"));
desktop, &desktop->settings.dummy_apps[DummyAppLeft]);
break;
}
case DesktopDummyEventOpenDown:
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.dummy_apps[DummyAppDown]);
break;
case DesktopDummyEventOpenOk:
desktop_scene_main_open_app_or_profile(
desktop, &desktop->settings.dummy_apps[DummyAppOk]);
break;
case DesktopLockedEventUpdate:
desktop_view_locked_update(desktop->locked_view);
consumed = true;

View File

@@ -1,27 +1,30 @@
#pragma once
typedef enum {
DesktopMainEventLock,
DesktopMainEventOpenLockMenu,
DesktopMainEventOpenArchive,
DesktopMainEventOpenFavoritePrimary,
DesktopMainEventOpenFavoriteSecondary,
DesktopMainEventOpenFavoriteTertiary,
DesktopMainEventOpenFavoriteLeftShort,
DesktopMainEventOpenFavoriteLeftLong,
DesktopMainEventOpenFavoriteRightShort,
DesktopMainEventOpenFavoriteRightLong,
DesktopMainEventOpenMenu,
DesktopMainEventOpenDebug,
DesktopMainEventOpenPassport,
DesktopMainEventOpenPowerOff,
DesktopMainEventLock,
DesktopMainEventOpenGameMenu,
DesktopMainEventOpenTetris,
DesktopMainEventOpenArkanoid,
DesktopMainEventOpenDOOM,
DesktopMainEventOpenZombiez,
DesktopMainEventOpenHeap,
DesktopDummyEventOpenLeft,
DesktopDummyEventOpenDown,
DesktopDummyEventOpenOk,
// TODO add long press in Dummy mode & RightLong
DesktopDummyEventOpenUpLong,
DesktopDummyEventOpenDownLong,
DesktopDummyEventOpenLeftLong,
DesktopLockedEventUnlocked,
DesktopLockedEventUpdate,
DesktopLockedEventShowPinInput,
DesktopLockedEventDoorsClosed,
DesktopPinInputEventResetWrongPinLabel,
DesktopPinInputEventUnlocked,

View File

@@ -99,6 +99,7 @@ void desktop_view_locked_update(DesktopViewLocked* locked_view) {
if(view_state == DesktopViewLockedStateDoorsClosing &&
!desktop_view_locked_doors_move(model)) {
locked_view->callback(DesktopLockedEventDoorsClosed, locked_view->context);
model->view_state = DesktopViewLockedStateLocked;
} else if(view_state == DesktopViewLockedStateLockedHintShown) {
model->view_state = DesktopViewLockedStateLocked;

View File

@@ -59,18 +59,18 @@ bool desktop_main_input_callback(InputEvent* event, void* context) {
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenArchive, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenFavoritePrimary, main_view->context);
main_view->callback(DesktopMainEventOpenFavoriteLeftShort, main_view->context);
}
// Right key is handled by animation manager
// Right key short is handled by animation manager
} else if(event->type == InputTypeLong) {
if(event->key == InputKeyDown) {
if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventLock, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(DesktopMainEventOpenDebug, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(DesktopMainEventOpenFavoriteSecondary, main_view->context);
main_view->callback(DesktopMainEventOpenFavoriteLeftLong, main_view->context);
} else if(event->key == InputKeyRight) {
main_view->callback(DesktopMainEventOpenFavoriteTertiary, main_view->context);
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventLock, main_view->context);
main_view->callback(DesktopMainEventOpenFavoriteRightLong, main_view->context);
} else if(event->key == InputKeyOk) {
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
main_view->callback(DesktopAnimationEventNewIdleAnimation, main_view->context);
@@ -80,31 +80,26 @@ bool desktop_main_input_callback(InputEvent* event, void* context) {
} else {
if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
main_view->callback(
DesktopMainEventOpenGameMenu, main_view->context); // OPENS Snake
main_view->callback(DesktopDummyEventOpenOk, main_view->context);
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenLockMenu, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(
DesktopMainEventOpenTetris, main_view->context); // OPENS Tetris
main_view->callback(DesktopDummyEventOpenDown, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(
DesktopMainEventOpenArkanoid, main_view->context); // OPENS Arkanoid
main_view->callback(DesktopDummyEventOpenLeft, main_view->context);
}
// Right key is handled by animation manager
// Right key short is handled by animation manager
} else if(event->type == InputTypeLong) {
if(event->key == InputKeyOk) {
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
main_view->callback(DesktopAnimationEventNewIdleAnimation, main_view->context);
}
} else if(event->key == InputKeyUp) {
main_view->callback(DesktopMainEventOpenDOOM, main_view->context); // OPENS DOOM
main_view->callback(DesktopDummyEventOpenUpLong, main_view->context);
} else if(event->key == InputKeyDown) {
main_view->callback(
DesktopMainEventOpenZombiez, main_view->context); // OPENS Zombiez
main_view->callback(DesktopDummyEventOpenDownLong, main_view->context);
} else if(event->key == InputKeyLeft) {
main_view->callback(
DesktopMainEventOpenHeap, main_view->context); // OPENS Heap Defence
main_view->callback(DesktopDummyEventOpenLeftLong, main_view->context);
}
}
}