- Refactor the way apps work: Instead of a C interface, they are now C++ classes. The main reasoning is that attaching data to an app was cumbersome. Having different implementations for different kinds of apps was cumbersome too. (3 or 4 layers of manifest nesting for the TactilityC project) - External apps are still written in C, but they get a createData/destroyData in their manifest, so: - External apps now have their own manifest. - All functions in the original AppManifest are removed and replaced by a single `createApp` function - External apps now automatically register (each app individually!) when they run the first time. As a side-effect they become visible in the `AppList` app! - Adapted all apps for the new interface. - Adapted all internal logic for these changes (Gui, ViewPort, Loader, AppContext, AppInstance, etc.) - Rewrote parts of Loader to use std::shared_ptr to make the code much safer. - Added a refcount check for the `AppInstance` and `App` at the end of their lifecycle. Show warning if refcount is too high.
87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "CoreDefines.h"
|
|
#include "ManifestRegistry.h"
|
|
#include <Bundle.h>
|
|
#include <string>
|
|
|
|
// Forward declarations
|
|
typedef struct _lv_obj_t lv_obj_t;
|
|
|
|
namespace tt::app {
|
|
|
|
class App;
|
|
class AppContext;
|
|
|
|
/** Application types */
|
|
enum class Type {
|
|
/** Boot screen, shown before desktop is launched. */
|
|
Boot,
|
|
/** A launcher app sits at the root of the app stack after the boot splash is finished */
|
|
Launcher,
|
|
/** Apps that generally aren't started from the desktop (e.g. image viewer) */
|
|
Hidden,
|
|
/** Standard apps, provided by the system. */
|
|
System,
|
|
/** The apps that are launched/shown by the Settings app. The Settings app itself is of type AppTypeSystem. */
|
|
Settings,
|
|
/** User-provided apps. */
|
|
User
|
|
};
|
|
|
|
/** Result status code for application result callback. */
|
|
enum class Result {
|
|
Ok = 0U,
|
|
Cancelled = 1U,
|
|
Error = 2U
|
|
};
|
|
|
|
class Location {
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
Location() = default;
|
|
explicit Location(const std::string& path) : path(path) {}
|
|
|
|
public:
|
|
|
|
static Location internal() { return {}; }
|
|
|
|
static Location external(const std::string& path) {
|
|
return Location(path);
|
|
}
|
|
|
|
bool isInternal() const { return path.empty(); }
|
|
bool isExternal() const { return !path.empty(); }
|
|
const std::string& getPath() const { return path; }
|
|
};
|
|
|
|
typedef std::shared_ptr<App>(*CreateApp)();
|
|
|
|
struct AppManifest {
|
|
/** The identifier by which the app is launched by the system and other apps. */
|
|
std::string id;
|
|
|
|
/** The user-readable name of the app. Used in UI. */
|
|
std::string name;
|
|
|
|
/** Optional icon. */
|
|
std::string icon = {};
|
|
|
|
/** App type affects launch behaviour. */
|
|
Type type = Type::User;
|
|
|
|
/** Where the app is located */
|
|
Location location = Location::internal();
|
|
|
|
/** Create the instance of the app */
|
|
CreateApp createApp = nullptr;
|
|
};
|
|
|
|
struct {
|
|
bool operator()(const std::shared_ptr<AppManifest>& left, const std::shared_ptr<AppManifest>& right) const { return left->name < right->name; }
|
|
} SortAppManifestByName;
|
|
|
|
} // namespace
|