From 73a854ead53c78308821f9f8f7fe5203ee13cae2 Mon Sep 17 00:00:00 2001 From: XK <47260768+XK9274@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:43:35 +0000 Subject: [PATCH] Initalise default values, guard against missing files --- src/common/system/settings.h | 2 +- src/tweaks/values.h | 45 +++++++++++-------- static/build/.tmp_update/script/blue_light.sh | 13 +++++- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/common/system/settings.h b/src/common/system/settings.h index fd19ba7f57..e6f2e65915 100644 --- a/src/common/system/settings.h +++ b/src/common/system/settings.h @@ -103,7 +103,7 @@ static settings_s __default_settings = (settings_s){ .enable_logging = false, .blue_light_state = false, .blue_light_level = 0, - .blue_light_rgb = 00000, + .blue_light_rgb = 8421504, .blue_light_time = "20:00", .blue_light_time_off = "08:00", .mainui_button_x = "", diff --git a/src/tweaks/values.h b/src/tweaks/values.h index fce4411b53..981b93f6c1 100644 --- a/src/tweaks/values.h +++ b/src/tweaks/values.h @@ -60,34 +60,43 @@ int value_appShortcut(int button) return 0; } -int value_blueLightLevel(void) -{ - int blueLightLevel = 0; - config_get("display/blueLightLevel", CONFIG_INT, &blueLightLevel); - return blueLightLevel; -} - -int value_blueLightRGB(void) -{ +int value_blueLightRGB(void) { int blueLightRGB = 0; - config_get("display/blueLightRGB", CONFIG_INT, &blueLightRGB); + if (!config_get("display/blueLightRGB", CONFIG_INT, &blueLightRGB)) { + blueLightRGB = settings.blue_light_rgb; + config_setNumber("display/blueLightRGB", blueLightRGB); + } return blueLightRGB; } -int value_blueLightTimeOn(void) -{ - char blueLightTime[12]; +int value_blueLightLevel(void) { + int blueLightLevel = 0; + if (!config_get("display/blueLightLevel", CONFIG_INT, &blueLightLevel)) { + blueLightLevel = settings.blue_light_level; + config_setNumber("display/blueLightLevel", blueLightLevel); + } + value_blueLightRGB(); // also init a default rgb size + return blueLightLevel; +} + +int value_blueLightTimeOn(void) { + char blueLightTime[12] = {0}; int blueLightID = 0; - config_get("display/blueLightTime", CONFIG_STR, blueLightTime); + if (!config_get("display/blueLightTime", CONFIG_STR, blueLightTime)) { + strcpy(blueLightTime, settings.blue_light_time); + config_setString("display/blueLightTime", blueLightTime); + } blueLightID = formatter_timeStringToID(blueLightTime); return blueLightID; } -int value_blueLightTimeOff(void) -{ - char blueLightTimeOff[12]; +int value_blueLightTimeOff(void) { + char blueLightTimeOff[12] = {0}; int blueLightID = 0; - config_get("display/blueLightTimeOff", CONFIG_STR, blueLightTimeOff); + if (!config_get("display/blueLightTimeOff", CONFIG_STR, blueLightTimeOff)) { + strcpy(blueLightTimeOff, settings.blue_light_time_off); + config_setString("display/blueLightTimeOff", blueLightTimeOff); + } blueLightID = formatter_timeStringToID(blueLightTimeOff); return blueLightID; } diff --git a/static/build/.tmp_update/script/blue_light.sh b/static/build/.tmp_update/script/blue_light.sh index 0d65291a40..d189156d65 100644 --- a/static/build/.tmp_update/script/blue_light.sh +++ b/static/build/.tmp_update/script/blue_light.sh @@ -69,8 +69,17 @@ disable_blue_light_filter() { check_blf() { sync - blueLightTimeOn=$(cat /mnt/SDCARD/.tmp_update/config/display/blueLightTime) - blueLightTimeOff=$(cat /mnt/SDCARD/.tmp_update/config/display/blueLightTimeOff) + + blueLightTimeOnFile="/mnt/SDCARD/.tmp_update/config/display/blueLightTime" + blueLightTimeOffFile="/mnt/SDCARD/.tmp_update/config/display/blueLightTimeOff" + + if [ ! -f "$blueLightTimeOnFile" ] || [ ! -f "$blueLightTimeOffFile" ]; then + rm -f "$lockfile" + return + fi + + blueLightTimeOn=$(cat "$blueLightTimeOnFile") + blueLightTimeOff=$(cat "$blueLightTimeOffFile") currentTime=$(date +"%H:%M") currentTimeMinutes=$(to_minutes_since_midnight "$currentTime")