From 4bf55d7303c1b28a3ca5ad5437914d0eac29c0e9 Mon Sep 17 00:00:00 2001 From: paxo-rch Date: Mon, 28 Oct 2024 19:59:45 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20mise=20a=20jour=20des=20apps=20premierpl?= =?UTF-8?q?an/arri=C3=A8replan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/applications/src/app.cpp | 56 +++++++++++-------- lib/applications/src/app.hpp | 3 +- lib/gui/src/ElementBase.cpp | 6 +- lib/lua/src/lua_file.cpp | 4 +- src/main.cpp | 10 ++-- storage/sys_apps/testbc/app.lua | 20 ++++--- storage/sys_apps/testbc/manifest.json | 2 +- .../sys_apps/testbc/sub/.sub1/manifest.json | 2 +- 8 files changed, 57 insertions(+), 46 deletions(-) diff --git a/lib/applications/src/app.cpp b/lib/applications/src/app.cpp index 18cef1d3..3eb3621d 100644 --- a/lib/applications/src/app.cpp +++ b/lib/applications/src/app.cpp @@ -8,10 +8,9 @@ namespace AppManager { : name(name), fullName(name), path(path), manifest(manifest), auth(auth), luaInstance(nullptr), app_state(NOT_RUNNING), background(false) { - std::cout << "App: \"" << name << "\" \"" << fullName << "\"" << std::endl; } - void App::run(const bool background, const std::vector& parameters) { + void App::run(const std::vector& parameters) { if (!auth) { throw libsystem::exceptions::RuntimeError("App is not authorized to run"); } @@ -43,7 +42,7 @@ namespace AppManager { } bool App::isRunning() const { - return app_state == RUNNING || app_state == RUNNING_BACKGROUND; + return this->luaInstance != nullptr; } bool App::isLoaded() const { @@ -62,6 +61,14 @@ namespace AppManager { luaInstance->stop(); luaInstance.reset(); // delete luaInstance + for (auto it = appStack.begin(); it != appStack.end();) { + if (*it == this) { + it = appStack.erase(it); + } else { + ++it; + } + } + app_state = NOT_RUNNING; std::cout << "App killed" << std::endl; @@ -174,7 +181,7 @@ namespace AppManager { void askGui(const LuaFile* lua) { App* app = lua->app; - if (lua->lua_gui.mainWindow == nullptr) { + /*if (lua->lua_gui.mainWindow == nullptr) { for (auto it = appStack.begin(); it != appStack.end(); ++it) { if (*it == app) { app->app_state = App::AppState::NOT_RUNNING; @@ -184,7 +191,7 @@ namespace AppManager { } return; - } + }*/ // if (appStack.empty() || appStack.back() != app) { // appStack.push_back(app); @@ -198,11 +205,11 @@ namespace AppManager { std::string allowedFiles = stream.read(); stream.close(); - libsystem::log("auth.list : " + allowedFiles); + //libsystem::log("auth.list : " + allowedFiles); for (auto dir: dirs) { auto appPath = storage::Path(directory) / dir; - libsystem::log("Loading app at \"" + appPath.str() + "\"."); + //libsystem::log("Loading app at \"" + appPath.str() + "\"."); auto manifestPath = storage::Path(directory) / dir / "manifest.json"; @@ -211,7 +218,7 @@ namespace AppManager { manifestStream.close(); if (!nlohmann::json::accept(manifestContent)) { - std::cout << "Error: invalid manifest at \"" << manifestPath.str() << "\"" << std::endl; + std::cerr << "Error: invalid manifest at \"" << manifestPath.str() << "\"" << std::endl; continue; } @@ -242,7 +249,8 @@ namespace AppManager { ); } - app->fullName = prefix.size() ? (prefix + "." + dir) : (dir); + app->fullName = prefix.size() ? (prefix + dir) : (dir); + libsystem::log("Loading app \"" + app->fullName + "\"."); if (!dir.empty() && dir[0] == '.') { app->visible = false; @@ -260,12 +268,6 @@ namespace AppManager { std::cout << "loading app in the background" << std::endl; } - if (manifest["autorun"].is_boolean()) { - if (manifest["autorun"] && app->background) { - app.get()->run(true); - } - } - if(manifest["subdir"].is_string()) // todo, restrict only for subdirs { if((app.get()->path / "../" / manifest["subdir"]).exists()) @@ -275,8 +277,14 @@ namespace AppManager { } // Add app to list - libsystem::log("Loaded app : " + app->toString() + "."); + //libsystem::log("Loaded app : " + app->toString() + "."); appList.push_back(app); + + if (manifest["autorun"].is_boolean()) { + if (manifest["autorun"] && app->background) { + app.get()->run(); + } + } } } @@ -297,22 +305,25 @@ namespace AppManager { for (const auto& app: appList) { if(app->background == false) // app is not in background { - if (app->isRunning()) { // app is running - app->luaInstance->loop(); - } 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 + if (app->isRunning()) { - app->kill(); + app->luaInstance->loop(); } } } // Update foreground app GUI if (!appStack.empty()) { - const App* app = appStack.back(); + App* app = appStack.back(); if (app->luaInstance != nullptr) { app->luaInstance->lua_gui.update(); } + + if(app->luaInstance->lua_gui.mainWindow == nullptr) // app has no GUI + { + app->kill(); + } } threadsync.unlock(); @@ -348,9 +359,6 @@ namespace AppManager { // Kill the app app->kill(); - - // Remove app from stack - appStack.pop_back(); } bool isAnyVisibleApp() { diff --git a/lib/applications/src/app.hpp b/lib/applications/src/app.hpp index b04fab14..856b73ad 100644 --- a/lib/applications/src/app.hpp +++ b/lib/applications/src/app.hpp @@ -36,10 +36,9 @@ namespace AppManager 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 ¶meters = {}); + void run(const std::vector ¶meters = {}); /** * @brief Wake up the app (if it was sleeping) diff --git a/lib/gui/src/ElementBase.cpp b/lib/gui/src/ElementBase.cpp index 1d5e46da..e88c5996 100644 --- a/lib/gui/src/ElementBase.cpp +++ b/lib/gui/src/ElementBase.cpp @@ -210,9 +210,11 @@ bool gui::ElementBase::update() if (widgetPressed != nullptr && widgetPressed != this) return false; + uint16_t resolution = 0; + bool isScreenTouched = graphics::isTouched(); - bool isWidgetTouched = isScreenTouched && (getAbsoluteX()-10 < touchX && touchX < getAbsoluteX() + getWidth() +10 && - getAbsoluteY()-10 < touchY && touchY < getAbsoluteY() + getHeight() +10); + bool isWidgetTouched = isScreenTouched && (getAbsoluteX()-resolution < touchX && touchX < getAbsoluteX() + getWidth() +resolution && + getAbsoluteY()-resolution < touchY && touchY < getAbsoluteY() + getHeight() +resolution); bool returnValue = false; diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index 41270f22..4284dc76 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -619,7 +619,7 @@ void LuaFile::load() lua.set_function("launch", sol::overload([&](std::string name, std::vector arg) { try{ - AppManager::get(name)->run(false, arg); + AppManager::get(name)->run(arg); } catch(std::runtime_error &e) { std::cerr << "Erreur: " << e.what() << std::endl; @@ -633,7 +633,7 @@ void LuaFile::load() { try { - AppManager::get(name)->run(false, {}); + AppManager::get(name)->run({}); } catch (std::runtime_error &e) { diff --git a/src/main.cpp b/src/main.cpp index 03c350be..7f69409b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,10 +56,10 @@ void mainLoop(void* data) { try { const std::shared_ptr oobeApp = AppManager::get(".oobe"); - oobeApp->run(false); + oobeApp->run(); } catch (std::runtime_error& e) { - std::cerr << "Lua error: " << e.what() << std::endl; - guiManager.showErrorMessage(e.what()); + //std::cerr << "Lua error: " << e.what() << std::endl; + //guiManager.showErrorMessage(e.what()); //AppManager::appList[i].kill(); } } @@ -99,7 +99,7 @@ void mainLoop(void* data) { // Launch the app try { - app->run(app->background); + app->run(); } catch (std::runtime_error& e) { std::cerr << "Erreur: " << e.what() << std::endl; // Affichage du msg d'erreur @@ -241,7 +241,7 @@ void setup() // gestion des appels entrants GSM::ExternalEvents::onIncommingCall = []() { - eventHandlerApp.setTimeout(new Callback<>([](){AppManager::get(".receivecall")->run(false);}), 0); + eventHandlerApp.setTimeout(new Callback<>([](){AppManager::get(".receivecall")->run();}), 0); }; // Gestion de la réception d'un message diff --git a/storage/sys_apps/testbc/app.lua b/storage/sys_apps/testbc/app.lua index e9085a12..f5f412cb 100644 --- a/storage/sys_apps/testbc/app.lua +++ b/storage/sys_apps/testbc/app.lua @@ -1,15 +1,17 @@ function run() print("run baground testbc app, no displayed: show conter to 10 and run settings app") print(time) - local counter = 0 + -- local counter = 0 - local function printCounter() - counter = counter + 1 - print("Counter: " .. counter .. " sec") - if(counter == 10) then - launch("settings") - end - end + -- local function printCounter() + -- counter = counter + 1 + -- print("Counter: " .. counter .. " sec") + -- if(counter == 10) then + -- launch("settings") + -- end + -- end - time:setInterval(printCounter, 1000) + -- time:setInterval(printCounter, 1000) + + launch("testbc.sub1") end \ No newline at end of file diff --git a/storage/sys_apps/testbc/manifest.json b/storage/sys_apps/testbc/manifest.json index bd8ea4ca..79717348 100644 --- a/storage/sys_apps/testbc/manifest.json +++ b/storage/sys_apps/testbc/manifest.json @@ -4,6 +4,6 @@ "files", "time" ], - "background": true, + "background": false, "subdir": "sub" } \ No newline at end of file diff --git a/storage/sys_apps/testbc/sub/.sub1/manifest.json b/storage/sys_apps/testbc/sub/.sub1/manifest.json index fd0db4e8..fba5d376 100644 --- a/storage/sys_apps/testbc/sub/.sub1/manifest.json +++ b/storage/sys_apps/testbc/sub/.sub1/manifest.json @@ -5,5 +5,5 @@ "time" ], "background": true, - "autorun": true + "autorun": false } \ No newline at end of file