Sync desktop settings app to new stuffs

This commit is contained in:
Willy-JL
2024-08-07 22:15:59 +02:00
parent 06cb63f4bf
commit b14944b029
9 changed files with 46 additions and 37 deletions

View File

@@ -73,7 +73,6 @@ DesktopSettingsApp* desktop_settings_app_alloc(void) {
DesktopSettingsApp* app = malloc(sizeof(DesktopSettingsApp));
app->gui = furi_record_open(RECORD_GUI);
app->desktop = furi_record_open(RECORD_DESKTOP);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&desktop_settings_scene_handlers, app);
@@ -142,20 +141,21 @@ void desktop_settings_app_free(DesktopSettingsApp* app) {
scene_manager_free(app->scene_manager);
// Records
furi_record_close(RECORD_DIALOGS);
furi_record_close(RECORD_DESKTOP);
furi_record_close(RECORD_GUI);
free(app);
}
extern int32_t desktop_settings_app(void* p) {
UNUSED(p);
DesktopSettingsApp* app = desktop_settings_app_alloc();
Desktop* desktop = furi_record_open(RECORD_DESKTOP);
desktop_api_get_settings(desktop, &app->settings);
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneStart);
if(p && (strcmp(p, DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG) == 0)) {
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinSetupHowto);
} else {
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneStart);
}
view_dispatcher_run(app->view_dispatcher);

View File

