Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paxo-rch committed Sep 11, 2024
1 parent 0b31f22 commit 6bc9980
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 189 deletions.
103 changes: 0 additions & 103 deletions lib/applications/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,109 +3,6 @@
#include <libsystem.hpp>
#include <standby.hpp>

// namespace app {
// std::vector<App> appList;
//
// bool request;
// AppRequest requestingApp;
//
// void init() {
// std::vector<std::string> dirs = storage::Path(APP_DIR).listdir();
//
// storage::FileStream stream((storage::Path(PERMS_DIR) / "auth.list").str(), storage::READ);
// const std::string allowedFiles = stream.read();
// stream.close();
//
// for (const auto& dir: dirs) {
// std::cout << (storage::Path(APP_DIR) / dir).str() << std::endl;
// if (allowedFiles.find((storage::Path(APP_DIR) / dir).str()) != std::string::npos) {
// appList.push_back({
// dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(PERMS_DIR) / (dir + ".json"), true
// });
// } else {
// appList.push_back({
// dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(APP_DIR) / dir / "manifest.json", false
// });
// }
// }
// }
//
// App getApp(const std::string& appName) {
// for (auto &app: appList) {
// if (app.name == appName) {
// return app;
// }
// }
//
// return {"", storage::Path(), storage::Path(), false};
// }
//
// bool askPerm(App &app) {
// gui::elements::Window win;
// auto *label = new Label(0, 0, 320, 400);
//
// storage::FileStream stream(app.manifest.str(), storage::READ);
// std::string data = stream.read();
// stream.close();
//
// label->setText(data);
// win.addChild(label);
//
// auto *btn = new Button(35, 420, 250, 38);
// btn->setText("Accepter");
// win.addChild(btn);
//
// // TODO: Add "Cancel" button
//
// while (true) {
// win.updateAll();
//
// if (btn->isTouched()) {
// storage::FileStream streamP((storage::Path(PERMS_DIR) / "auth.list").str(), storage::APPEND);
// streamP.write(app.path.str() + "\n");
// streamP.close();
//
// app.manifest = storage::Path(PERMS_DIR) / (app.name + ".json");
// app.auth = true;
//
// storage::FileStream newPermCopy(app.manifest.str(), storage::WRITE);
// newPermCopy.write(data);
// newPermCopy.close();
//
// return true;
// }
// }
// }
//
// void runApp(const storage::Path& path) {
// for (auto &app: appList) {
// if (app.path.str() == path.str()) {
// if (app.auth) {
// std::cout << "Succes: running app" << std::endl;
// LuaFile luaApp(path, app.manifest);
// luaApp.run();
// } else {
// std::cout << "Asking for permissions" << std::endl;
//
// if (askPerm(app)) {
// LuaFile luaApp(path, app.manifest);
// luaApp.run();
// }
// }
//
// return;
// }
// }
//
// std::cout << "Error: no such app" << std::endl;
// }
//
// void runApp(const AppRequest& app) {
// LuaFile luaApp(app.app.path, app.app.manifest);
// luaApp.run(app.parameters);
// }
// };

