[FL-1824] Dolphin refactoring (#701)

* refactoring p1
* refactoring p2
* cleanups
* locked screen refresh rate fix
* better locked view logic
* seperate dolphin service and desktop app
* Desktop: Favorite app acess (Left key), Settings app
* Desktop settings version, submenu header
* remove unused icon anomation + naming fix

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
its your bedtime
2021-09-28 12:40:39 +03:00
committed by GitHub
parent a8981d317a
commit 1c4e6ec74d
44 changed files with 1974 additions and 728 deletions

View File

@@ -0,0 +1,30 @@
#include "desktop_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const desktop_on_enter_handlers[])(void*) = {
#include "desktop_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const desktop_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "desktop_scene_config.h"
};
#undef ADD_SCENE
// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const desktop_on_exit_handlers[])(void* context) = {
#include "desktop_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers desktop_scene_handlers = {
.on_enter_handlers = desktop_on_enter_handlers,
.on_event_handlers = desktop_on_event_handlers,
.on_exit_handlers = desktop_on_exit_handlers,
.scene_num = DesktopSceneNum,
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) DesktopScene##id,
typedef enum {
#include "desktop_scene_config.h"
DesktopSceneNum,
} DesktopScene;
#undef ADD_SCENE
extern const SceneManagerHandlers desktop_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "desktop_scene_config.h"
#undef ADD_SCENE
// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "desktop_scene_config.h"
#undef ADD_SCENE
// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "desktop_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,6 @@
ADD_SCENE(desktop, main, Main)
ADD_SCENE(desktop, lock_menu, LockMenu)
ADD_SCENE(desktop, locked, Locked)
ADD_SCENE(desktop, debug, Debug)
ADD_SCENE(desktop, first_start, FirstStart)
ADD_SCENE(desktop, hw_mismatch, HwMismatch)

View File

@@ -0,0 +1,62 @@
#include "../desktop_i.h"
#include "../views/desktop_debug.h"
#include "applications/dolphin/dolphin.h"
#include "applications/dolphin/helpers/dolphin_deed.h"
void desktop_scene_debug_callback(DesktopDebugEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
const void desktop_scene_debug_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_debug_get_dolphin_data(desktop->debug_view);
desktop_debug_set_callback(desktop->debug_view, desktop_scene_debug_callback, desktop);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewDebug);
}
const bool desktop_scene_debug_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
Dolphin* dolphin = furi_record_open("dolphin");
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopDebugEventExit:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
dolphin_save(dolphin);
consumed = true;
break;
case DesktopDebugEventDeed:
dolphin_deed(dolphin, DolphinDeedIButtonEmulate);
desktop_debug_get_dolphin_data(desktop->debug_view);
consumed = true;
break;
case DesktopDebugEventWrongDeed:
dolphin_deed(dolphin, DolphinDeedWrong);
desktop_debug_get_dolphin_data(desktop->debug_view);
consumed = true;
break;
case DesktopDebugEventSaveState:
dolphin_save(dolphin);
consumed = true;
break;
default:
break;
}
}
furi_record_close("dolphin");
return consumed;
}
const void desktop_scene_debug_on_exit(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_debug_reset_screen_idx(desktop->debug_view);
}

View File

@@ -0,0 +1,43 @@
#include "../desktop_i.h"
#include "../views/desktop_first_start.h"
#include "applications/dolphin/dolphin.h"
void desktop_scene_first_start_callback(DesktopFirstStartEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
const void desktop_scene_first_start_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
DesktopFirstStartView* first_start_view = desktop->first_start_view;
desktop_first_start_set_callback(
first_start_view, desktop_scene_first_start_callback, desktop);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewFirstStart);
}
const bool desktop_scene_first_start_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopFirstStartCompleted:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
const void desktop_scene_first_start_on_exit(void* context) {
// Desktop* desktop = (Desktop*)context;
Dolphin* dolphin = furi_record_open("dolphin");
dolphin_save(dolphin);
furi_record_close("dolphin");
}

View File

@@ -0,0 +1,37 @@
#include "../desktop_i.h"
#include "../views/desktop_hw_mismatch.h"
void desktop_scene_hw_mismatch_callback(DesktopHwMismatchEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
const void desktop_scene_hw_mismatch_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_hw_mismatch_set_callback(
desktop->hw_mismatch_view, desktop_scene_hw_mismatch_callback, desktop);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewHwMismatch);
}
const bool desktop_scene_hw_mismatch_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopHwMismatchEventExit:
scene_manager_previous_scene(desktop->scene_manager);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
const void desktop_scene_hw_mismatch_on_exit(void* context) {
// Desktop* desktop = (Desktop*)context;
}