@@ -10,7 +10,7 @@
#include <dialogs/dialogs.h>
#include <assets_icons.h>
#include <desktop/desktop_i.h>
#include <desktop/desktop_settings.h>
#include <desktop/views/desktop_view_pin_input.h>
#include "views/desktop_settings_view_pin_setup_howto.h"
#include "views/desktop_settings_view_pin_setup_howto2.h"
@@ -37,7 +37,7 @@ extern const char* EXTRA_KEYBINDS[];
extern const size_t EXTRA_KEYBINDS_COUNT;
typedef struct {
Desktop* desktop;
DesktopSettings settings;
Gui* gui;
DialogsApp* dialogs;
@@ -55,8 +55,6 @@ typedef struct {
bool pincode_buffer_filled;
uint32_t pin_menu_idx;
bool save_settings;
} DesktopSettingsApp;
const char* desktop_settings_app_get_keybind(DesktopSettingsApp* app);

View File

@@ -1 +0,0 @@
#include <applications/services/desktop/helpers/pin.c>

View File

@@ -0,0 +1,5 @@
// Since settings app is external, it cannot access firmware functions
// For simple utils like this, easier to include C code in app too
// Instead of copying the file, can (ab)use preprocessor to copy source code here
#include <applications/services/desktop/helpers/pin_code.c>
// Then, we still use the Header from original code as if nothing happened

View File

@@ -4,7 +4,6 @@
#include "../desktop_settings_app.h"
#include "desktop_settings_scene.h"
#include "desktop_settings_scene_i.h"
#include "desktop/helpers/pin.h"
#define SCENE_EVENT_SET_PIN 0
#define SCENE_EVENT_CHANGE_PIN 1

View File

@@ -49,8 +49,6 @@ bool desktop_settings_scene_pin_setup_done_on_event(void* context, SceneManagerE
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SCENE_EVENT_DONE: {
memcpy(&app->desktop->settings.pin_code, &app->pincode_buffer, sizeof(PinCode));
app->save_settings = true;
bool scene_found = false;
scene_found = scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, DesktopSettingsAppScenePinMenu);

View File

@@ -4,16 +4,16 @@
#include "../desktop_settings_app.h"
#include "desktop_settings_scene.h"
enum VarItemListIndex {
VarItemListIndexKeybinds,
VarItemListIndexResetKeybinds,
VarItemListIndexPinSetup,
VarItemListIndexAutoLockTime,
VarItemListIndexAutoLockPin,
};
typedef enum {
DesktopSettingsPinSetup = 0,
DesktopSettingsKeybindSetup,
DesktopSettingsResetKeybinds,
DesktopSettingsAutoLockDelay,
DesktopSettingsAutoLockPin,
} DesktopSettingsEntry;
#define AUTO_LOCK_DELAY_COUNT 9
const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
static const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
"OFF",
"10s",
"15s",
@@ -24,7 +24,7 @@ const char* const auto_lock_delay_text[AUTO_LOCK_DELAY_COUNT] = {
"5min",
"10min",
};
const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
static const uint32_t auto_lock_delay_value[AUTO_LOCK_DELAY_COUNT] =
{0, 10000, 15000, 30000, 60000, 90000, 120000, 300000, 600000};
static void desktop_settings_scene_start_var_list_enter_callback(void* context, uint32_t index) {
@@ -37,8 +37,7 @@ static void desktop_settings_scene_start_auto_lock_delay_changed(VariableItem* i
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, auto_lock_delay_text[index]);
app->desktop->settings.auto_lock_delay_ms = auto_lock_delay_value[index];
app->save_settings = true;
app->settings.auto_lock_delay_ms = auto_lock_delay_value[index];
}
static void desktop_settings_scene_start_auto_lock_pin_changed(VariableItem* item) {
@@ -46,8 +45,7 @@ static void desktop_settings_scene_start_auto_lock_pin_changed(VariableItem* ite
uint8_t value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
app->desktop->settings.auto_lock_with_pin = value;
app->save_settings = true;
app->settings.auto_lock_with_pin = value;
}
void desktop_settings_scene_start_on_enter(void* context) {
@@ -57,12 +55,12 @@ void desktop_settings_scene_start_on_enter(void* context) {
VariableItem* item;
uint8_t value_index;
variable_item_list_add(variable_item_list, "PIN Setup", 1, NULL, NULL);
variable_item_list_add(variable_item_list, "Keybinds Setup", 1, NULL, NULL);
variable_item_list_add(variable_item_list, "Reset Keybinds to Default", 1, NULL, NULL);
variable_item_list_add(variable_item_list, "PIN Setup", 1, NULL, NULL);
item = variable_item_list_add(
variable_item_list,
"Auto Lock Time",
@@ -71,7 +69,7 @@ void desktop_settings_scene_start_on_enter(void* context) {
app);
value_index = value_index_uint32(
app->desktop->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
app->settings.auto_lock_delay_ms, auto_lock_delay_value, AUTO_LOCK_DELAY_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, auto_lock_delay_text[value_index]);
@@ -82,9 +80,8 @@ void desktop_settings_scene_start_on_enter(void* context) {
desktop_settings_scene_start_auto_lock_pin_changed,
app);
variable_item_set_current_value_index(item, app->desktop->settings.auto_lock_with_pin);
variable_item_set_current_value_text(
item, app->desktop->settings.auto_lock_with_pin ? "ON" : "OFF");
variable_item_set_current_value_index(item, app->settings.auto_lock_with_pin);
variable_item_set_current_value_text(item, app->settings.auto_lock_with_pin ? "ON" : "OFF");
variable_item_list_set_enter_callback(
variable_item_list, desktop_settings_scene_start_var_list_enter_callback, app);
@@ -98,23 +95,28 @@ bool desktop_settings_scene_start_on_event(void* context, SceneManagerEvent even
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case VarItemListIndexKeybinds:
case DesktopSettingsPinSetup:
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinMenu);
break;
case DesktopSettingsKeybindSetup:
scene_manager_set_scene_state(
app->scene_manager, DesktopSettingsAppSceneKeybindsType, 0);
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneKeybindsType);
consumed = true;
break;
case VarItemListIndexResetKeybinds:
case DesktopSettingsResetKeybinds:
scene_manager_set_scene_state(
app->scene_manager, DesktopSettingsAppSceneKeybindsType, 0);
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppSceneKeybindsReset);
consumed = true;
break;
case VarItemListIndexPinSetup:
scene_manager_next_scene(app->scene_manager, DesktopSettingsAppScenePinMenu);
consumed = true;
default:
break;
}
consumed = true;
}
return consumed;
}

View File

@@ -1 +1,5 @@
// Since settings app is external, it cannot access firmware functions
// For simple utils like this, easier to include C code in app too
// Instead of copying the file, can (ab)use preprocessor to copy source code here
#include <applications/services/desktop/views/desktop_view_pin_input.c>
// Then, we still use the Header from original code as if nothing happened

View File

@@ -1 +1,5 @@
// Since settings app is external, it cannot access firmware functions
// For simple utils like this, easier to include C code in app too
// Instead of copying the file, can (ab)use preprocessor to copy source code here
#include <applications/settings/about/about.c>
// Then, we still use the Header from original code as if nothing happened