mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 15:38:35 -07:00
Merge desktop service changes, refactor some old code
This commit is contained in:
@@ -14,5 +14,5 @@ App(
|
|||||||
conflicts=["updater"],
|
conflicts=["updater"],
|
||||||
stack_size=2 * 1024,
|
stack_size=2 * 1024,
|
||||||
order=60,
|
order=60,
|
||||||
sdk_headers=["desktop_settings.h"],
|
sdk_headers=["desktop.h"],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,32 +1,26 @@
|
|||||||
#include <storage/storage.h>
|
#include "desktop_i.h"
|
||||||
#include <assets_icons.h>
|
|
||||||
#include <gui/gui.h>
|
|
||||||
#include <gui/gui_i.h>
|
|
||||||
#include <gui/view_stack.h>
|
|
||||||
#include <notification/notification.h>
|
|
||||||
#include <notification/notification_messages.h>
|
|
||||||
#include <furi.h>
|
|
||||||
#include <furi_hal.h>
|
|
||||||
#include <cli/cli.h>
|
#include <cli/cli.h>
|
||||||
#include <cli/cli_vcp.h>
|
#include <cli/cli_vcp.h>
|
||||||
#include <locale/locale.h>
|
|
||||||
#include <applications/main/archive/helpers/archive_helpers_ext.h>
|
|
||||||
#include <momentum/momentum.h>
|
|
||||||
|
|
||||||
#include "animations/animation_manager.h"
|
#include <gui/gui_i.h>
|
||||||
#include "desktop/scenes/desktop_scene.h"
|
|
||||||
#include "desktop/scenes/desktop_scene_i.h"
|
#include <locale/locale.h>
|
||||||
#include "desktop/views/desktop_view_locked.h"
|
#include <storage/storage.h>
|
||||||
#include "desktop/views/desktop_view_pin_input.h"
|
#include <momentum/settings.h>
|
||||||
#include "desktop/views/desktop_view_pin_timeout.h"
|
#include <applications/main/archive/helpers/archive_helpers_ext.h>
|
||||||
#include "desktop_i.h"
|
|
||||||
#include "helpers/pin.h"
|
#include <assets_icons.h>
|
||||||
|
|
||||||
|
#include "scenes/desktop_scene.h"
|
||||||
|
#include "scenes/desktop_scene_locked.h"
|
||||||
|
|
||||||
#define TAG "Desktop"
|
#define TAG "Desktop"
|
||||||
|
|
||||||
static void desktop_auto_lock_arm(Desktop*);
|
static void desktop_auto_lock_arm(Desktop*);
|
||||||
static void desktop_auto_lock_inhibit(Desktop*);
|
static void desktop_auto_lock_inhibit(Desktop*);
|
||||||
static void desktop_start_auto_lock_timer(Desktop*);
|
static void desktop_start_auto_lock_timer(Desktop*);
|
||||||
|
static void desktop_apply_settings(Desktop*);
|
||||||
|
|
||||||
static void desktop_loader_callback(const void* message, void* context) {
|
static void desktop_loader_callback(const void* message, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
@@ -43,6 +37,16 @@ static void desktop_loader_callback(const void* message, void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void desktop_storage_callback(const void* message, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
Desktop* desktop = context;
|
||||||
|
const StorageEvent* event = message;
|
||||||
|
|
||||||
|
if(event->type == StorageEventTypeCardMount) {
|
||||||
|
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalReloadSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
furi_assert(canvas);
|
furi_assert(canvas);
|
||||||
@@ -117,27 +121,39 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
|||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
|
|
||||||
switch(event) {
|
if(event == DesktopGlobalBeforeAppStarted) {
|
||||||
case DesktopGlobalBeforeAppStarted:
|
|
||||||
if(animation_manager_is_animation_loaded(desktop->animation_manager)) {
|
if(animation_manager_is_animation_loaded(desktop->animation_manager)) {
|
||||||
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_auto_lock_inhibit(desktop);
|
desktop_auto_lock_inhibit(desktop);
|
||||||
|
desktop->app_running = true;
|
||||||
|
|
||||||
furi_semaphore_release(desktop->animation_semaphore);
|
furi_semaphore_release(desktop->animation_semaphore);
|
||||||
return true;
|
|
||||||
case DesktopGlobalAfterAppFinished:
|
} else if(event == DesktopGlobalAfterAppFinished) {
|
||||||
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
||||||
desktop_clock_reconfigure(desktop);
|
|
||||||
desktop_auto_lock_arm(desktop);
|
desktop_auto_lock_arm(desktop);
|
||||||
return true;
|
desktop->app_running = false;
|
||||||
case DesktopGlobalAutoLock:
|
|
||||||
if(!loader_is_locked(desktop->loader) && !desktop->locked) {
|
} else if(event == DesktopGlobalAutoLock) {
|
||||||
|
if(!desktop->app_running && !desktop->locked) {
|
||||||
desktop_lock(desktop, desktop->settings.auto_lock_with_pin);
|
desktop_lock(desktop, desktop->settings.auto_lock_with_pin);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
} else if(event == DesktopGlobalSaveSettings) {
|
||||||
|
desktop_settings_save(&desktop->settings);
|
||||||
|
desktop_apply_settings(desktop);
|
||||||
|
|
||||||
|
} else if(event == DesktopGlobalReloadSettings) {
|
||||||
|
desktop_settings_load(&desktop->settings);
|
||||||
|
desktop_apply_settings(desktop);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return scene_manager_handle_custom_event(desktop->scene_manager, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scene_manager_handle_custom_event(desktop->scene_manager, event);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool desktop_back_event_callback(void* context) {
|
static bool desktop_back_event_callback(void* context) {
|
||||||
@@ -205,87 +221,42 @@ static void desktop_clock_timer_callback(void* context) {
|
|||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Desktop* desktop = context;
|
Desktop* desktop = context;
|
||||||
|
|
||||||
if(gui_active_view_port_count(desktop->gui, GuiLayerStatusBarLeft) < 6) {
|
const bool clock_enabled = gui_active_view_port_count(desktop->gui, GuiLayerStatusBarLeft) < 6;
|
||||||
|
|
||||||
|
if(clock_enabled) {
|
||||||
desktop_clock_update(desktop);
|
desktop_clock_update(desktop);
|
||||||
|
|
||||||
view_port_enabled_set(desktop->clock_viewport, true);
|
|
||||||
} else {
|
|
||||||
view_port_enabled_set(desktop->clock_viewport, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view_port_enabled_set(desktop->clock_viewport, clock_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktop_lock(Desktop* desktop, bool pin_lock) {
|
static void desktop_apply_settings(Desktop* desktop) {
|
||||||
furi_assert(!desktop->locked);
|
|
||||||
|
|
||||||
pin_lock = pin_lock && desktop_pin_is_valid(&desktop->settings.pin_code);
|
|
||||||
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
|
||||||
furi_hal_rtc_set_pin_fails(0);
|
|
||||||
}
|
|
||||||
if(pin_lock) {
|
|
||||||
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
|
||||||
Cli* cli = furi_record_open(RECORD_CLI);
|
|
||||||
cli_session_close(cli);
|
|
||||||
furi_record_close(RECORD_CLI);
|
|
||||||
if(!momentum_settings.allow_locked_rpc_commands) {
|
|
||||||
Bt* bt = furi_record_open(RECORD_BT);
|
|
||||||
bt_close_rpc_connection(bt);
|
|
||||||
furi_record_close(RECORD_BT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
desktop_auto_lock_inhibit(desktop);
|
|
||||||
scene_manager_set_scene_state(
|
|
||||||
desktop->scene_manager, DesktopSceneLocked, SCENE_LOCKED_FIRST_ENTER);
|
|
||||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
|
||||||
|
|
||||||
DesktopStatus status = {.locked = true};
|
|
||||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
|
||||||
|
|
||||||
desktop->locked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void desktop_unlock(Desktop* desktop) {
|
|
||||||
furi_assert(desktop->locked);
|
|
||||||
|
|
||||||
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
|
||||||
gui_set_lockdown(gui, false);
|
|
||||||
furi_record_close(RECORD_GUI);
|
|
||||||
desktop_view_locked_unlock(desktop->locked_view);
|
|
||||||
scene_manager_search_and_switch_to_previous_scene(desktop->scene_manager, DesktopSceneMain);
|
|
||||||
desktop_auto_lock_arm(desktop);
|
|
||||||
|
|
||||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
|
||||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
|
||||||
furi_hal_rtc_set_pin_fails(0);
|
|
||||||
Cli* cli = furi_record_open(RECORD_CLI);
|
|
||||||
cli_session_open(cli, &cli_vcp);
|
|
||||||
furi_record_close(RECORD_CLI);
|
|
||||||
}
|
|
||||||
|
|
||||||
Bt* bt = furi_record_open(RECORD_BT);
|
|
||||||
bt_open_rpc_connection(bt);
|
|
||||||
furi_record_close(RECORD_BT);
|
|
||||||
|
|
||||||
DesktopStatus status = {.locked = false};
|
|
||||||
furi_pubsub_publish(desktop->status_pubsub, &status);
|
|
||||||
|
|
||||||
desktop->locked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
|
|
||||||
desktop->in_transition = true;
|
desktop->in_transition = true;
|
||||||
if(enabled) {
|
|
||||||
furi_hal_rtc_set_flag(FuriHalRtcFlagStealthMode);
|
desktop_clock_reconfigure(desktop);
|
||||||
} else {
|
|
||||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagStealthMode);
|
view_port_enabled_set(desktop->dummy_mode_icon_viewport, desktop->settings.dummy_mode);
|
||||||
|
|
||||||
|
if(!desktop->app_running && !desktop->locked) {
|
||||||
|
desktop_auto_lock_arm(desktop);
|
||||||
}
|
}
|
||||||
desktop_lock_menu_set_stealth_mode_state(desktop->lock_menu, enabled);
|
|
||||||
view_port_enabled_set(desktop->stealth_mode_icon_viewport, enabled);
|
|
||||||
desktop->in_transition = false;
|
desktop->in_transition = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Desktop* desktop_alloc(void) {
|
static void desktop_init_settings(Desktop* desktop) {
|
||||||
|
furi_pubsub_subscribe(storage_get_pubsub(desktop->storage), desktop_storage_callback, desktop);
|
||||||
|
|
||||||
|
if(storage_sd_status(desktop->storage) != FSE_OK) {
|
||||||
|
FURI_LOG_D(TAG, "SD Card not ready, skipping settings");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
desktop_settings_load(&desktop->settings);
|
||||||
|
desktop_apply_settings(desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Desktop* desktop_alloc(void) {
|
||||||
Desktop* desktop = malloc(sizeof(Desktop));
|
Desktop* desktop = malloc(sizeof(Desktop));
|
||||||
|
|
||||||
desktop->animation_semaphore = furi_semaphore_alloc(1, 0);
|
desktop->animation_semaphore = furi_semaphore_alloc(1, 0);
|
||||||
@@ -383,16 +354,14 @@ Desktop* desktop_alloc(void) {
|
|||||||
}
|
}
|
||||||
gui_add_view_port(desktop->gui, desktop->stealth_mode_icon_viewport, GuiLayerStatusBarLeft);
|
gui_add_view_port(desktop->gui, desktop->stealth_mode_icon_viewport, GuiLayerStatusBarLeft);
|
||||||
|
|
||||||
|
// Unload animations before starting an application
|
||||||
desktop->loader = furi_record_open(RECORD_LOADER);
|
desktop->loader = furi_record_open(RECORD_LOADER);
|
||||||
|
furi_pubsub_subscribe(loader_get_pubsub(desktop->loader), desktop_loader_callback, desktop);
|
||||||
|
|
||||||
|
desktop->storage = furi_record_open(RECORD_STORAGE);
|
||||||
desktop->notification = furi_record_open(RECORD_NOTIFICATION);
|
desktop->notification = furi_record_open(RECORD_NOTIFICATION);
|
||||||
desktop->app_start_stop_subscription = furi_pubsub_subscribe(
|
|
||||||
loader_get_pubsub(desktop->loader), desktop_loader_callback, desktop);
|
|
||||||
|
|
||||||
desktop->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
desktop->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
||||||
desktop->input_events_subscription = NULL;
|
|
||||||
desktop->ascii_events_pubsub = furi_record_open(RECORD_ASCII_EVENTS);
|
desktop->ascii_events_pubsub = furi_record_open(RECORD_ASCII_EVENTS);
|
||||||
desktop->ascii_events_subscription = NULL;
|
|
||||||
|
|
||||||
desktop->auto_lock_timer =
|
desktop->auto_lock_timer =
|
||||||
furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop);
|
furi_timer_alloc(desktop_auto_lock_timer_callback, FuriTimerTypeOnce, desktop);
|
||||||
@@ -402,19 +371,95 @@ Desktop* desktop_alloc(void) {
|
|||||||
desktop->update_clock_timer =
|
desktop->update_clock_timer =
|
||||||
furi_timer_alloc(desktop_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
furi_timer_alloc(desktop_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
||||||
|
|
||||||
|
desktop->app_running = loader_is_locked(desktop->loader);
|
||||||
|
|
||||||
furi_record_create(RECORD_DESKTOP, desktop);
|
furi_record_create(RECORD_DESKTOP, desktop);
|
||||||
|
|
||||||
return desktop;
|
return desktop;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool desktop_check_file_flag(const char* flag_path) {
|
/*
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
* Private API
|
||||||
bool exists = storage_common_stat(storage, flag_path, NULL) == FSE_OK;
|
*/
|
||||||
furi_record_close(RECORD_STORAGE);
|
|
||||||
|
|
||||||
return exists;
|
void desktop_lock(Desktop* desktop, bool with_pin) {
|
||||||
|
furi_assert(!desktop->locked);
|
||||||
|
|
||||||
|
with_pin = with_pin && desktop_pin_code_is_set();
|
||||||
|
if(!furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
||||||
|
furi_hal_rtc_set_pin_fails(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(with_pin) {
|
||||||
|
furi_hal_rtc_set_flag(FuriHalRtcFlagLock);
|
||||||
|
if(!momentum_settings.allow_locked_rpc_commands) {
|
||||||
|
Cli* cli = furi_record_open(RECORD_CLI);
|
||||||
|
cli_session_close(cli);
|
||||||
|
furi_record_close(RECORD_CLI);
|
||||||
|
Bt* bt = furi_record_open(RECORD_BT);
|
||||||
|
bt_close_rpc_connection(bt);
|
||||||
|
furi_record_close(RECORD_BT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
desktop_auto_lock_inhibit(desktop);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
desktop->scene_manager, DesktopSceneLocked, DesktopSceneLockedStateFirstEnter);
|
||||||
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLocked);
|
||||||
|
|
||||||
|
DesktopStatus status = {.locked = true};
|
||||||
|
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||||
|
|
||||||
|
desktop->locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void desktop_unlock(Desktop* desktop) {
|
||||||
|
furi_assert(desktop->locked);
|
||||||
|
|
||||||
|
view_port_enabled_set(desktop->lock_icon_viewport, false);
|
||||||
|
Gui* gui = furi_record_open(RECORD_GUI);
|
||||||
|
gui_set_lockdown(gui, false);
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
desktop_view_locked_unlock(desktop->locked_view);
|
||||||
|
scene_manager_search_and_switch_to_previous_scene(desktop->scene_manager, DesktopSceneMain);
|
||||||
|
desktop_auto_lock_arm(desktop);
|
||||||
|
bool with_pin = furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock);
|
||||||
|
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
||||||
|
furi_hal_rtc_set_pin_fails(0);
|
||||||
|
|
||||||
|
if(with_pin) {
|
||||||
|
Cli* cli = furi_record_open(RECORD_CLI);
|
||||||
|
cli_session_open(cli, &cli_vcp);
|
||||||
|
furi_record_close(RECORD_CLI);
|
||||||
|
Bt* bt = furi_record_open(RECORD_BT);
|
||||||
|
bt_open_rpc_connection(bt);
|
||||||
|
furi_record_close(RECORD_BT);
|
||||||
|
}
|
||||||
|
|
||||||
|
DesktopStatus status = {.locked = false};
|
||||||
|
furi_pubsub_publish(desktop->status_pubsub, &status);
|
||||||
|
|
||||||
|
desktop->locked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void desktop_set_stealth_mode_state(Desktop* desktop, bool enabled) {
|
||||||
|
desktop->in_transition = true;
|
||||||
|
|
||||||
|
if(enabled) {
|
||||||
|
furi_hal_rtc_set_flag(FuriHalRtcFlagStealthMode);
|
||||||
|
} else {
|
||||||
|
furi_hal_rtc_reset_flag(FuriHalRtcFlagStealthMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_port_enabled_set(desktop->stealth_mode_icon_viewport, enabled);
|
||||||
|
|
||||||
|
desktop->in_transition = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public API
|
||||||
|
*/
|
||||||
|
|
||||||
bool desktop_api_is_locked(Desktop* instance) {
|
bool desktop_api_is_locked(Desktop* instance) {
|
||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
return furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock);
|
return furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock);
|
||||||
@@ -430,6 +475,26 @@ FuriPubSub* desktop_api_get_status_pubsub(Desktop* instance) {
|
|||||||
return instance->status_pubsub;
|
return instance->status_pubsub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void desktop_api_reload_settings(Desktop* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopGlobalReloadSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void desktop_api_get_settings(Desktop* instance, DesktopSettings* settings) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(settings);
|
||||||
|
|
||||||
|
*settings = instance->settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void desktop_api_set_settings(Desktop* instance, const DesktopSettings* settings) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_assert(settings);
|
||||||
|
|
||||||
|
instance->settings = *settings;
|
||||||
|
view_dispatcher_send_custom_event(instance->view_dispatcher, DesktopGlobalSaveSettings);
|
||||||
|
}
|
||||||
|
|
||||||
static const KeybindType keybind_types[] = {
|
static const KeybindType keybind_types[] = {
|
||||||
[InputTypeShort] = KeybindTypePress,
|
[InputTypeShort] = KeybindTypePress,
|
||||||
[InputTypeLong] = KeybindTypeHold,
|
[InputTypeLong] = KeybindTypeHold,
|
||||||
@@ -479,6 +544,10 @@ void desktop_run_keybind(Desktop* instance, InputType _type, InputKey _key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Application thread
|
||||||
|
*/
|
||||||
|
|
||||||
int32_t desktop_srv(void* p) {
|
int32_t desktop_srv(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
|
||||||
@@ -491,31 +560,15 @@ int32_t desktop_srv(void* p) {
|
|||||||
|
|
||||||
Desktop* desktop = desktop_alloc();
|
Desktop* desktop = desktop_alloc();
|
||||||
|
|
||||||
bool ok = DESKTOP_SETTINGS_LOAD(&desktop->settings);
|
desktop_init_settings(desktop);
|
||||||
if(ok && desktop->settings.pin_code.length) {
|
|
||||||
ok = desktop_pin_is_valid(&desktop->settings.pin_code);
|
|
||||||
}
|
|
||||||
if(!ok) {
|
|
||||||
memset(&desktop->settings, 0, sizeof(desktop->settings));
|
|
||||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
|
||||||
furi_hal_rtc_set_pin_fails(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
DESKTOP_KEYBINDS_LOAD(&desktop->keybinds, sizeof(desktop->keybinds));
|
|
||||||
|
|
||||||
desktop_clock_reconfigure(desktop);
|
|
||||||
|
|
||||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||||
|
|
||||||
if(momentum_settings.lock_on_boot || furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
if(momentum_settings.lock_on_boot || furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
|
||||||
desktop_lock(desktop, true);
|
desktop_lock(desktop, true);
|
||||||
} else {
|
|
||||||
if(!loader_is_locked(desktop->loader)) {
|
|
||||||
desktop_auto_lock_arm(desktop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(desktop_check_file_flag(SLIDESHOW_FS_PATH)) {
|
if(storage_file_exists(desktop->storage, SLIDESHOW_FS_PATH)) {
|
||||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow);
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneSlideshow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,14 +592,12 @@ int32_t desktop_srv(void* p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special case: autostart application is already running
|
// Special case: autostart application is already running
|
||||||
if(loader_is_locked(desktop->loader) &&
|
if(desktop->app_running && animation_manager_is_animation_loaded(desktop->animation_manager)) {
|
||||||
animation_manager_is_animation_loaded(desktop->animation_manager)) {
|
|
||||||
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
animation_manager_unload_and_stall_animation(desktop->animation_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
view_dispatcher_run(desktop->view_dispatcher);
|
view_dispatcher_run(desktop->view_dispatcher);
|
||||||
|
|
||||||
furi_crash("That was unexpected");
|
// Should never get here (a service thread will crash automatically if it returns)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,17 @@
|
|||||||
#include <desktop/desktop_settings.h>
|
#include <desktop/desktop_settings.h>
|
||||||
#include "../views/desktop_view_lock_menu.h"
|
#include "../views/desktop_view_lock_menu.h"
|
||||||
#include "desktop_scene.h"
|
#include "desktop_scene.h"
|
||||||
#include "../helpers/pin.h"
|
#include "../helpers/pin_code.h"
|
||||||
#include <power/power_service/power.h>
|
#include <power/power_service/power.h>
|
||||||
|
|
||||||
#define TAG "DesktopSceneLock"
|
#define TAG "DesktopSceneLock"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CheckPinNo,
|
||||||
|
CheckPinLock,
|
||||||
|
CheckPinLockOff,
|
||||||
|
} CheckPin;
|
||||||
|
|
||||||
void desktop_scene_lock_menu_callback(DesktopEvent event, void* context) {
|
void desktop_scene_lock_menu_callback(DesktopEvent event, void* context) {
|
||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
|
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
|
||||||
@@ -22,17 +29,14 @@ void desktop_scene_lock_menu_callback(DesktopEvent event, void* context) {
|
|||||||
void desktop_scene_lock_menu_on_enter(void* context) {
|
void desktop_scene_lock_menu_on_enter(void* context) {
|
||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
|
|
||||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, CheckPinNo);
|
||||||
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
|
desktop_lock_menu_set_callback(desktop->lock_menu, desktop_scene_lock_menu_callback, desktop);
|
||||||
desktop_lock_menu_set_pin_state(
|
desktop_lock_menu_set_pin_state(desktop->lock_menu, desktop_pin_code_is_set());
|
||||||
desktop->lock_menu, desktop_pin_is_valid(&desktop->settings.pin_code));
|
|
||||||
desktop_lock_menu_set_stealth_mode_state(
|
desktop_lock_menu_set_stealth_mode_state(
|
||||||
desktop->lock_menu, furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode));
|
desktop->lock_menu, furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode));
|
||||||
desktop_lock_menu_set_idx(desktop->lock_menu, 3);
|
desktop_lock_menu_set_idx(desktop->lock_menu, 3);
|
||||||
|
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
gui_set_hide_statusbar(desktop->gui, true);
|
||||||
gui_set_hide_statusbar(gui, true);
|
|
||||||
furi_record_close(RECORD_GUI);
|
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
|
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdLockMenu);
|
||||||
}
|
}
|
||||||
@@ -57,13 +61,14 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
|||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event.type == SceneManagerEventTypeTick) {
|
if(event.type == SceneManagerEventTypeTick) {
|
||||||
int check_pin_changed =
|
CheckPin check_pin_changed =
|
||||||
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
|
scene_manager_get_scene_state(desktop->scene_manager, DesktopSceneLockMenu);
|
||||||
if(check_pin_changed && desktop_pin_code_is_set()) {
|
if(check_pin_changed != CheckPinNo && desktop_pin_code_is_set()) {
|
||||||
desktop_lock_menu_set_pin_state(desktop->lock_menu, true);
|
desktop_lock_menu_set_pin_state(desktop->lock_menu, true);
|
||||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
scene_manager_set_scene_state(
|
||||||
|
desktop->scene_manager, DesktopSceneLockMenu, CheckPinNo);
|
||||||
desktop_lock(desktop, true);
|
desktop_lock(desktop, true);
|
||||||
if(check_pin_changed == 2) {
|
if(check_pin_changed == CheckPinLockOff) {
|
||||||
Power* power = furi_record_open(RECORD_POWER);
|
Power* power = furi_record_open(RECORD_POWER);
|
||||||
furi_delay_ms(500);
|
furi_delay_ms(500);
|
||||||
power_off(power);
|
power_off(power);
|
||||||
@@ -85,18 +90,19 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
|||||||
break;
|
break;
|
||||||
case DesktopLockMenuEventLockPinCode:
|
case DesktopLockMenuEventLockPinCode:
|
||||||
desktop_scene_lock_menu_save_settings(desktop);
|
desktop_scene_lock_menu_save_settings(desktop);
|
||||||
if(desktop_pin_is_valid(&desktop->settings.pin_code)) {
|
if(desktop_pin_code_is_set()) {
|
||||||
desktop_lock(desktop, true);
|
desktop_lock(desktop, true);
|
||||||
} else {
|
} else {
|
||||||
loader_start_detached_with_gui_error(
|
loader_start_detached_with_gui_error(
|
||||||
desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
|
desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
|
||||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 1);
|
scene_manager_set_scene_state(
|
||||||
|
desktop->scene_manager, DesktopSceneLockMenu, CheckPinLock);
|
||||||
}
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
case DesktopLockMenuEventLockPinOff:
|
case DesktopLockMenuEventLockPinOff:
|
||||||
desktop_scene_lock_menu_save_settings(desktop);
|
desktop_scene_lock_menu_save_settings(desktop);
|
||||||
if(desktop_pin_is_valid(&desktop->settings.pin_code)) {
|
if(desktop_pin_code_is_set()) {
|
||||||
desktop_lock(desktop, true);
|
desktop_lock(desktop, true);
|
||||||
Power* power = furi_record_open(RECORD_POWER);
|
Power* power = furi_record_open(RECORD_POWER);
|
||||||
furi_delay_ms(500);
|
furi_delay_ms(500);
|
||||||
@@ -105,7 +111,8 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
|||||||
} else {
|
} else {
|
||||||
loader_start_detached_with_gui_error(
|
loader_start_detached_with_gui_error(
|
||||||
desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
|
desktop->loader, "Desktop", DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG);
|
||||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 2);
|
scene_manager_set_scene_state(
|
||||||
|
desktop->scene_manager, DesktopSceneLockMenu, CheckPinLockOff);
|
||||||
}
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
break;
|
break;
|
||||||
@@ -124,7 +131,7 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if(event.type == SceneManagerEventTypeBack) {
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, 0);
|
scene_manager_set_scene_state(desktop->scene_manager, DesktopSceneLockMenu, CheckPinNo);
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
@@ -133,7 +140,5 @@ void desktop_scene_lock_menu_on_exit(void* context) {
|
|||||||
Desktop* desktop = (Desktop*)context;
|
Desktop* desktop = (Desktop*)context;
|
||||||
desktop_scene_lock_menu_save_settings(desktop);
|
desktop_scene_lock_menu_save_settings(desktop);
|
||||||
|
|
||||||
Gui* gui = furi_record_open(RECORD_GUI);
|
gui_set_hide_statusbar(desktop->gui, false);
|
||||||
gui_set_hide_statusbar(gui, false);
|
|
||||||
furi_record_close(RECORD_GUI);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,10 +59,9 @@ static void desktop_scene_pin_input_done_callback(const DesktopPinCode* pin_code
|
|||||||
} else {
|
} else {
|
||||||
uint32_t pin_fails = furi_hal_rtc_get_pin_fails() + 1;
|
uint32_t pin_fails = furi_hal_rtc_get_pin_fails() + 1;
|
||||||
if(pin_fails >= 10 && momentum_settings.bad_pins_format) {
|
if(pin_fails >= 10 && momentum_settings.bad_pins_format) {
|
||||||
furi_hal_rtc_reset_registers();
|
|
||||||
furi_hal_rtc_set_flag(FuriHalRtcFlagStorageFormatInternal);
|
|
||||||
storage_sd_format(furi_record_open(RECORD_STORAGE));
|
storage_sd_format(furi_record_open(RECORD_STORAGE));
|
||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
furi_hal_rtc_reset_registers();
|
||||||
power_reboot(PowerBootModeNormal);
|
power_reboot(PowerBootModeNormal);
|
||||||
}
|
}
|
||||||
furi_hal_rtc_set_pin_fails(pin_fails);
|
furi_hal_rtc_set_pin_fails(pin_fails);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ void desktop_lock_menu_set_pin_state(DesktopLockMenuView* lock_menu, bool pin_is
|
|||||||
DesktopLockMenuViewModel * model,
|
DesktopLockMenuViewModel * model,
|
||||||
{
|
{
|
||||||
model->pin_is_set = pin_is_set;
|
model->pin_is_set = pin_is_set;
|
||||||
model->pin_lock = pin_is_set;
|
model->lock_popup_index = pin_is_set; // Select with PIN by default if set
|
||||||
},
|
},
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
@@ -166,13 +166,13 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m->show_lock_menu) {
|
if(m->show_lock_popup) {
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
elements_bold_rounded_frame(canvas, 24, 4, 80, 56);
|
elements_bold_rounded_frame(canvas, 24, 4, 80, 56);
|
||||||
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignCenter, "Keypad Lock");
|
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignCenter, "Keypad Lock");
|
||||||
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignCenter, "PIN Code Lock");
|
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignCenter, "PIN Code Lock");
|
||||||
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignCenter, "PIN Lock + OFF");
|
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignCenter, "PIN Lock + OFF");
|
||||||
elements_frame(canvas, 28, 8 + m->pin_lock * 16, 72, 15);
|
elements_frame(canvas, 28, 8 + m->lock_popup_index * 16, 72, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
|||||||
|
|
||||||
DesktopLockMenuView* lock_menu = context;
|
DesktopLockMenuView* lock_menu = context;
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
int pin_lock = 0;
|
bool show_lock_popup = false;
|
||||||
bool show_lock_menu = false;
|
DesktopLockMenuPopupIndex lock_popup_index = 0;
|
||||||
bool stealth_mode = false;
|
bool stealth_mode = false;
|
||||||
bool consumed = true;
|
bool consumed = true;
|
||||||
|
|
||||||
@@ -196,26 +196,28 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
|||||||
lock_menu->view,
|
lock_menu->view,
|
||||||
DesktopLockMenuViewModel * model,
|
DesktopLockMenuViewModel * model,
|
||||||
{
|
{
|
||||||
show_lock_menu = model->show_lock_menu;
|
show_lock_popup = model->show_lock_popup;
|
||||||
stealth_mode = model->stealth_mode;
|
stealth_mode = model->stealth_mode;
|
||||||
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
||||||
if(model->show_lock_menu) {
|
if(model->show_lock_popup) {
|
||||||
if(event->key == InputKeyUp) {
|
if(event->key == InputKeyUp) {
|
||||||
model->pin_lock--;
|
if(model->lock_popup_index == 0) {
|
||||||
if(model->pin_lock < 0) {
|
model->lock_popup_index = DesktopLockMenuPopupIndexMAX - 1;
|
||||||
model->pin_lock = 2;
|
} else {
|
||||||
|
model->lock_popup_index--;
|
||||||
}
|
}
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
model->pin_lock++;
|
if(model->lock_popup_index == DesktopLockMenuPopupIndexMAX - 1) {
|
||||||
if(model->pin_lock > 2) {
|
model->lock_popup_index = 0;
|
||||||
model->pin_lock = 0;
|
} else {
|
||||||
|
model->lock_popup_index++;
|
||||||
}
|
}
|
||||||
} else if(event->key == InputKeyBack || event->key == InputKeyOk) {
|
} else if(event->key == InputKeyBack || event->key == InputKeyOk) {
|
||||||
model->show_lock_menu = false;
|
model->show_lock_popup = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(model->idx == DesktopLockMenuIndexLock && event->key == InputKeyOk) {
|
if(model->idx == DesktopLockMenuIndexLock && event->key == InputKeyOk) {
|
||||||
model->show_lock_menu = true;
|
model->show_lock_popup = true;
|
||||||
} else if(model->idx < 6) {
|
} else if(model->idx < 6) {
|
||||||
if(event->key == InputKeyUp || event->key == InputKeyDown) {
|
if(event->key == InputKeyUp || event->key == InputKeyDown) {
|
||||||
if(model->idx % 2) {
|
if(model->idx % 2) {
|
||||||
@@ -250,21 +252,21 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
idx = model->idx;
|
idx = model->idx;
|
||||||
pin_lock = model->pin_lock;
|
lock_popup_index = model->lock_popup_index;
|
||||||
},
|
},
|
||||||
true);
|
true);
|
||||||
|
|
||||||
DesktopEvent desktop_event = 0;
|
DesktopEvent desktop_event = 0;
|
||||||
if(show_lock_menu) {
|
if(show_lock_popup) {
|
||||||
if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||||
switch(pin_lock) {
|
switch(lock_popup_index) {
|
||||||
case 0:
|
case DesktopLockMenuPopupIndexKeypad:
|
||||||
desktop_event = DesktopLockMenuEventLockKeypad;
|
desktop_event = DesktopLockMenuEventLockKeypad;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case DesktopLockMenuPopupIndexPinCode:
|
||||||
desktop_event = DesktopLockMenuEventLockPinCode;
|
desktop_event = DesktopLockMenuEventLockPinCode;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case DesktopLockMenuPopupIndexPinOff:
|
||||||
desktop_event = DesktopLockMenuEventLockPinOff;
|
desktop_event = DesktopLockMenuEventLockPinOff;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -23,14 +23,21 @@ struct DesktopLockMenuView {
|
|||||||
bool save_bt;
|
bool save_bt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DesktopLockMenuPopupIndexKeypad,
|
||||||
|
DesktopLockMenuPopupIndexPinCode,
|
||||||
|
DesktopLockMenuPopupIndexPinOff,
|
||||||
|
DesktopLockMenuPopupIndexMAX,
|
||||||
|
} DesktopLockMenuPopupIndex;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t idx;
|
uint8_t idx;
|
||||||
bool _dummy_mode; // Unused, kept for compatibility
|
bool _dummy_mode; // Unused, kept for compatibility
|
||||||
bool stealth_mode;
|
bool stealth_mode;
|
||||||
|
|
||||||
bool pin_is_set;
|
bool pin_is_set;
|
||||||
int pin_lock;
|
bool show_lock_popup;
|
||||||
bool show_lock_menu;
|
DesktopLockMenuPopupIndex lock_popup_index;
|
||||||
DesktopLockMenuView* lock_menu;
|
DesktopLockMenuView* lock_menu;
|
||||||
} DesktopLockMenuViewModel;
|
} DesktopLockMenuViewModel;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user