Cleaner settings implementation (proper defaults)

This commit is contained in:
Willy-JL
2023-02-17 23:30:28 +00:00
parent 8a8e5b3de0
commit 462a0c8efc
8 changed files with 31 additions and 23 deletions

View File

@@ -84,7 +84,7 @@ static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
} }
static int ArchiveFile_t_cmp(const ArchiveFile_t* a, const ArchiveFile_t* b) { static int ArchiveFile_t_cmp(const ArchiveFile_t* a, const ArchiveFile_t* b) {
if(!XTREME_SETTINGS()->sort_ignore_dirs) { if(XTREME_SETTINGS()->sort_dirs_first) {
if(a->type == ArchiveFileTypeFolder && b->type != ArchiveFileTypeFolder) { if(a->type == ArchiveFileTypeFolder && b->type != ArchiveFileTypeFolder) {
return -1; return -1;
} }

View File

@@ -528,7 +528,6 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) {
animation->active_cycles = u32value; animation->active_cycles = u32value;
if(!flipper_format_read_uint32(ff, "Frame rate", &u32value, 1)) break; if(!flipper_format_read_uint32(ff, "Frame rate", &u32value, 1)) break;
uint16_t anim_speed = XTREME_SETTINGS()->anim_speed; uint16_t anim_speed = XTREME_SETTINGS()->anim_speed;
anim_speed = (anim_speed == 0 ? 100 : anim_speed);
u32value = (u32value * anim_speed) / 100; u32value = (u32value * anim_speed) / 100;
FURI_CONST_ASSIGN(animation->icon_animation.frame_rate, u32value < 1 ? 1 : u32value); FURI_CONST_ASSIGN(animation->icon_animation.frame_rate, u32value < 1 ? 1 : u32value);
if(!flipper_format_read_uint32(ff, "Duration", &u32value, 1)) break; if(!flipper_format_read_uint32(ff, "Duration", &u32value, 1)) break;

View File

@@ -94,7 +94,6 @@ Dolphin* dolphin_alloc() {
dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent)); dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent));
dolphin->pubsub = furi_pubsub_alloc(); dolphin->pubsub = furi_pubsub_alloc();
int32_t butthurt = XTREME_SETTINGS()->butthurt_timer; int32_t butthurt = XTREME_SETTINGS()->butthurt_timer;
butthurt = butthurt == 0 ? 43200 : butthurt;
dolphin->butthurt_timer = xTimerCreate( dolphin->butthurt_timer = xTimerCreate(
NULL, (butthurt > 0) ? (butthurt * 1000) : -1, pdTRUE, dolphin, dolphin_butthurt_timer_callback); NULL, (butthurt > 0) ? (butthurt * 1000) : -1, pdTRUE, dolphin, dolphin_butthurt_timer_callback);
dolphin->flush_timer = dolphin->flush_timer =

View File

@@ -91,7 +91,7 @@ static int BrowserItem_t_cmp(const BrowserItem_t* a, const BrowserItem_t* b) {
if(b->type == BrowserItemTypeBack) { if(b->type == BrowserItemTypeBack) {
return 1; return 1;
} }
if(!XTREME_SETTINGS()->sort_ignore_dirs) { if(XTREME_SETTINGS()->sort_dirs_first) {
if(a->type == BrowserItemTypeFolder && b->type != BrowserItemTypeFolder) { if(a->type == BrowserItemTypeFolder && b->type != BrowserItemTypeFolder) {
return -1; return -1;
} }

View File

@@ -26,14 +26,14 @@ typedef enum {
} PowerEventType; } PowerEventType;
typedef enum { typedef enum {
BatteryIconOff = 1, BatteryIconOff,
BatteryIconBar = 2, BatteryIconBar,
BatteryIconPercent = 3, BatteryIconPercent,
BatteryIconInvertedPercent = 4, BatteryIconInvertedPercent,
BatteryIconRetro3 = 5, BatteryIconRetro3,
BatteryIconRetro5 = 6, BatteryIconRetro5,
BatteryIconBarPercent = 0, BatteryIconBarPercent,
BatteryIconCount = 7, BatteryIconCount,
} BatteryIcon; } BatteryIcon;
typedef union { typedef union {

View File

@@ -31,6 +31,17 @@ void XTREME_SETTINGS_LOAD() {
if(!loaded) { if(!loaded) {
memset(xtreme_settings, 0, sizeof(XtremeSettings)); memset(xtreme_settings, 0, sizeof(XtremeSettings));
xtreme_settings->asset_pack = ""; // SFW
xtreme_settings->anim_speed = 100; // 100%
xtreme_settings->cycle_anims = 0; // Meta.txt
xtreme_settings->unlock_anims = false; // OFF
xtreme_settings->battery_icon = BatteryIconBarPercent; // Bar %
xtreme_settings->status_icons = true; // ON
xtreme_settings->bar_borders = true; // ON
xtreme_settings->bar_background = false; // OFF
xtreme_settings->bad_bt = false; // USB
xtreme_settings->sort_dirs_first = true; // ON
xtreme_settings->butthurt_timer = 43200; // 12 H
} }
} }
} }

View File

@@ -11,7 +11,7 @@
#define MAX_PACK_NAME_LEN 32 #define MAX_PACK_NAME_LEN 32
#define XTREME_SETTINGS_VERSION (2) #define XTREME_SETTINGS_VERSION (3)
#define XTREME_SETTINGS_PATH INT_PATH(XTREME_SETTINGS_FILE_NAME) #define XTREME_SETTINGS_PATH INT_PATH(XTREME_SETTINGS_FILE_NAME)
#define XTREME_SETTINGS_MAGIC (0x69) #define XTREME_SETTINGS_MAGIC (0x69)
@@ -28,7 +28,7 @@ typedef struct {
bool bar_borders; bool bar_borders;
bool bar_background; bool bar_background;
bool bad_bt; bool bad_bt;
bool sort_ignore_dirs; bool sort_dirs_first;
int32_t butthurt_timer; int32_t butthurt_timer;
} XtremeSettings; } XtremeSettings;

View File

@@ -19,7 +19,7 @@ static void xtreme_app_scene_main_asset_pack_changed(VariableItem* item) {
const char* const anim_speed_names[] = const char* const anim_speed_names[] =
{"25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"}; {"25%", "50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"};
const int32_t anim_speed_values[COUNT_OF(anim_speed_names)] = const int32_t anim_speed_values[COUNT_OF(anim_speed_names)] =
{25, 50, 75, 0, 125, 150, 175, 200, 225, 250, 275, 300}; {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300};
static void xtreme_app_scene_main_anim_speed_changed(VariableItem* item) { static void xtreme_app_scene_main_anim_speed_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item); XtremeApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
@@ -66,7 +66,7 @@ static void xtreme_app_scene_main_battery_icon_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item); XtremeApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, battery_icon_names[index]); variable_item_set_current_value_text(item, battery_icon_names[index]);
XTREME_SETTINGS()->battery_icon = (index + 1) % BatteryIconCount; XTREME_SETTINGS()->battery_icon = index;
app->save_settings = true; app->save_settings = true;
} }
@@ -137,7 +137,7 @@ const char* const butthurt_timer_names[] = {
"24 H", "24 H",
"48 H"}; "48 H"};
const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] =
{-1, 1800, 3600, 7200, 14400, 21600, 28800, 0, 86400, 172800}; {-1, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 172800};
static void xtreme_app_scene_main_butthurt_timer_changed(VariableItem* item) { static void xtreme_app_scene_main_butthurt_timer_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item); XtremeApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
@@ -151,7 +151,7 @@ static void xtreme_app_scene_main_sort_folders_before_changed(VariableItem* item
XtremeApp* app = variable_item_get_context(item); XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item); bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF"); variable_item_set_current_value_text(item, value ? "ON" : "OFF");
XTREME_SETTINGS()->sort_ignore_dirs = !value; XTREME_SETTINGS()->sort_dirs_first = value;
app->save_settings = true; app->save_settings = true;
} }
@@ -256,9 +256,8 @@ void xtreme_app_scene_main_on_enter(void* context) {
BatteryIconCount, BatteryIconCount,
xtreme_app_scene_main_battery_icon_changed, xtreme_app_scene_main_battery_icon_changed,
app); app);
value_index = (xtreme_settings->battery_icon + BatteryIconCount - 1) % BatteryIconCount; variable_item_set_current_value_index(item, xtreme_settings->battery_icon);
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, battery_icon_names[xtreme_settings->battery_icon]);
variable_item_set_current_value_text(item, battery_icon_names[value_index]);
item = variable_item_list_add( item = variable_item_list_add(
var_item_list, "Status Icons", 2, xtreme_app_scene_main_status_icons_changed, app); var_item_list, "Status Icons", 2, xtreme_app_scene_main_status_icons_changed, app);
@@ -327,8 +326,8 @@ void xtreme_app_scene_main_on_enter(void* context) {
2, 2,
xtreme_app_scene_main_sort_folders_before_changed, xtreme_app_scene_main_sort_folders_before_changed,
app); app);
variable_item_set_current_value_index(item, !xtreme_settings->sort_ignore_dirs); variable_item_set_current_value_index(item, xtreme_settings->sort_dirs_first);
variable_item_set_current_value_text(item, !xtreme_settings->sort_ignore_dirs ? "ON" : "OFF"); variable_item_set_current_value_text(item, xtreme_settings->sort_dirs_first ? "ON" : "OFF");
FuriString* version_tag = furi_string_alloc_printf( FuriString* version_tag = furi_string_alloc_printf(
"%s %s", version_get_gitbranchnum(NULL), version_get_builddate(NULL)); "%s %s", version_get_gitbranchnum(NULL), version_get_builddate(NULL));