View File

@@ -0,0 +1,42 @@
#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);
}
const void desktop_scene_lock_menu_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewLockMenu);
}
const 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_next_scene(desktop->scene_manager, DesktopSceneLocked);
consumed = true;
break;
case DesktopLockMenuEventExit:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
const void desktop_scene_lock_menu_on_exit(void* context) {
Desktop* desktop = (Desktop*)context;
desktop_lock_menu_reset_idx(desktop->lock_menu);
}

View File

@@ -0,0 +1,51 @@
#include "../desktop_i.h"
#include "../views/desktop_locked.h"
void desktop_scene_locked_callback(DesktopLockedEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
const void desktop_scene_locked_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
DesktopLockedView* locked_view = desktop->locked_view;
desktop_locked_set_callback(locked_view, desktop_scene_locked_callback, desktop);
desktop_locked_reset_door_pos(locked_view);
desktop_locked_update_hint_timeout(locked_view);
view_port_enabled_set(desktop->lock_viewport, true);
osTimerStart(locked_view->timer, 63);
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewLocked);
}
const bool desktop_scene_locked_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopLockedEventUnlock:
scene_manager_set_scene_state(
desktop->scene_manager, DesktopSceneMain, DesktopMainEventUnlocked);
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
consumed = true;
break;
case DesktopLockedEventUpdate:
desktop_locked_manage_redraw(desktop->locked_view);
consumed = true;
default:
break;
}
}
return consumed;
}
const void desktop_scene_locked_on_exit(void* context) {
Desktop* desktop = (Desktop*)context;
DesktopLockedView* locked_view = desktop->locked_view;
desktop_locked_reset_counter(desktop->locked_view);
osTimerStop(locked_view->timer);
}

View File

@@ -0,0 +1,88 @@
#include "../desktop_i.h"
#include "../views/desktop_main.h"
#include "applications.h"
#define MAIN_VIEW_DEFAULT (0UL)
static void desktop_switch_to_app(Desktop* desktop, const FlipperApplication* flipper_app) {
furi_assert(desktop);
furi_assert(flipper_app);
furi_assert(flipper_app->app);
furi_assert(flipper_app->name);
if(furi_thread_get_state(desktop->scene_thread) != FuriThreadStateStopped) {
FURI_LOG_E("Desktop", "Thread is already running");
return;
}
furi_thread_set_name(desktop->scene_thread, flipper_app->name);
furi_thread_set_stack_size(desktop->scene_thread, flipper_app->stack_size);
furi_thread_set_callback(desktop->scene_thread, flipper_app->app);
furi_thread_start(desktop->scene_thread);
}
void desktop_scene_main_callback(DesktopMainEvent event, void* context) {
Desktop* desktop = (Desktop*)context;
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
}
const void desktop_scene_main_on_enter(void* context) {
Desktop* desktop = (Desktop*)context;
DesktopMainView* main_view = desktop->main_view;
desktop_main_set_callback(main_view, desktop_scene_main_callback, desktop);
view_port_enabled_set(desktop->lock_viewport, false);
if(scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneMain) ==
DesktopMainEventUnlocked) {
desktop_main_unlocked(desktop->main_view);
}
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewMain);
}
const bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
Desktop* desktop = (Desktop*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DesktopMainEventOpenMenu:
with_value_mutex(
desktop->menu_vm, (Menu * menu) { menu_ok(menu); });
consumed = true;
break;
case DesktopMainEventOpenLockMenu:
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLockMenu);
consumed = true;
break;
case DesktopMainEventOpenDebug:
scene_manager_next_scene(desktop->scene_manager, DesktopViewDebug);
consumed = true;
break;
case DesktopMainEventOpenArchive:
desktop_switch_to_app(desktop, &FLIPPER_ARCHIVE);
consumed = true;
break;
case DesktopMainEventOpenFavorite:
desktop_settings_load(&desktop->settings);
desktop_switch_to_app(desktop, &FLIPPER_APPS[desktop->settings.favorite]);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
const void desktop_scene_main_on_exit(void* context) {
Desktop* desktop = (Desktop*)context;
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneMain, MAIN_VIEW_DEFAULT);
desktop_main_reset_hint(desktop->main_view);
}