Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Adolfo Reyna
2026-07-04 15:39:52 -04:00
396 changed files with 114753 additions and 2051 deletions
+5 -13
View File
@@ -1,35 +1,28 @@
#include <Tactility/MountPoints.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Logger.h>
#include <Tactility/settings/BootSettings.h>
#include <Tactility/Paths.h>
#include <format>
#include <string>
#include <vector>
namespace tt::settings {
constexpr auto* TAG = "BootSettings";
constexpr auto* PROPERTIES_FILE_FORMAT = "{}/settings/boot.properties";
constexpr auto* PROPERTIES_KEY_LAUNCHER_APP_ID = "launcherAppId";
constexpr auto* PROPERTIES_KEY_AUTO_START_APP_ID = "autoStartAppId";
static std::string getPropertiesFilePath() {
std::string sdcard_path;
if (findFirstMountedSdCardPath(sdcard_path)) {
std::string path = std::format(PROPERTIES_FILE_FORMAT, sdcard_path);
if (file::isFile(path)) {
return path;
}
}
return std::format(PROPERTIES_FILE_FORMAT, file::MOUNT_POINT_DATA);
return std::format(PROPERTIES_FILE_FORMAT, getUserDataPath());
}
bool loadBootSettings(BootSettings& properties) {
const std::string path = getPropertiesFilePath();
if (!file::isFile(path)) {
return false;
}
if (!file::loadPropertiesFile(path, [&properties](auto& key, auto& value) {
if (key == PROPERTIES_KEY_AUTO_START_APP_ID) {
properties.autoStartAppId = value;
@@ -37,7 +30,6 @@ bool loadBootSettings(BootSettings& properties) {
properties.launcherAppId = value;
}
})) {
LOG_I(TAG, "No settings at %s", path.c_str());
return false;
}
+17 -3
View File
@@ -1,6 +1,8 @@
#include <Tactility/settings/DisplaySettings.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Paths.h>
#include <tactility/hal/Device.h>
#include <Tactility/hal/display/DisplayDevice.h>
@@ -10,7 +12,10 @@
namespace tt::settings::display {
constexpr auto* SETTINGS_FILE = "/data/settings/display.properties";
static std::string getSettingsFilePath() {
return getUserDataPath() + "/settings/display.properties";
}
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
@@ -110,8 +115,13 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
}
bool load(DisplaySettings& settings) {
auto settings_path = getSettingsFilePath();
if (!file::isFile(settings_path)) {
return false;
}
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -191,7 +201,11 @@ bool save(const DisplaySettings& settings) {
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
return file::savePropertiesFile(SETTINGS_FILE, map);
auto settings_path = getSettingsFilePath();
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
return false;
}
return file::savePropertiesFile(settings_path, map);
}
lv_display_rotation_t toLvglDisplayRotation(Orientation orientation) {
+17 -3
View File
@@ -1,20 +1,30 @@
#include <Tactility/settings/KeyboardSettings.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Paths.h>
#include <map>
#include <string>
namespace tt::settings::keyboard {
constexpr auto* SETTINGS_FILE = "/data/settings/keyboard.properties";
static std::string getSettingsFilePath() {
return getUserDataPath() + "/settings/keyboard.properties";
}
constexpr auto* KEY_BACKLIGHT_ENABLED = "backlightEnabled";
constexpr auto* KEY_BACKLIGHT_BRIGHTNESS = "backlightBrightness";
constexpr auto* KEY_BACKLIGHT_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
constexpr auto* KEY_BACKLIGHT_TIMEOUT_MS = "backlightTimeoutMs";
bool load(KeyboardSettings& settings) {
auto settings_path = getSettingsFilePath();
if (!file::isFile(settings_path)) {
return false;
}
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -54,7 +64,11 @@ bool save(const KeyboardSettings& settings) {
map[KEY_BACKLIGHT_BRIGHTNESS] = std::to_string(settings.backlightBrightness);
map[KEY_BACKLIGHT_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
map[KEY_BACKLIGHT_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
return file::savePropertiesFile(SETTINGS_FILE, map);
auto settings_path = getSettingsFilePath();
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
return false;
}
return file::savePropertiesFile(settings_path, map);
}
}
+20 -19
View File
@@ -1,11 +1,13 @@
#include <Tactility/Logger.h>
#include <Tactility/MountPoints.h>
#include <Tactility/Mutex.h>
#include <Tactility/file/File.h>
#include <Tactility/file/FileLock.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/settings/Language.h>
#include <Tactility/settings/SystemSettings.h>
#include "Tactility/Paths.h"
#include <format>
namespace tt::settings {
@@ -14,16 +16,19 @@ static const auto LOGGER = Logger("SystemSettings");
constexpr auto* FILE_PATH_FORMAT = "{}/settings/system.properties";
static Mutex mutex;
static bool cached = false;
static SystemSettings cachedSettings;
static bool hasSystemSettingsFile() {
auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath());
return file::isFile(file_path);
}
static bool loadSystemSettingsFromFile(SystemSettings& properties) {
auto file_path = std::format(FILE_PATH_FORMAT, file::MOUNT_POINT_DATA);
auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath());
LOGGER.info("System settings loading from {}", file_path);
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(file_path, map)) {
LOGGER.error("Failed to load {}", file_path);
return false;
}
@@ -51,25 +56,17 @@ static bool loadSystemSettingsFromFile(SystemSettings& properties) {
properties.dateFormat = "MM/DD/YYYY";
}
// Load region
auto region_entry = map.find("region");
if (region_entry != map.end() && !region_entry->second.empty()) {
properties.region = region_entry->second;
} else {
LOGGER.info("Region missing or empty, using default EU");
properties.region = "EU";
}
LOGGER.info("System settings loaded");
return true;
}
bool loadSystemSettings(SystemSettings& properties) {
if (!cached) {
if (!loadSystemSettingsFromFile(cachedSettings)) {
return false;
if (!cached && hasSystemSettingsFile()) {
if (loadSystemSettingsFromFile(cachedSettings)) {
cached = true;
} else {
LOGGER.error("Failed to load");
}
cached = true;
}
properties = cachedSettings;
@@ -77,12 +74,16 @@ bool loadSystemSettings(SystemSettings& properties) {
}
bool saveSystemSettings(const SystemSettings& properties) {
auto file_path = std::format(FILE_PATH_FORMAT, file::MOUNT_POINT_DATA);
auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath());
std::map<std::string, std::string> map;
map["language"] = toString(properties.language);
map["timeFormat24h"] = properties.timeFormat24h ? "true" : "false";
map["dateFormat"] = properties.dateFormat;
map["region"] = properties.region;
if (!file::findOrCreateParentDirectory(file_path, 0755)) {
LOGGER.error("Failed to create parent dir for {}", file_path);
return false;
}
if (!file::savePropertiesFile(file_path, map)) {
LOGGER.error("Failed to save {}", file_path);
@@ -1,7 +1,9 @@
#include <Tactility/settings/TouchCalibrationSettings.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Mutex.h>
#include <Tactility/Paths.h>
#include <algorithm>
#include <cstdlib>
@@ -12,7 +14,10 @@
namespace tt::settings::touch {
constexpr auto* SETTINGS_FILE = "/data/settings/touch-calibration.properties";
static std::string getSettingsFilePath() {
return getUserDataPath() + "/settings/touch-calibration.properties";
}
constexpr auto* SETTINGS_KEY_ENABLED = "enabled";
constexpr auto* SETTINGS_KEY_X_MIN = "xMin";
constexpr auto* SETTINGS_KEY_X_MAX = "xMax";
@@ -60,8 +65,13 @@ bool isValid(const TouchCalibrationSettings& settings) {
}
bool load(TouchCalibrationSettings& settings) {
auto settings_path = getSettingsFilePath();
if (!file::isFile(settings_path)) {
return false;
}
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -112,7 +122,12 @@ bool save(const TouchCalibrationSettings& settings) {
map[SETTINGS_KEY_Y_MIN] = std::to_string(settings.yMin);
map[SETTINGS_KEY_Y_MAX] = std::to_string(settings.yMax);
if (!file::savePropertiesFile(SETTINGS_FILE, map)) {
auto settings_path = getSettingsFilePath();
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
return false;
}
if (!file::savePropertiesFile(settings_path, map)) {
return false;
}
@@ -1,5 +1,7 @@
#include <Tactility/settings/TrackballSettings.h>
#include <Tactility/file/File.h>
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/Paths.h>
#include <map>
#include <string>
@@ -7,7 +9,10 @@
namespace tt::settings::trackball {
constexpr auto* SETTINGS_FILE = "/data/settings/trackball.properties";
static std::string getSettingsFilePath() {
return getUserDataPath() + "/settings/trackball.properties";
}
constexpr auto* KEY_TRACKBALL_ENABLED = "trackballEnabled";
constexpr auto* KEY_TRACKBALL_MODE = "trackballMode";
constexpr auto* KEY_ENCODER_SENSITIVITY = "encoderSensitivity";
@@ -19,8 +24,13 @@ constexpr uint8_t MIN_POINTER_SENSITIVITY = 1;
constexpr uint8_t MAX_POINTER_SENSITIVITY = 10;
bool load(TrackballSettings& settings) {
auto settings_path = getSettingsFilePath();
if (!file::isFile(settings_path)) {
return false;
}
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -80,7 +90,11 @@ bool save(const TrackballSettings& settings) {
map[KEY_TRACKBALL_MODE] = (settings.trackballMode == TrackballMode::Pointer) ? "1" : "0";
map[KEY_ENCODER_SENSITIVITY] = std::to_string(std::clamp(settings.encoderSensitivity, MIN_ENCODER_SENSITIVITY, MAX_ENCODER_SENSITIVITY));
map[KEY_POINTER_SENSITIVITY] = std::to_string(std::clamp(settings.pointerSensitivity, MIN_POINTER_SENSITIVITY, MAX_POINTER_SENSITIVITY));
return file::savePropertiesFile(SETTINGS_FILE, map);
auto settings_path = getSettingsFilePath();
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
return false;
}
return file::savePropertiesFile(settings_path, map);
}
}
@@ -2,6 +2,7 @@
#include <Tactility/file/PropertiesFile.h>
#include <Tactility/file/File.h>
#include <Tactility/Logger.h>
#include <Tactility/Paths.h>
#include <charconv>
#include <map>
@@ -17,8 +18,11 @@
namespace tt::settings::webserver {
static const auto LOGGER = tt::Logger("WebServerSettings");
constexpr auto* SETTINGS_FILE = "/data/service/webserver/settings.properties";
static const auto LOGGER = Logger("WebServerSettings");
static std::string getSettingsFilePath() {
return getUserDataPath() + "/settings/webserver.properties";
}
// Property keys
constexpr auto* KEY_WIFI_ENABLED = "wifiEnabled";
@@ -86,8 +90,13 @@ static bool isEmptyCredential(const std::string& value) {
}
bool load(WebServerSettings& settings) {
auto settings_path = getSettingsFilePath();
if (!file::isFile(settings_path)) {
return false;
}
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
if (!file::loadPropertiesFile(settings_path, map)) {
return false;
}
@@ -146,7 +155,7 @@ bool load(WebServerSettings& settings) {
// Persist the generated password immediately
map[KEY_AP_PASSWORD] = settings.apPassword;
if (file::savePropertiesFile(SETTINGS_FILE, map)) {
if (file::savePropertiesFile(getSettingsFilePath(), map)) {
LOGGER.info("Generated and saved new secure AP password");
} else {
LOGGER.error("Failed to save generated AP password");
@@ -187,7 +196,7 @@ bool load(WebServerSettings& settings) {
// We need to save these to the file so they're consistent across reboots
map[KEY_WEBSERVER_USERNAME] = settings.webServerUsername;
map[KEY_WEBSERVER_PASSWORD] = settings.webServerPassword;
if (file::savePropertiesFile(SETTINGS_FILE, map)) {
if (file::savePropertiesFile(getSettingsFilePath(), map)) {
LOGGER.info("Generated and saved new secure credentials");
} else {
LOGGER.error("Failed to save generated credentials - auth may be inconsistent across reboots");
@@ -253,8 +262,12 @@ bool save(const WebServerSettings& settings) {
map[KEY_WEBSERVER_USERNAME] = settings.webServerUsername;
map[KEY_WEBSERVER_PASSWORD] = settings.webServerPassword;
// Save to flash storage only (no SD backup - settings sync at boot handles restore)
return file::savePropertiesFile(SETTINGS_FILE, map);
auto settings_path = getSettingsFilePath();
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
LOGGER.error("Failed to create parent dir for {}", settings_path);
return false;
}
return file::savePropertiesFile(settings_path, map);
}
}
+9
View File
@@ -49,6 +49,15 @@ std::string getTimeZoneName() {
}
}
bool hasTimeZone() {
Preferences preferences(TIME_SETTINGS_NAMESPACE);
std::string timezone;
if (!preferences.optString(TIMEZONE_PREFERENCES_KEY_NAME, timezone)) {
return false;
}
return !timezone.empty();
}
std::string getTimeZoneCode() {
Preferences preferences(TIME_SETTINGS_NAMESPACE);
std::string result;