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

55 lines
1.4 KiB
C++

#include "Tactility/service/wifi/WifiSettings.h"
#include "Tactility/Preferences.h"
#include "Tactility/file/PropertiesFile.h"
#include <Tactility/Log.h>
#include <Tactility/file/File.h>
namespace tt::service::wifi::settings {
constexpr auto* TAG = "WifiSettings";
constexpr auto* SETTINGS_FILE = "/data/service/Wifi/wifi.properties";
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
struct WifiProperties {
bool enableOnBoot;
};
static bool load(WifiProperties& properties) {
std::map<std::string, std::string> map;
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
return false;
}
if (!map.contains(SETTINGS_KEY_ENABLE_ON_BOOT)) {
return false;
}
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
properties.enableOnBoot = (enable_on_boot_string == "true");
return true;
}
static bool save(const WifiProperties& properties) {
std::map<std::string, std::string> map;
map[SETTINGS_KEY_ENABLE_ON_BOOT] = properties.enableOnBoot ? "true" : "false";
return file::savePropertiesFile(SETTINGS_FILE, map);
}
void setEnableOnBoot(bool enable) {
WifiProperties properties { .enableOnBoot = enable };
if (!save(properties)) {
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
}
}
bool shouldEnableOnBoot() {
WifiProperties properties;
if (!load(properties)) {
return false;
}
return properties.enableOnBoot;
}
} // namespace