App and Service improvements (#106)
This commit is contained in:
committed by
GitHub
parent
e86a11b7e2
commit
50ee77d572
@@ -3,12 +3,12 @@
|
||||
#include "Parameters.h"
|
||||
#include "WifiConnect.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "lvgl.h"
|
||||
#include "service/gui/Gui.h"
|
||||
#include "service/wifi/WifiSettings.h"
|
||||
#include "lvgl/Style.h"
|
||||
#include "lvgl/Toolbar.h"
|
||||
#include <TactilityCore.h>
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
|
||||
@@ -107,7 +107,7 @@ void View::createBottomButtons(WifiConnect* wifi, lv_obj_t* parent) {
|
||||
}
|
||||
|
||||
// TODO: Standardize dialogs
|
||||
void View::init(App& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
|
||||
void View::init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
|
||||
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lvgl::toolbar_create(parent, app);
|
||||
@@ -187,15 +187,17 @@ void View::init(App& app, WifiConnect* wifiConnect, lv_obj_t* parent) {
|
||||
service::gui::keyboardAddTextArea(password_textarea);
|
||||
|
||||
// Init from app parameters
|
||||
const Bundle& bundle = app.getParameters();
|
||||
std::string ssid;
|
||||
if (bundle.optString(WIFI_CONNECT_PARAM_SSID, ssid)) {
|
||||
lv_textarea_set_text(ssid_textarea, ssid.c_str());
|
||||
}
|
||||
auto bundle = app.getParameters();
|
||||
if (bundle != nullptr) {
|
||||
std::string ssid;
|
||||
if (bundle->optString(WIFI_CONNECT_PARAM_SSID, ssid)) {
|
||||
lv_textarea_set_text(ssid_textarea, ssid.c_str());
|
||||
}
|
||||
|
||||
std::string password;
|
||||
if (bundle.optString(WIFI_CONNECT_PARAM_PASSWORD, password)) {
|
||||
lv_textarea_set_text(password_textarea, password.c_str());
|
||||
std::string password;
|
||||
if (bundle->optString(WIFI_CONNECT_PARAM_PASSWORD, password)) {
|
||||
lv_textarea_set_text(password_textarea, password.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Bindings.h"
|
||||
#include "State.h"
|
||||
|
||||
#include "app/App.h"
|
||||
#include "app/AppContext.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
namespace tt::app::wificonnect {
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
lv_obj_t* connection_error = nullptr;
|
||||
lv_group_t* group = nullptr;
|
||||
|
||||
void init(App& app, WifiConnect* wifiConnect, lv_obj_t* parent);
|
||||
void init(AppContext& app, WifiConnect* wifiConnect, lv_obj_t* parent);
|
||||
void update(Bindings* bindings, State* state);
|
||||
|
||||
void createBottomButtons(WifiConnect* wifi, lv_obj_t* parent);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "WifiConnect.h"
|
||||
|
||||
#include "app/App.h"
|
||||
#include "app/AppContext.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "service/wifi/Wifi.h"
|
||||
@@ -10,6 +10,18 @@ namespace tt::app::wificonnect {
|
||||
|
||||
#define TAG "wifi_connect"
|
||||
|
||||
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() {
|
||||
app::AppContext* app = service::loader::getCurrentApp();
|
||||
if (app->getManifest().id == manifest.id) {
|
||||
return std::static_pointer_cast<WifiConnect>(app->getData());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void eventCallback(const void* message, void* context) {
|
||||
auto* event = static_cast<const service::wifi::WifiEvent*>(message);
|
||||
auto* wifi = static_cast<WifiConnect*>(context);
|
||||
@@ -76,7 +88,7 @@ void WifiConnect::requestViewUpdate() {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void WifiConnect::onShow(App& app, lv_obj_t* parent) {
|
||||
void WifiConnect::onShow(AppContext& app, lv_obj_t* parent) {
|
||||
lock();
|
||||
view_enabled = true;
|
||||
view.init(app, this, parent);
|
||||
@@ -84,41 +96,35 @@ void WifiConnect::onShow(App& app, lv_obj_t* parent) {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void WifiConnect::onHide(App& app) {
|
||||
void WifiConnect::onHide(AppContext& app) {
|
||||
// No need to lock view, as this is called from within Gui's LVGL context
|
||||
lock();
|
||||
view_enabled = false;
|
||||
unlock();
|
||||
}
|
||||
|
||||
static void onShow(App& app, lv_obj_t* parent) {
|
||||
auto* wifi = static_cast<WifiConnect*>(app.getData());
|
||||
static void onShow(AppContext& app, lv_obj_t* parent) {
|
||||
auto wifi = std::static_pointer_cast<WifiConnect>(app.getData());
|
||||
wifi->onShow(app, parent);
|
||||
}
|
||||
|
||||
static void onHide(App& app) {
|
||||
auto* wifi = static_cast<WifiConnect*>(app.getData());
|
||||
static void onHide(AppContext& app) {
|
||||
auto wifi = std::static_pointer_cast<WifiConnect>(app.getData());
|
||||
wifi->onHide(app);
|
||||
}
|
||||
|
||||
static void onStart(App& app) {
|
||||
auto* wifi_connect = new WifiConnect();
|
||||
app.setData(wifi_connect);
|
||||
static void onStart(AppContext& app) {
|
||||
auto wifi = std::shared_ptr<WifiConnect>(new WifiConnect());
|
||||
app.setData(wifi);
|
||||
}
|
||||
|
||||
static void onStop(App& app) {
|
||||
auto* wifi_connect = static_cast<WifiConnect*>(app.getData());
|
||||
tt_assert(wifi_connect != nullptr);
|
||||
delete wifi_connect;
|
||||
}
|
||||
|
||||
extern const Manifest manifest = {
|
||||
extern const AppManifest manifest = {
|
||||
.id = "WifiConnect",
|
||||
.name = "Wi-Fi Connect",
|
||||
.icon = LV_SYMBOL_WIFI,
|
||||
.type = TypeSettings,
|
||||
.onStart = &onStart,
|
||||
.onStop = &onStop,
|
||||
.onShow = &onShow,
|
||||
.onHide = &onHide
|
||||
};
|
||||
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void onShow(App& app, lv_obj_t* parent);
|
||||
void onHide(App& app);
|
||||
void onShow(AppContext& app, lv_obj_t* parent);
|
||||
void onHide(AppContext& app);
|
||||
|
||||
State& getState() { return state; }
|
||||
Bindings& getBindings() { return bindings; }
|
||||
|
||||
Reference in New Issue
Block a user