f6cdabf3c0
## App state Improved app state management in `LoaderService` and `GuiService`: - Re-ordered some of the state transitions - Hardened `GuiService` for repeated events (that might trigger a re-render of an app that's already rendered) - Validate state transitions in `LoaderService` and crash if an app transitions from the wrong state to the next one. ## LoaderService - Removed `tt::loader::` functions and expose `LoaderService` interface publicly. - Implement `stopAll()` and `stopAll(id)` which stops all instances of an app, including any apps that were launched by it. - Rename `stop()` functions to `stopTop()` - Created `stopTop(id)` which only stops the top-most app when the app id matches. - Moved `loader::LoaderEvent` to `loader::LoaderService::Event` - Changed app instance `std::stack` to `std::vector` ## Improvements - `ElfApp`: error 22 now shows a hint that `main()` might be missing - Starting, installing and uninstalling apps now stops any running app (and its children) on the stack ## Bugfixes - `HttpdReq` out of memory issue now shows an error message and doesn't crash anymore (this would happen on devices without PSRAM with WiFi active, when an app was installed) - `GuiService::hideApp()` lock should not wait for timeout and now waits indefinitely - `Buildscript/release-sdk-current.sh` deletes the previous local release before building a new one ## Code correctness - App classes were made `final` - Apps that had a `void start()` now have a `LaunchId start()` - `tt::app::State`: renamed `Started` to `Created` and `Stopped` to `Destroyed` to properly reflect earlier name changes
116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include "Tactility/app/AppContext.h"
|
|
|
|
#include <Tactility/Bundle.h>
|
|
#include <Tactility/Mutex.h>
|
|
|
|
#include <string>
|
|
|
|
// Forward declarations
|
|
typedef struct _lv_obj_t lv_obj_t;
|
|
|
|
namespace tt::app {
|
|
|
|
// Forward declarations
|
|
class AppContext;
|
|
enum class Result;
|
|
|
|
typedef unsigned int LaunchId;
|
|
|
|
class App {
|
|
|
|
Mutex mutex;
|
|
|
|
struct ResultHolder {
|
|
Result result;
|
|
std::unique_ptr<Bundle> resultData;
|
|
|
|
explicit ResultHolder(Result result) : result(result), resultData(nullptr) {}
|
|
|
|
ResultHolder(Result result, std::unique_ptr<Bundle> resultData) :
|
|
result(result),
|
|
resultData(std::move(resultData)) {}
|
|
};
|
|
|
|
std::unique_ptr<ResultHolder> resultHolder;
|
|
|
|
public:
|
|
|
|
App() = default;
|
|
virtual ~App() = default;
|
|
|
|
virtual void onCreate(AppContext& appContext) {}
|
|
virtual void onDestroy(AppContext& appContext) {}
|
|
virtual void onShow(AppContext& appContext, lv_obj_t* parent) {}
|
|
virtual void onHide(AppContext& appContext) {}
|
|
virtual void onResult(AppContext& appContext, LaunchId launchId, Result result, std::unique_ptr<Bundle> _Nullable resultData) {}
|
|
|
|
Mutex& getMutex() { return mutex; }
|
|
|
|
bool hasResult() const { return resultHolder != nullptr; }
|
|
|
|
void setResult(Result result, std::unique_ptr<Bundle> resultData = nullptr) {
|
|
auto lock = getMutex().asScopedLock();
|
|
lock.lock();
|
|
resultHolder = std::make_unique<ResultHolder>(result, std::move(resultData));
|
|
}
|
|
|
|
/**
|
|
* Used by system to extract the result data when this application is finished.
|
|
* Note that this removes the data from the class!
|
|
*/
|
|
bool moveResult(Result& outResult, std::unique_ptr<Bundle>& outBundle) {
|
|
auto lock = getMutex().asScopedLock();
|
|
lock.lock();
|
|
|
|
if (resultHolder == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
outResult = resultHolder->result;
|
|
outBundle = std::move(resultHolder->resultData);
|
|
resultHolder = nullptr;
|
|
return true;
|
|
}
|
|
};
|
|
|
|
template<typename T>
|
|
std::shared_ptr<App> create() { return std::shared_ptr<T>(new T); }
|
|
|
|
/**
|
|
* @brief Start an app
|
|
* @param[in] id application name or id
|
|
* @param[in] parameters optional parameters to pass onto the application
|
|
*/
|
|
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters = nullptr);
|
|
|
|
/** @brief Stop the currently showing app. Show the previous app if any app was still running. */
|
|
void stop();
|
|
|
|
/** @brief Stop a specific app and any apps it might have launched on the stack.
|
|
* @param[in] id the app id
|
|
*/
|
|
void stop(const std::string& id);
|
|
|
|
/** @brief Stop all app instances that match with this identifier and also stop the apps they started.
|
|
* @warning onResult() will only be called for the resulting app that gets shown (if any)
|
|
* @param[in] id the id of the app to stop
|
|
*/
|
|
void stopAll(const std::string& id);
|
|
|
|
/** @return true if the app is running somewhere in the app stack (doesn't have to be the top-most app) */
|
|
bool isRunning(const std::string& id);
|
|
|
|
/** @return the currently running app context (it is only ever null before the splash screen is shown) */
|
|
std::shared_ptr<AppContext> _Nullable getCurrentAppContext();
|
|
|
|
/** @return the currently running app (it is only ever null before the splash screen is shown) */
|
|
std::shared_ptr<App> _Nullable getCurrentApp();
|
|
|
|
bool install(const std::string& path);
|
|
|
|
bool uninstall(const std::string& appId);
|
|
|
|
}
|