mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
## Time & Date - Added time to statusbar widget - Added Time & Date Settings app - Added TimeZone app for selecting TimeZone - Added `tt::time` namespace with timezone code ## Other changes - Added `SystemEvent` to publish/subscribe to system wide (e.g. for init code, but also for time settings changes) - Changed the way the statusbar widget works: now there's only 1 that gets shown/hidden, instead of 1 instance per app instance. - Moved `lowercase()` function to new namespace: `tt::string` - Increased T-Deck flash & PSRAM SPI frequencies to 120 MHz (from 80 MHz) - Temporary work-around (+ TODO item) for LVGL stack size (issue with WiFi app) - Suppress T-Deck keystroke debugging to debug level (privacy issue) - Improved SDL dependency wiring in various `CMakeLists.txt` - `Loader` service had some variables renamed to the newer C++ style (from previous C style)
102 lines
2.3 KiB
C++
102 lines
2.3 KiB
C++
#include <ctime>
|
|
#include "Time.h"
|
|
#include "Preferences.h"
|
|
#include "kernel/SystemEvents.h"
|
|
|
|
namespace tt::time {
|
|
|
|
#ifdef ESP_PLATFORM
|
|
|
|
#define TIME_SETTINGS_NAMESPACE "time"
|
|
|
|
#define TIMEZONE_PREFERENCES_KEY_NAME "tz_name"
|
|
#define TIMEZONE_PREFERENCES_KEY_CODE "tz_code"
|
|
#define TIMEZONE_PREFERENCES_KEY_TIME24 "tz_time24"
|
|
|
|
void init() {
|
|
auto code= getTimeZoneCode();
|
|
if (!code.empty()) {
|
|
setenv("TZ", code.c_str(), 1);
|
|
tzset();
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
setenv("TZ", code.c_str(), 1);
|
|
tzset();
|
|
|
|
kernel::systemEventPublish(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() {
|
|
Preferences preferences(TIME_SETTINGS_NAMESPACE);
|
|
bool show24Hour = true;
|
|
preferences.optBool(TIMEZONE_PREFERENCES_KEY_TIME24, show24Hour);
|
|
return show24Hour;
|
|
}
|
|
|
|
void setTimeFormat24Hour(bool show24Hour) {
|
|
Preferences preferences(TIME_SETTINGS_NAMESPACE);
|
|
preferences.putBool(TIMEZONE_PREFERENCES_KEY_TIME24, show24Hour);
|
|
kernel::systemEventPublish(kernel::SystemEvent::Time);
|
|
}
|
|
|
|
#else
|
|
|
|
static std::string timeZoneName;
|
|
static std::string timeZoneCode;
|
|
static bool show24Hour = true;
|
|
|
|
void init() {}
|
|
|
|
void setTimeZone(const std::string& name, const std::string& code) {
|
|
timeZoneName = name;
|
|
timeZoneCode = code;
|
|
kernel::systemEventPublish(kernel::SystemEvent::Time);
|
|
}
|
|
|
|
std::string getTimeZoneName() {
|
|
return timeZoneName;
|
|
}
|
|
|
|
std::string getTimeZoneCode() {
|
|
return timeZoneCode;
|
|
}
|
|
|
|
bool isTimeFormat24Hour() {
|
|
return show24Hour;
|
|
}
|
|
|
|
void setTimeFormat24Hour(bool enabled) {
|
|
show24Hour = enabled;
|
|
kernel::systemEventPublish(kernel::SystemEvent::Time);
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|