Refactor app access (#205)
- Use `tt::app::` functions to start/stop apps and get current app(context) instead of using loader everywhere - Removed `tt_service_loader.*` from TactilityC - Created `tt_app_stop()` for TactilityC - Bumped version to 0.3.0 to prepare for upcoming release
This commit is contained in:
committed by
GitHub
parent
68e34ca740
commit
6337458992
@@ -52,9 +52,8 @@ class AlertDialogApp : public App {
|
||||
private:
|
||||
|
||||
static void onButtonClickedCallback(lv_event_t* e) {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
assert(appContext != nullptr);
|
||||
auto app = std::static_pointer_cast<AlertDialogApp>(appContext->getApp());
|
||||
auto app = std::static_pointer_cast<AlertDialogApp>(getCurrentApp());
|
||||
assert(app != nullptr);
|
||||
app->onButtonClicked(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ lv_obj_t* GpioApp::createGpioRowWrapper(lv_obj_t* parent) {
|
||||
// region Task
|
||||
|
||||
void GpioApp::onTimer(TT_UNUSED std::shared_ptr<void> context) {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext->getManifest().id == manifest.id) {
|
||||
auto app = std::static_pointer_cast<GpioApp>(appContext->getApp());
|
||||
if (app != nullptr) {
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<I2cScannerApp> _Nullable optApp() {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<I2cScannerApp>(appContext->getApp());
|
||||
} else {
|
||||
|
||||
@@ -58,9 +58,8 @@ private:
|
||||
}
|
||||
|
||||
static void onButtonClickedCallback(lv_event_t* e) {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
assert(appContext != nullptr);
|
||||
auto app = std::static_pointer_cast<InputDialogApp>(appContext->getApp());
|
||||
auto app = std::static_pointer_cast<InputDialogApp>(getCurrentApp());
|
||||
assert(app != nullptr);
|
||||
app->onButtonClicked(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class PowerApp;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<PowerApp> _Nullable optApp() {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<PowerApp>(appContext->getApp());
|
||||
} else {
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace tt::app::screenshot {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
class ScreenshotApp : public App {
|
||||
class ScreenshotApp final : public App {
|
||||
|
||||
lv_obj_t* modeDropdown = nullptr;
|
||||
lv_obj_t* pathTextArea = nullptr;
|
||||
@@ -39,7 +39,7 @@ class ScreenshotApp : public App {
|
||||
public:
|
||||
|
||||
ScreenshotApp();
|
||||
~ScreenshotApp();
|
||||
~ScreenshotApp() final;
|
||||
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override;
|
||||
void onStartPressed();
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<ScreenshotApp> _Nullable optApp() {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<ScreenshotApp>(appContext->getApp());
|
||||
} else {
|
||||
|
||||
@@ -49,9 +49,8 @@ class SelectionDialogApp : public App {
|
||||
private:
|
||||
|
||||
static void onListItemSelectedCallback(lv_event_t* e) {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
assert(appContext != nullptr);
|
||||
auto app = std::static_pointer_cast<SelectionDialogApp>(appContext->getApp());
|
||||
auto app = std::static_pointer_cast<SelectionDialogApp>(getCurrentApp());
|
||||
assert(app != nullptr);
|
||||
app->onListItemSelected(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,11 +93,9 @@ private:
|
||||
|
||||
static void onListItemSelectedCallback(lv_event_t* e) {
|
||||
auto index = reinterpret_cast<std::size_t>(lv_event_get_user_data(e));
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
auto app = std::static_pointer_cast<TimeZoneApp>(appContext->getApp());
|
||||
app->onListItemSelected(index);
|
||||
}
|
||||
auto app = std::static_pointer_cast<TimeZoneApp>(getCurrentApp());
|
||||
assert(app != nullptr);
|
||||
app->onListItemSelected(index);
|
||||
}
|
||||
|
||||
void onListItemSelected(std::size_t index) {
|
||||
@@ -120,7 +118,7 @@ private:
|
||||
}
|
||||
|
||||
static void updateTimerCallback(std::shared_ptr<void> context) {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
auto app = std::static_pointer_cast<TimeZoneApp>(appContext->getApp());
|
||||
app->updateList();
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "Tactility/app/wifiapsettings/WifiApSettings.h"
|
||||
|
||||
#include "Tactility/app/App.h"
|
||||
#include "Tactility/app/AppContext.h"
|
||||
#include "Tactility/app/AppManifest.h"
|
||||
#include "Tactility/app/alertdialog/AlertDialog.h"
|
||||
#include "Tactility/lvgl/Style.h"
|
||||
#include "Tactility/lvgl/Toolbar.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
@@ -17,20 +18,10 @@ namespace tt::app::wifiapsettings {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
const std::shared_ptr<AppContext> _Nullable optWifiApSettingsApp() {
|
||||
auto app = service::loader::getCurrentAppContext();
|
||||
if (app != nullptr && app->getManifest().id == manifest.id) {
|
||||
return app;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void start(const std::string& ssid) {
|
||||
auto bundle = std::make_shared<Bundle>();
|
||||
bundle->putString("ssid", ssid);
|
||||
service::loader::startApp(manifest.id, bundle);
|
||||
app::start(manifest.id, bundle);
|
||||
}
|
||||
|
||||
static void onPressForget(TT_UNUSED lv_event_t* event) {
|
||||
@@ -44,11 +35,7 @@ static void onPressForget(TT_UNUSED lv_event_t* event) {
|
||||
static void onToggleAutoConnect(lv_event_t* event) {
|
||||
lv_event_code_t code = lv_event_get_code(event);
|
||||
|
||||
auto app = optWifiApSettingsApp();
|
||||
if (app == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto app = getCurrentAppContext();
|
||||
auto parameters = app->getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
@@ -125,31 +112,28 @@ class WifiApSettings : public App {
|
||||
}
|
||||
|
||||
void onResult(TT_UNUSED AppContext& appContext, TT_UNUSED Result result, std::unique_ptr<Bundle> bundle) override {
|
||||
auto index = alertdialog::getResultIndex(*bundle);
|
||||
if (index == 0) { // Yes
|
||||
auto app = optWifiApSettingsApp();
|
||||
if (app == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (result == Result::Ok && bundle != nullptr) {
|
||||
auto index = alertdialog::getResultIndex(*bundle);
|
||||
if (index == 0) { // Yes
|
||||
auto parameters = appContext.getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
|
||||
auto parameters = app->getParameters();
|
||||
tt_check(parameters != nullptr, "Parameters missing");
|
||||
std::string ssid = parameters->getString("ssid");
|
||||
if (service::wifi::settings::remove(ssid.c_str())) {
|
||||
TT_LOG_I(TAG, "Removed SSID");
|
||||
|
||||
std::string ssid = parameters->getString("ssid");
|
||||
if (service::wifi::settings::remove(ssid.c_str())) {
|
||||
TT_LOG_I(TAG, "Removed SSID");
|
||||
if (
|
||||
service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive &&
|
||||
service::wifi::getConnectionTarget() == ssid
|
||||
) {
|
||||
service::wifi::disconnect();
|
||||
}
|
||||
|
||||
if (
|
||||
service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive &&
|
||||
service::wifi::getConnectionTarget() == ssid
|
||||
) {
|
||||
service::wifi::disconnect();
|
||||
// Stop self
|
||||
app::stop();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to remove SSID");
|
||||
}
|
||||
|
||||
// Stop self
|
||||
service::loader::stopApp();
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to remove SSID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ void View::resetErrors() {
|
||||
}
|
||||
|
||||
static void onConnect(TT_UNUSED lv_event_t* event) {
|
||||
auto wifi = optWifiConnect();
|
||||
auto wifi = std::static_pointer_cast<WifiConnect>(getCurrentApp());
|
||||
auto& view = wifi->getView();
|
||||
|
||||
wifi->getState().setConnectionError(false);
|
||||
|
||||
@@ -13,16 +13,6 @@ namespace tt::app::wificonnect {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<WifiConnect> _Nullable optWifiConnect() {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<WifiConnect>(appContext->getApp());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void eventCallback(const void* message, void* context) {
|
||||
auto* event = static_cast<const service::wifi::Event*>(message);
|
||||
auto* wifi = static_cast<WifiConnect*>(context);
|
||||
|
||||
@@ -36,7 +36,7 @@ static void on_enable_switch_changed(lv_event_t* event) {
|
||||
if (code == LV_EVENT_VALUE_CHANGED) {
|
||||
bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED);
|
||||
|
||||
auto wifi = optWifiManage();
|
||||
auto wifi = std::static_pointer_cast<WifiManage>(getCurrentApp());
|
||||
auto bindings = wifi->getBindings();
|
||||
|
||||
bindings.onWifiToggled(is_on);
|
||||
|
||||
@@ -14,16 +14,6 @@ namespace tt::app::wifimanage {
|
||||
|
||||
extern const AppManifest manifest;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<WifiManage> _Nullable optWifiManage() {
|
||||
auto appContext = service::loader::getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<WifiManage>(appContext->getApp());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void onConnect(const char* ssid) {
|
||||
service::wifi::settings::WifiApSettings settings;
|
||||
if (service::wifi::settings::load(ssid, &settings)) {
|
||||
|
||||
Reference in New Issue
Block a user