Skip to content

Commit 5d69cee

Browse files
Merge branch 'main' into charles_dev
# Conflicts: # lib/gui/src/ElementBase.cpp # lib/gui/src/elements/Button.hpp # lib/tasks/src/standby.cpp # src/main.cpp
2 parents d59bed1 + ac2562b commit 5d69cee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2456
-502
lines changed

lib/applications/src/app.cpp

+25-149
Original file line numberDiff line numberDiff line change
@@ -3,109 +3,6 @@
33
#include <libsystem.hpp>
44
#include <standby.hpp>
55

6-
// namespace app {
7-
// std::vector<App> appList;
8-
//
9-
// bool request;
10-
// AppRequest requestingApp;
11-
//
12-
// void init() {
13-
// std::vector<std::string> dirs = storage::Path(APP_DIR).listdir();
14-
//
15-
// storage::FileStream stream((storage::Path(PERMS_DIR) / "auth.list").str(), storage::READ);
16-
// const std::string allowedFiles = stream.read();
17-
// stream.close();
18-
//
19-
// for (const auto& dir: dirs) {
20-
// std::cout << (storage::Path(APP_DIR) / dir).str() << std::endl;
21-
// if (allowedFiles.find((storage::Path(APP_DIR) / dir).str()) != std::string::npos) {
22-
// appList.push_back({
23-
// dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(PERMS_DIR) / (dir + ".json"), true
24-
// });
25-
// } else {
26-
// appList.push_back({
27-
// dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(APP_DIR) / dir / "manifest.json", false
28-
// });
29-
// }
30-
// }
31-
// }
32-
//
33-
// App getApp(const std::string& appName) {
34-
// for (auto &app: appList) {
35-
// if (app.name == appName) {
36-
// return app;
37-
// }
38-
// }
39-
//
40-
// return {"", storage::Path(), storage::Path(), false};
41-
// }
42-
//
43-
// bool askPerm(App &app) {
44-
// gui::elements::Window win;
45-
// auto *label = new Label(0, 0, 320, 400);
46-
//
47-
// storage::FileStream stream(app.manifest.str(), storage::READ);
48-
// std::string data = stream.read();
49-
// stream.close();
50-
//
51-
// label->setText(data);
52-
// win.addChild(label);
53-
//
54-
// auto *btn = new Button(35, 420, 250, 38);
55-
// btn->setText("Accepter");
56-
// win.addChild(btn);
57-
//
58-
// // TODO: Add "Cancel" button
59-
//
60-
// while (true) {
61-
// win.updateAll();
62-
//
63-
// if (btn->isTouched()) {
64-
// storage::FileStream streamP((storage::Path(PERMS_DIR) / "auth.list").str(), storage::APPEND);
65-
// streamP.write(app.path.str() + "\n");
66-
// streamP.close();
67-
//
68-
// app.manifest = storage::Path(PERMS_DIR) / (app.name + ".json");
69-
// app.auth = true;
70-
//
71-
// storage::FileStream newPermCopy(app.manifest.str(), storage::WRITE);
72-
// newPermCopy.write(data);
73-
// newPermCopy.close();
74-
//
75-
// return true;
76-
// }
77-
// }
78-
// }
79-
//
80-
// void runApp(const storage::Path& path) {
81-
// for (auto &app: appList) {
82-
// if (app.path.str() == path.str()) {
83-
// if (app.auth) {
84-
// std::cout << "Succes: running app" << std::endl;
85-
// LuaFile luaApp(path, app.manifest);
86-
// luaApp.run();
87-
// } else {
88-
// std::cout << "Asking for permissions" << std::endl;
89-
//
90-
// if (askPerm(app)) {
91-
// LuaFile luaApp(path, app.manifest);
92-
// luaApp.run();
93-
// }
94-
// }
95-
//
96-
// return;
97-
// }
98-
// }
99-
//
100-
// std::cout << "Error: no such app" << std::endl;
101-
// }
102-
//
103-
// void runApp(const AppRequest& app) {
104-
// LuaFile luaApp(app.app.path, app.app.manifest);
105-
// luaApp.run(app.parameters);
106-
// }
107-
// };
108-
1096
namespace AppManager {
1107
App::App(const std::string& name, const storage::Path& path, const storage::Path& manifest, const bool auth)
1118
: name(name), fullName(name), path(path), manifest(manifest),
@@ -377,69 +274,48 @@ namespace AppManager {
377274
}
378275

379276
void loop() {
380-
threadsync.lock();
381-
// Implementation for the main loop
382-
if (!appStack.empty() && hardware::getHomeButton())
383-
// if the home button is pressed, remove the app from the stack, and kill it if it's not running in the background
384-
{
385-
while (hardware::getHomeButton()) {}
386-
387-
if (!appStack.empty()) {
388-
if (appStack.back()->background == false) {
389-
const auto app = appStack.back();
390-
int count = 0; // TODO: Use ?
277+
updateForeground();
278+
updateBackground();
279+
}
391280

392-
for (const auto& it : appStack) {
393-
if (it == app) {
394-
count++;
395-
}
396-
}
281+
void updateForeground() {
282+
threadsync.lock();
397283

284+
// Run tick on every app
285+
for (const auto& app: appList) {
286+
if(app->background == false) // app is not in background
287+
{
288+
if (app->isRunning()) { // app is running
289+
app->luaInstance->loop();
290+
} else if (std::find(appStack.begin(), appStack.end(), app.get()) != appStack.end()) // if app is no longer in the stack (no gui is running) -> kill it
291+
{
398292
app->kill();
399-
} else {
400-
std::cerr << "Error: app is in background" << std::endl;
401293
}
402-
403-
appStack.pop_back();
404-
}
405-
}
406-
407-
for (const auto& app: appList) {
408-
if (app->isRunning()) {
409-
app->luaInstance->loop();
410-
} else if (app->luaInstance != nullptr) {
411-
app->kill();
412294
}
413295
}
414296

297+
// Update foreground app GUI
415298
if (!appStack.empty()) {
416-
appStack.back()->luaInstance->lua_gui.update();
299+
const App* app = appStack.back();
300+
301+
if (app->luaInstance != nullptr) {
302+
app->luaInstance->lua_gui.update();
303+
}
417304
}
418305

419306
threadsync.unlock();
420-
421-
StandbyMode::wait();
422307
}
423308

424-
void update() {
309+
void updateBackground() {
425310
threadsync.lock();
426311

427312
// Run tick on every app
428313
for (const auto& app: appList) {
429-
if (app->isRunning()) {
430-
app->luaInstance->loop();
431-
} else if (app->luaInstance != nullptr) {
432-
app->kill();
433-
}
434-
}
435-
436-
// Update foreground app GUI
437-
// TODO : What happens if a background app is on top of a foreground app on the stack ?
438-
if (!appStack.empty()) {
439-
const App* app = appStack.back();
440-
441-
if (app->luaInstance != nullptr) {
442-
app->luaInstance->lua_gui.update();
314+
if(app->background == true) // app is in background
315+
{
316+
if (app->isRunning()) { // app is running
317+
app->luaInstance->loop();
318+
}
443319
}
444320
}
445321

lib/applications/src/app.hpp

+57-56
Original file line numberDiff line numberDiff line change
@@ -14,113 +14,114 @@
1414
#define PERMS_DIR "/system"
1515

1616

17-
// namespace app
18-
// {
19-
// struct App
20-
// {
21-
// std::string name;
22-
// storage::Path path;
23-
// storage::Path manifest;
24-
// bool auth;
25-
// };
26-
//
27-
// struct AppRequest
28-
// {
29-
// App app;
30-
// std::vector<std::string> parameters;
31-
// };
32-
//
33-
// extern std::vector<App> appList;
34-
//
35-
// extern bool request;
36-
// extern AppRequest requestingApp;
37-
//
38-
// void init();
39-
// App getApp(const std::string& appName);
40-
// bool askPerm(App &app);
41-
// void runApp(const storage::Path& path);
42-
// void runApp(const AppRequest& app);
43-
// };
44-
4517
namespace AppManager
4618
{
4719
struct Permissions
4820
{
4921
// It's better with english (access)
5022

51-
bool acces_gui = false;
23+
bool acces_gui = false; // graphics
5224
bool acces_files = false;
53-
bool acces_files_root = false;
54-
bool acces_hardware = false;
55-
bool acces_time = false;
56-
bool acces_web_paxo = false;
57-
bool acces_web = false;
58-
bool acces_gsm = false;
25+
bool acces_files_root = false; // files from /
26+
bool acces_hardware = false; // hardware, ex: light, flash, vibrator...
27+
bool acces_time = false; // time
28+
bool acces_web_paxo = false; // web only on paxo.fr
29+
bool acces_web = false; // on any url
30+
bool acces_gsm = false; // messages, calls
5931
};
6032

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

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

44+
/**
45+
* @brief Wake up the app (if it was sleeping)
46+
*/
6847
void wakeup();
6948

49+
/**
50+
* @brief Put the app to sleep = the app will still loaded, but it will have neither events nor code that run.
51+
*
52+
* @note If the app is not running, this function does nothing
53+
*/
7054
void sleep();
71-
72-
[[nodiscard]] bool isRunning() const; // app is active
73-
[[nodiscard]] bool isLoaded() const; // app is loaded and allocated
74-
[[nodiscard]] bool isVisible() const; // app is visible
55+
/**
56+
* @return true if the app is running (and not sleeping)
57+
*/
58+
[[nodiscard]] bool isRunning() const;
59+
60+
/**
61+
* @return true if the app is loaded and allocated (even if it's sleeping)
62+
*/
63+
[[nodiscard]] bool isLoaded() const;
64+
65+
/**
66+
* @return true if the app is both running and visible
67+
*/
68+
[[nodiscard]] bool isVisible() const;
69+
70+
/**
71+
* @brief Kill the app (if it was running)
72+
*
73+
* @note If the app is not running, this function does nothing
74+
*/
7575
void kill();
7676

77+
/**
78+
* @brief Request auth for the app, so it's manifest is agreed
79+
*/
7780
void requestAuth();
7881

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

81-
std::string name;
82-
std::string fullName;
83-
storage::Path path; // app directory
84-
storage::Path manifest;
85-
bool auth; // is allowed to run
86-
bool visible = false;
84+
std::string name; // app name
85+
std::string fullName; // app directory name, full name
86+
storage::Path path; // app directory
87+
storage::Path manifest; // app manifest (can be in the app folder is not validated, or in the system folder if validated)
88+
bool auth; // is allowed to run
89+
bool visible = false; // is visible on the menu (if it has a . before the folder name)
8790

88-
std::string errors;
91+
std::string errors; // errors pushed from the app
8992

90-
enum AppState {
93+
enum AppState { // app state
9194
RUNNING,
9295
RUNNING_BACKGROUND,
9396
SLEEPING,
9497
NOT_RUNNING
9598
};
9699

97-
std::shared_ptr<LuaFile> luaInstance;
98-
uint8_t app_state;
99-
bool background;
100+
std::shared_ptr<LuaFile> luaInstance; // lua environment for the app
101+
uint8_t app_state; // app state
102+
bool background; // app is in background
100103
};
101104

102105
// TODO : Check if "extern" is needed
103106

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

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

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

113116
void init();
114117

115-
/**
116-
* @deprecated
117-
*/
118118
void loop();
119119

120120
/**
121121
* Update every application.
122122
*/
123-
void update();
123+
void updateForeground(); // easy to understand
124+
void updateBackground();
124125

125126
/**
126127
* Quit the currently foreground running application.

0 commit comments

Comments
 (0)