Ken Van Hoeylandt 8c8ccd8783
Merge develop into main (#305)
## New features

- Implement translations for apps
- Created `tt::settings::setLanguage` and `::getLanguage()`
- External app errors are now reported to the user via an AlertDialog
- Store system settings in `/data/settings.properties`
- Created a "Region & Language" app and moved the timezone setting there.

## Other changes

- Change `/data` and `/system` filesystem sector size from 4096 to 512 bytes to allow for more small files (60+ files of 4kB were over the limit of 256kB for the filesystem)
- Increased size of `/data` and `/system`
- Moved `tt::time::*` to `tt::settings`
- Removed the timezone setting from the "Time & Date" setting app
- Reverse encoder direction of Lilygo T-Lora Pager
- Improved partability of `Time.cpp` (removed separate set of functions for PC/sim)
2025-08-28 21:50:29 +02:00

82 lines
1.9 KiB
C++

#include <Tactility/settings/Time.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Preferences.h>
#include <Tactility/settings/SettingsProperties.h>
#ifdef ESP_PLATFORM
#include <ctime>
#endif
namespace tt::settings {
constexpr auto* TIME_SETTINGS_NAMESPACE = "time";
constexpr auto* TIMEZONE_PREFERENCES_KEY_NAME = "tz_name";
constexpr auto* TIMEZONE_PREFERENCES_KEY_CODE = "tz_code";
constexpr auto* TIMEZONE_PREFERENCES_KEY_TIME24 = "tz_time24";
void initTimeZone() {
#ifdef ESP_PLATFORM
auto code= getTimeZoneCode();
if (!code.empty()) {
setenv("TZ", code.c_str(), 1);
tzset();
}
#endif
}
void setTimeZone(const std::string& name, const std::string& code) {
Preferences preferences(TIME_SETTINGS_NAMESPACE);
preferences.putString(TIMEZONE_PREFERENCES_KEY_NAME, name);
preferences.putString(TIMEZONE_PREFERENCES_KEY_CODE, code);
#ifdef ESP_PLATFORM
setenv("TZ", code.c_str(), 1);
tzset();
#endif
kernel::publishSystemEvent(kernel::SystemEvent::Time);
}
std::string getTimeZoneName() {
Preferences preferences(TIME_SETTINGS_NAMESPACE);
std::string result;
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_NAME, result)) {
return result;
} else {
return {};
}
}
std::string getTimeZoneCode() {
Preferences preferences(TIME_SETTINGS_NAMESPACE);
std::string result;
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_CODE, result)) {
return result;
} else {
return {};
}
}
bool isTimeFormat24Hour() {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
return true;
} else {
return properties.timeFormat24h;
}
}
void setTimeFormat24Hour(bool show24Hour) {
SettingsProperties properties;
if (!loadSettingsProperties(properties)) {
return;
}
properties.timeFormat24h = show24Hour;
saveSettingsProperties(properties);
}
}