Tactiliest/Tactility/Source/Tactility.cpp
Ken Van Hoeylandt bf91e7530d
Time & date, system events and much more (#152)
## 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)
2025-01-10 23:44:32 +01:00

185 lines
6.0 KiB
C++

#include "Tactility.h"
#include "app/ManifestRegistry.h"
#include "service/ServiceRegistry.h"
#include "service/loader/Loader.h"
#include "TactilityHeadless.h"
#include "lvgl/Init_i.h"
namespace tt {
#define TAG "tactility"
static const Configuration* config_instance = nullptr;
// region Default services
namespace service {
namespace gui { extern const ServiceManifest manifest; }
namespace loader { extern const ServiceManifest manifest; }
namespace statusbar { extern const ServiceManifest manifest; }
#if TT_FEATURE_SCREENSHOT_ENABLED
namespace screenshot { extern const ServiceManifest manifest; }
#endif
}
static const std::vector<const service::ServiceManifest*> system_services = {
&service::loader::manifest,
&service::gui::manifest, // depends on loader service
&service::statusbar::manifest,
#if TT_FEATURE_SCREENSHOT_ENABLED
&service::screenshot::manifest
#endif
};
// endregion
// region Default apps
namespace app {
namespace alertdialog { extern const AppManifest manifest; }
namespace applist { extern const AppManifest manifest; }
namespace boot { extern const AppManifest manifest; }
namespace files { extern const AppManifest manifest; }
namespace gpio { extern const AppManifest manifest; }
namespace display { extern const AppManifest manifest; }
namespace i2cscanner { extern const AppManifest manifest; }
namespace i2csettings { extern const AppManifest manifest; }
namespace imageviewer { extern const AppManifest manifest; }
namespace inputdialog { extern const AppManifest manifest; }
namespace launcher { extern const AppManifest manifest; }
namespace log { extern const AppManifest manifest; }
namespace power { extern const AppManifest manifest; }
namespace selectiondialog { extern const AppManifest manifest; }
namespace settings { extern const AppManifest manifest; }
namespace systeminfo { extern const AppManifest manifest; }
namespace textviewer { extern const AppManifest manifest; }
namespace timedatesettings { extern const AppManifest manifest; }
namespace timezone { extern const AppManifest manifest; }
namespace usbsettings { extern const AppManifest manifest; }
namespace wifiapsettings { extern const AppManifest manifest; }
namespace wificonnect { extern const AppManifest manifest; }
namespace wifimanage { extern const AppManifest manifest; }
#if TT_FEATURE_SCREENSHOT_ENABLED
namespace screenshot { extern const AppManifest manifest; }
#endif
#ifdef ESP_PLATFORM
extern const AppManifest elfWrapperManifest;
namespace crashdiagnostics { extern const AppManifest manifest; }
#endif
}
#ifndef ESP_PLATFORM
#endif
static const std::vector<const app::AppManifest*> system_apps = {
&app::alertdialog::manifest,
&app::applist::manifest,
&app::boot::manifest,
&app::display::manifest,
&app::files::manifest,
&app::gpio::manifest,
&app::i2cscanner::manifest,
&app::i2csettings::manifest,
&app::imageviewer::manifest,
&app::inputdialog::manifest,
&app::launcher::manifest,
&app::log::manifest,
&app::settings::manifest,
&app::selectiondialog::manifest,
&app::systeminfo::manifest,
&app::textviewer::manifest,
&app::timedatesettings::manifest,
&app::timezone::manifest,
&app::usbsettings::manifest,
&app::wifiapsettings::manifest,
&app::wificonnect::manifest,
&app::wifimanage::manifest,
#if TT_FEATURE_SCREENSHOT_ENABLED
&app::screenshot::manifest,
#endif
#ifdef ESP_PLATFORM
&app::crashdiagnostics::manifest,
&app::elfWrapperManifest, // For hot-loading ELF apps
#endif
};
// endregion
static void register_system_apps() {
TT_LOG_I(TAG, "Registering default apps");
for (const auto* app_manifest: system_apps) {
addApp(app_manifest);
}
if (getConfiguration()->hardware->power != nullptr) {
addApp(&app::power::manifest);
}
}
static void register_user_apps(const std::vector<const app::AppManifest*>& apps) {
TT_LOG_I(TAG, "Registering user apps");
for (auto* manifest : apps) {
assert(manifest != nullptr);
addApp(manifest);
}
}
static void register_and_start_system_services() {
TT_LOG_I(TAG, "Registering and starting system services");
for (const auto& service_manifest: system_services) {
addService(service_manifest);
tt_check(service::startService(service_manifest->id));
}
}
static void register_and_start_user_services(const std::vector<const service::ServiceManifest*>& services) {
TT_LOG_I(TAG, "Registering and starting user services");
for (auto* manifest : services) {
assert(manifest != nullptr);
addService(manifest);
tt_check(service::startService(manifest->id));
}
}
void run(const Configuration& config) {
TT_LOG_I(TAG, "init started");
tt_assert(config.hardware);
const hal::Configuration& hardware = *config.hardware;
// Assign early so starting services can use it
config_instance = &config;
initHeadless(hardware);
lvgl::init(hardware);
// Note: the order of starting apps and services is critical!
// System services are registered first so the apps below can find them if needed
register_and_start_system_services();
// Then we register system apps. They are not used/started yet.
register_system_apps();
// Then we register and start user services. They are started after system app
// registration just in case they want to figure out which system apps are installed.
register_and_start_user_services(config.services);
// Now we register the user apps, as they might rely on the user services.
register_user_apps(config.apps);
TT_LOG_I(TAG, "init starting desktop app");
service::loader::startApp(app::boot::manifest.id);
TT_LOG_I(TAG, "init complete");
TT_LOG_I(TAG, "Processing main dispatcher");
while (true) {
getMainDispatcher().consume(TtWaitForever);
}
}
const Configuration* _Nullable getConfiguration() {
return config_instance;
}
} // namespace