Merge develop into main (#348)

## 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
This commit is contained in:
Ken Van Hoeylandt
2025-09-27 18:04:09 +02:00
committed by GitHub
parent dcf28d0868
commit f6cdabf3c0
48 changed files with 504 additions and 342 deletions
+14
View File
@@ -88,6 +88,20 @@ LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable pa
/** @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();
@@ -1,7 +1,9 @@
#pragma once
#include <Tactility/app/App.h>
namespace tt::app::imageviewer {
void start(const std::string& file);
LaunchId start(const std::string& file);
};
}
@@ -1,5 +1,6 @@
#pragma once
#include <Tactility/app/App.h>
#include <Tactility/Bundle.h>
#include <string>
@@ -11,7 +12,7 @@
*/
namespace tt::app::inputdialog {
void start(const std::string& title, const std::string& message, const std::string& prefilled = "");
LaunchId start(const std::string& title, const std::string& message, const std::string& prefilled = "");
/**
* @return the text that was in the field when OK was pressed, or otherwise empty string
@@ -1,11 +1,14 @@
#pragma once
#include <Tactility/app/App.h>
namespace tt::app::notes {
/**
* Start the notes app with the specified text file.
* @param[in] filePath the path to the text file to open
* @return the launch id
*/
void start(const std::string& filePath);
LaunchId start(const std::string& filePath);
}
@@ -1,5 +1,6 @@
#pragma once
#include <Tactility/app/App.h>
#include <Tactility/Bundle.h>
#include <string>
@@ -15,7 +16,7 @@
*/
namespace tt::app::selectiondialog {
void start(const std::string& title, const std::vector<std::string>& items);
LaunchId start(const std::string& title, const std::vector<std::string>& items);
/**
* Get the index of the item that the user selected.
@@ -1,7 +1,9 @@
#pragma once
#include <Tactility/app/App.h>
namespace tt::app::wifimanage {
void start();
LaunchId start();
} // namespace
@@ -1,45 +1,99 @@
#pragma once
#include "Tactility/app/AppManifest.h"
#include <Tactility/app/AppInstance.h>
#include <Tactility/app/AppManifest.h>
#include <Tactility/Bundle.h>
#include <Tactility/DispatcherThread.h>
#include <Tactility/PubSub.h>
#include <Tactility/service/Service.h>
#include <memory>
namespace tt::service::loader {
// region LoaderEvent for PubSub
enum class LoaderEvent{
ApplicationStarted,
ApplicationShowing,
ApplicationHiding,
ApplicationStopped
class LoaderService final : public Service {
public:
enum class Event {
ApplicationStarted,
ApplicationShowing,
ApplicationHiding,
ApplicationStopped
};
private:
std::shared_ptr<PubSub<Event>> pubsubExternal = std::make_shared<PubSub<Event>>();
Mutex mutex = Mutex(Mutex::Type::Recursive);
std::vector<std::shared_ptr<app::AppInstance>> appStack;
app::LaunchId nextLaunchId = 0;
/** The dispatcher thread needs a callstack large enough to accommodate all the dispatched methods.
* This includes full LVGL redraw via Gui::redraw()
*/
std::unique_ptr<DispatcherThread> dispatcherThread = std::make_unique<DispatcherThread>("loader_dispatcher", 6144); // Files app requires ~5k
void onStartAppMessage(const std::string& id, app::LaunchId launchId, std::shared_ptr<const Bundle> parameters);
void onStopTopAppMessage(const std::string& id);
void onStopAllAppMessage(const std::string& id);
void transitionAppToState(const std::shared_ptr<app::AppInstance>& app, app::State state);
int findAppInStack(const std::string& id) const;
bool onStart(TT_UNUSED ServiceContext& service) override {
dispatcherThread->start();
return true;
}
void onStop(TT_UNUSED ServiceContext& service) override {
// Send stop signal to thread and wait for thread to finish
mutex.withLock([this] {
dispatcherThread->stop();
});
}
public:
/**
* @brief Start an app given an app id and an optional bundle with parameters
* @param id the app identifier
* @param parameters optional parameter bundle
* @return the launch id
*/
app::LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters);
/**
* @brief Stops the top-most app (the one that is currently active shown to the user
* @warning Avoid calling this directly and use stopTop(id) instead
*/
void stopTop();
/**
* @brief Stops the top-most app if the id is still matching by the time the stop event arrives.
* @param id the id of the app to stop
*/
void stopTop(const std::string& id);
/**
* @brief Stops all apps with the provided id and any apps that were pushed on top of the stack after the original app was started.
* @param id the id of the app to stop
*/
void stopAll(const std::string& id);
/** @return the AppContext of the top-most application */
std::shared_ptr<app::AppContext> _Nullable getCurrentAppContext();
/** @return true if the app is running anywhere in the app stack (the app does not have to be the top-most one for this to return true) */
bool isRunning(const std::string& id) const;
/** @return the PubSub object that is responsible for event publishing */
std::shared_ptr<PubSub<Event>> getPubsub() const { return pubsubExternal; }
};
// endregion LoaderEvent for PubSub
/**
* @brief Start an app
* @param[in] id application name or id
* @param[in] parameters optional parameters to pass onto the application
* @return the launch id
*/
app::LaunchId startApp(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 stopApp();
/** @return the currently running app context (it is only ever null before the splash screen is shown) */
std::shared_ptr<app::AppContext> _Nullable getCurrentAppContext();
/** @return the currently running app (it is only ever null before the splash screen is shown) */
std::shared_ptr<app::App> _Nullable getCurrentApp();
/**
* @brief PubSub for LoaderEvent
*/
std::shared_ptr<PubSub<LoaderEvent>> getPubsub();
std::shared_ptr<LoaderService> _Nullable findLoaderService();
} // namespace