namespace AppManager {
App::App(const std::string& name, const storage::Path& path, const storage::Path& manifest, const bool auth)
: name(name), fullName(name), path(path), manifest(manifest),
Expand Down
110 changes: 55 additions & 55 deletions lib/applications/src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,107 +14,107 @@
#define PERMS_DIR "/system"


// namespace app
// {
// struct App
// {
// std::string name;
// storage::Path path;
// storage::Path manifest;
// bool auth;
// };
//
// struct AppRequest
// {
// App app;
// std::vector<std::string> parameters;
// };
//
// extern std::vector<App> appList;
//
// extern bool request;
// extern AppRequest requestingApp;
//
// void init();
// App getApp(const std::string& appName);
// bool askPerm(App &app);
// void runApp(const storage::Path& path);
// void runApp(const AppRequest& app);
// };

namespace AppManager
{
struct Permissions
{
// It's better with english (access)

bool acces_gui = false;
bool acces_gui = false; // graphics
bool acces_files = false;
bool acces_files_root = false;
bool acces_hardware = false;
bool acces_time = false;
bool acces_web_paxo = false;
bool acces_web = false;
bool acces_gsm = false;
bool acces_files_root = false; // files from /
bool acces_hardware = false; // hardware, ex: light, flash, vibrator...
bool acces_time = false; // time
bool acces_web_paxo = false; // web only on paxo.fr
bool acces_web = false; // on any url
bool acces_gsm = false; // messages, calls
};

class App
{
public:
App(const std::string& name, const storage::Path& path, const storage::Path& manifest, bool auth);

/**
* @param background Run in background
* @param parameters List of parameters to send to the lua run function of the app
*/
void run(bool background, const std::vector<std::string> &parameters = {});

/**
* @brief Wake up the app (if it was sleeping)
*/
void wakeup();

/**
* @brief Put the app to sleep = the app will still loaded, but it will have neither events nor code that run.
*
* @note If the app is not running, this function does nothing
*/
void sleep();

[[nodiscard]] bool isRunning() const; // app is active
[[nodiscard]] bool isLoaded() const; // app is loaded and allocated
[[nodiscard]] bool isVisible() const; // app is visible
/**
* @return true if the app is running (and not sleeping)
*/
[[nodiscard]] bool isRunning() const;

/**
* @return true if the app is loaded and allocated (even if it's sleeping)
*/
[[nodiscard]] bool isLoaded() const;

/**
* @return true if the app is both running and visible
*/
[[nodiscard]] bool isVisible() const;

/**
* @brief Kill the app (if it was running)
*
* @note If the app is not running, this function does nothing
*/
void kill();

/**
* @brief Request auth for the app, so it's manifest is agreed
*/
void requestAuth();

[[nodiscard]] std::string toString() const;

std::string name;
std::string fullName;
storage::Path path; // app directory
storage::Path manifest;
bool auth; // is allowed to run
bool visible = false;
std::string name; // app name
std::string fullName; // app directory name, full name
storage::Path path; // app directory
storage::Path manifest; // app manifest (can be in the app folder is not validated, or in the system folder if validated)
bool auth; // is allowed to run
bool visible = false; // is visible on the menu (if it has a . before the folder name)

std::string errors;
std::string errors; // errors pushed from the app

enum AppState {
enum AppState { // app state
RUNNING,
RUNNING_BACKGROUND,
SLEEPING,
NOT_RUNNING
};

std::shared_ptr<LuaFile> luaInstance;
uint8_t app_state;
bool background;
std::shared_ptr<LuaFile> luaInstance; // lua environment for the app
uint8_t app_state; // app state
bool background; // app is in background
};

// TODO : Check if "extern" is needed

extern std::mutex threadsync; // mutex for thread-safe operations between threads

extern std::vector<std::shared_ptr<App>> appList;
extern std::vector<App*> appStack;
extern std::vector<std::shared_ptr<App>> appList; // list of apps in the apps folder
extern std::vector<App*> appStack; // stack of the apps that are using the GUI, the last one is shown on the screen

int pushError(lua_State* L, sol::optional<const std::exception&> maybe_exception, sol::string_view description);
void askGui(const LuaFile* lua);
bool isAnyVisibleApp();

void init();

/**
* @deprecated
*/
void loop();

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/applications/src/launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace AppManager {
}

namespace applications::launcher {
void init();
void free();
void init(); // load the launcher
void free(); // free the launcher

void update();
void draw();
void update(); // update the launcher gui and events
void draw(); // make the gui of the launcher

bool iconTouched();
std::shared_ptr<AppManager::App> getApp();
bool iconTouched(); // check if an app icon is touched
std::shared_ptr<AppManager::App> getApp(); // get the selected app
}

#endif
16 changes: 8 additions & 8 deletions lib/gsm/src/contacts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace Contacts
std::string phone;
};

void load();
void save();
void load(); // load the contacts
void save(); // save the contacts

std::vector<contact> listContacts();
void addContact(contact c);
void deleteContact(std::string name);
void editContact(std::string name, contact c);
contact getContact(std::string name);
contact getByNumber(std::string number);
std::vector<contact> listContacts(); // local contact list (synchronized using load and save functions)
void addContact(contact c); // add a new contact {name, phone}
void deleteContact(std::string name); // delete a contact by name
void editContact(std::string name, contact c); // edit a contact by name
contact getContact(std::string name); // get a contact by name
contact getByNumber(std::string number); // get a contact by number
};

#endif // CONTACTS_HPP
10 changes: 10 additions & 0 deletions lib/gsm/src/conversation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ namespace Conversations
std::vector<Message> messages;
};

/**
* @brief Load a conversation from a file
* @param filePath The file path containing the conversation to load
* @param conv The conversation to load into
*/
void loadConversation(const storage::Path &filePath, Conversation &conv);
/**
* @brief Save a conversation to a file
* @param filePath The file path to save the conversation to
* @param conv The conversation to save
*/
void saveConversation(const storage::Path &filePath, const Conversation &conv);
}

Expand Down
1 change: 1 addition & 0 deletions lib/gsm/src/gsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ namespace GSM

#endif

// MMS: download a MMS from a URL, then decode the jpeg in it, and add it to the related conversation
std::string getHttpMMS(std::string number, std::string url) {
#ifdef ESP_PLATFORM
StandbyMode::triggerPower();
Expand Down
Loading

0 comments on commit 6bc9980

Please sign in to comment.