Skip to content

Commit 4bf55d7

Browse files
committed
Fix: mise a jour des apps premierplan/arrièreplan
1 parent eb4624d commit 4bf55d7

File tree

8 files changed

+57
-46
lines changed

8 files changed

+57
-46
lines changed

lib/applications/src/app.cpp

+32-24
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ namespace AppManager {
88
: name(name), fullName(name), path(path), manifest(manifest),
99
auth(auth),
1010
luaInstance(nullptr), app_state(NOT_RUNNING), background(false) {
11-
std::cout << "App: \"" << name << "\" \"" << fullName << "\"" << std::endl;
1211
}
1312

14-
void App::run(const bool background, const std::vector<std::string>& parameters) {
13+
void App::run(const std::vector<std::string>& parameters) {
1514
if (!auth) {
1615
throw libsystem::exceptions::RuntimeError("App is not authorized to run");
1716
}
@@ -43,7 +42,7 @@ namespace AppManager {
4342
}
4443

4544
bool App::isRunning() const {
46-
return app_state == RUNNING || app_state == RUNNING_BACKGROUND;
45+
return this->luaInstance != nullptr;
4746
}
4847

4948
bool App::isLoaded() const {
@@ -62,6 +61,14 @@ namespace AppManager {
6261
luaInstance->stop();
6362
luaInstance.reset(); // delete luaInstance
6463

64+
for (auto it = appStack.begin(); it != appStack.end();) {
65+
if (*it == this) {
66+
it = appStack.erase(it);
67+
} else {
68+
++it;
69+
}
70+
}
71+
6572
app_state = NOT_RUNNING;
6673

6774
std::cout << "App killed" << std::endl;
@@ -174,7 +181,7 @@ namespace AppManager {
174181
void askGui(const LuaFile* lua) {
175182
App* app = lua->app;
176183

177-
if (lua->lua_gui.mainWindow == nullptr) {
184+
/*if (lua->lua_gui.mainWindow == nullptr) {
178185
for (auto it = appStack.begin(); it != appStack.end(); ++it) {
179186
if (*it == app) {
180187
app->app_state = App::AppState::NOT_RUNNING;
@@ -184,7 +191,7 @@ namespace AppManager {
184191
}
185192
186193
return;
187-
}
194+
}*/
188195

189196
// if (appStack.empty() || appStack.back() != app) {
190197
// appStack.push_back(app);
@@ -198,11 +205,11 @@ namespace AppManager {
198205
std::string allowedFiles = stream.read();
199206
stream.close();
200207

201-
libsystem::log("auth.list : " + allowedFiles);
208+
//libsystem::log("auth.list : " + allowedFiles);
202209

203210
for (auto dir: dirs) {
204211
auto appPath = storage::Path(directory) / dir;
205-
libsystem::log("Loading app at \"" + appPath.str() + "\".");
212+
//libsystem::log("Loading app at \"" + appPath.str() + "\".");
206213

207214
auto manifestPath = storage::Path(directory) / dir / "manifest.json";
208215

@@ -211,7 +218,7 @@ namespace AppManager {
211218
manifestStream.close();
212219

213220
if (!nlohmann::json::accept(manifestContent)) {
214-
std::cout << "Error: invalid manifest at \"" << manifestPath.str() << "\"" << std::endl;
221+
std::cerr << "Error: invalid manifest at \"" << manifestPath.str() << "\"" << std::endl;
215222
continue;
216223
}
217224

@@ -242,7 +249,8 @@ namespace AppManager {
242249
);
243250
}
244251

245-
app->fullName = prefix.size() ? (prefix + "." + dir) : (dir);
252+
app->fullName = prefix.size() ? (prefix + dir) : (dir);
253+
libsystem::log("Loading app \"" + app->fullName + "\".");
246254

247255
if (!dir.empty() && dir[0] == '.') {
248256
app->visible = false;
@@ -260,12 +268,6 @@ namespace AppManager {
260268
std::cout << "loading app in the background" << std::endl;
261269
}
262270

263-
if (manifest["autorun"].is_boolean()) {
264-
if (manifest["autorun"] && app->background) {
265-
app.get()->run(true);
266-
}
267-
}
268-
269271
if(manifest["subdir"].is_string()) // todo, restrict only for subdirs
270272
{
271273
if((app.get()->path / "../" / manifest["subdir"]).exists())
@@ -275,8 +277,14 @@ namespace AppManager {
275277
}
276278

277279
// Add app to list
278-
libsystem::log("Loaded app : " + app->toString() + ".");
280+
//libsystem::log("Loaded app : " + app->toString() + ".");
279281
appList.push_back(app);
282+
283+
if (manifest["autorun"].is_boolean()) {
284+
if (manifest["autorun"] && app->background) {
285+
app.get()->run();
286+
}
287+
}
280288
}
281289
}
282290

@@ -297,22 +305,25 @@ namespace AppManager {
297305
for (const auto& app: appList) {
298306
if(app->background == false) // app is not in background
299307
{
300-
if (app->isRunning()) { // app is running
301-
app->luaInstance->loop();
302-
} 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
308+
if (app->isRunning())
303309
{
304-
app->kill();
310+
app->luaInstance->loop();
305311
}
306312
}
307313
}
308314

309315
// Update foreground app GUI
310316
if (!appStack.empty()) {
311-
const App* app = appStack.back();
317+
App* app = appStack.back();
312318

313319
if (app->luaInstance != nullptr) {
314320
app->luaInstance->lua_gui.update();
315321
}
322+
323+
if(app->luaInstance->lua_gui.mainWindow == nullptr) // app has no GUI
324+
{
325+
app->kill();
326+
}
316327
}
317328

318329
threadsync.unlock();
@@ -348,9 +359,6 @@ namespace AppManager {
348359

349360
// Kill the app
350361
app->kill();
351-
352-
// Remove app from stack
353-
appStack.pop_back();
354362
}
355363

356364
bool isAnyVisibleApp() {

lib/applications/src/app.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ namespace AppManager
3636
App(const std::string& name, const storage::Path& path, const storage::Path& manifest, bool auth);
3737

3838
/**
39-
* @param background Run in background
4039
* @param parameters List of parameters to send to the lua run function of the app
4140
*/
42-
void run(bool background, const std::vector<std::string> &parameters = {});
41+
void run(const std::vector<std::string> &parameters = {});
4342

4443
/**
4544
* @brief Wake up the app (if it was sleeping)

lib/gui/src/ElementBase.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ bool gui::ElementBase::update()
210210
if (widgetPressed != nullptr && widgetPressed != this)
211211
return false;
212212

213+
uint16_t resolution = 0;
214+
213215
bool isScreenTouched = graphics::isTouched();
214-
bool isWidgetTouched = isScreenTouched && (getAbsoluteX()-10 < touchX && touchX < getAbsoluteX() + getWidth() +10 &&
215-
getAbsoluteY()-10 < touchY && touchY < getAbsoluteY() + getHeight() +10);
216+
bool isWidgetTouched = isScreenTouched && (getAbsoluteX()-resolution < touchX && touchX < getAbsoluteX() + getWidth() +resolution &&
217+
getAbsoluteY()-resolution < touchY && touchY < getAbsoluteY() + getHeight() +resolution);
216218

217219
bool returnValue = false;
218220

lib/lua/src/lua_file.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ void LuaFile::load()
619619
lua.set_function("launch", sol::overload([&](std::string name, std::vector<std::string> arg)
620620
{
621621
try{
622-
AppManager::get(name)->run(false, arg);
622+
AppManager::get(name)->run(arg);
623623
}
624624
catch(std::runtime_error &e) {
625625
std::cerr << "Erreur: " << e.what() << std::endl;
@@ -633,7 +633,7 @@ void LuaFile::load()
633633
{
634634
try
635635
{
636-
AppManager::get(name)->run(false, {});
636+
AppManager::get(name)->run({});
637637
}
638638
catch (std::runtime_error &e)
639639
{

src/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ void mainLoop(void* data) {
5656
try {
5757
const std::shared_ptr<AppManager::App> oobeApp = AppManager::get(".oobe");
5858

59-
oobeApp->run(false);
59+
oobeApp->run();
6060
} catch (std::runtime_error& e) {
61-
std::cerr << "Lua error: " << e.what() << std::endl;
62-
guiManager.showErrorMessage(e.what());
61+
//std::cerr << "Lua error: " << e.what() << std::endl;
62+
//guiManager.showErrorMessage(e.what());
6363
//AppManager::appList[i].kill();
6464
}
6565
}
@@ -99,7 +99,7 @@ void mainLoop(void* data) {
9999

100100
// Launch the app
101101
try {
102-
app->run(app->background);
102+
app->run();
103103
} catch (std::runtime_error& e) {
104104
std::cerr << "Erreur: " << e.what() << std::endl;
105105
// Affichage du msg d'erreur
@@ -241,7 +241,7 @@ void setup()
241241
// gestion des appels entrants
242242
GSM::ExternalEvents::onIncommingCall = []()
243243
{
244-
eventHandlerApp.setTimeout(new Callback<>([](){AppManager::get(".receivecall")->run(false);}), 0);
244+
eventHandlerApp.setTimeout(new Callback<>([](){AppManager::get(".receivecall")->run();}), 0);
245245
};
246246

247247
// Gestion de la réception d'un message

storage/sys_apps/testbc/app.lua

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
function run()
22
print("run baground testbc app, no displayed: show conter to 10 and run settings app")
33
print(time)
4-
local counter = 0
4+
-- local counter = 0
55

6-
local function printCounter()
7-
counter = counter + 1
8-
print("Counter: " .. counter .. " sec")
9-
if(counter == 10) then
10-
launch("settings")
11-
end
12-
end
6+
-- local function printCounter()
7+
-- counter = counter + 1
8+
-- print("Counter: " .. counter .. " sec")
9+
-- if(counter == 10) then
10+
-- launch("settings")
11+
-- end
12+
-- end
1313

14-
time:setInterval(printCounter, 1000)
14+
-- time:setInterval(printCounter, 1000)
15+
16+
launch("testbc.sub1")
1517
end

storage/sys_apps/testbc/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"files",
55
"time"
66
],
7-
"background": true,
7+
"background": false,
88
"subdir": "sub"
99
}

storage/sys_apps/testbc/sub/.sub1/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"time"
66
],
77
"background": true,
8-
"autorun": true
8+
"autorun": false
99
}

0 commit comments

Comments
 (0)