@@ -8,10 +8,9 @@ namespace AppManager {
8
8
: name(name), fullName(name), path(path), manifest(manifest),
9
9
auth (auth),
10
10
luaInstance(nullptr ), app_state(NOT_RUNNING), background(false ) {
11
- std::cout << " App: \" " << name << " \" \" " << fullName << " \" " << std::endl;
12
11
}
13
12
14
- void App::run (const bool background, const std::vector<std::string>& parameters) {
13
+ void App::run (const std::vector<std::string>& parameters) {
15
14
if (!auth) {
16
15
throw libsystem::exceptions::RuntimeError (" App is not authorized to run" );
17
16
}
@@ -43,7 +42,7 @@ namespace AppManager {
43
42
}
44
43
45
44
bool App::isRunning () const {
46
- return app_state == RUNNING || app_state == RUNNING_BACKGROUND ;
45
+ return this -> luaInstance != nullptr ;
47
46
}
48
47
49
48
bool App::isLoaded () const {
@@ -62,6 +61,14 @@ namespace AppManager {
62
61
luaInstance->stop ();
63
62
luaInstance.reset (); // delete luaInstance
64
63
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
+
65
72
app_state = NOT_RUNNING;
66
73
67
74
std::cout << " App killed" << std::endl;
@@ -174,7 +181,7 @@ namespace AppManager {
174
181
void askGui (const LuaFile* lua) {
175
182
App* app = lua->app ;
176
183
177
- if (lua->lua_gui .mainWindow == nullptr ) {
184
+ /* if (lua->lua_gui.mainWindow == nullptr) {
178
185
for (auto it = appStack.begin(); it != appStack.end(); ++it) {
179
186
if (*it == app) {
180
187
app->app_state = App::AppState::NOT_RUNNING;
@@ -184,7 +191,7 @@ namespace AppManager {
184
191
}
185
192
186
193
return;
187
- }
194
+ }*/
188
195
189
196
// if (appStack.empty() || appStack.back() != app) {
190
197
// appStack.push_back(app);
@@ -198,11 +205,11 @@ namespace AppManager {
198
205
std::string allowedFiles = stream.read ();
199
206
stream.close ();
200
207
201
- libsystem::log (" auth.list : " + allowedFiles);
208
+ // libsystem::log("auth.list : " + allowedFiles);
202
209
203
210
for (auto dir: dirs) {
204
211
auto appPath = storage::Path (directory) / dir;
205
- libsystem::log (" Loading app at \" " + appPath.str () + " \" ." );
212
+ // libsystem::log("Loading app at \"" + appPath.str() + "\".");
206
213
207
214
auto manifestPath = storage::Path (directory) / dir / " manifest.json" ;
208
215
@@ -211,7 +218,7 @@ namespace AppManager {
211
218
manifestStream.close ();
212
219
213
220
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;
215
222
continue ;
216
223
}
217
224
@@ -242,7 +249,8 @@ namespace AppManager {
242
249
);
243
250
}
244
251
245
- app->fullName = prefix.size () ? (prefix + " ." + dir) : (dir);
252
+ app->fullName = prefix.size () ? (prefix + dir) : (dir);
253
+ libsystem::log (" Loading app \" " + app->fullName + " \" ." );
246
254
247
255
if (!dir.empty () && dir[0 ] == ' .' ) {
248
256
app->visible = false ;
@@ -260,12 +268,6 @@ namespace AppManager {
260
268
std::cout << " loading app in the background" << std::endl;
261
269
}
262
270
263
- if (manifest[" autorun" ].is_boolean ()) {
264
- if (manifest[" autorun" ] && app->background ) {
265
- app.get ()->run (true );
266
- }
267
- }
268
-
269
271
if (manifest[" subdir" ].is_string ()) // todo, restrict only for subdirs
270
272
{
271
273
if ((app.get ()->path / " ../" / manifest[" subdir" ]).exists ())
@@ -275,8 +277,14 @@ namespace AppManager {
275
277
}
276
278
277
279
// Add app to list
278
- libsystem::log (" Loaded app : " + app->toString () + " ." );
280
+ // libsystem::log("Loaded app : " + app->toString() + ".");
279
281
appList.push_back (app);
282
+
283
+ if (manifest[" autorun" ].is_boolean ()) {
284
+ if (manifest[" autorun" ] && app->background ) {
285
+ app.get ()->run ();
286
+ }
287
+ }
280
288
}
281
289
}
282
290
@@ -297,22 +305,25 @@ namespace AppManager {
297
305
for (const auto & app: appList) {
298
306
if (app->background == false ) // app is not in background
299
307
{
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 ())
303
309
{
304
- app->kill ();
310
+ app->luaInstance -> loop ();
305
311
}
306
312
}
307
313
}
308
314
309
315
// Update foreground app GUI
310
316
if (!appStack.empty ()) {
311
- const App* app = appStack.back ();
317
+ App* app = appStack.back ();
312
318
313
319
if (app->luaInstance != nullptr ) {
314
320
app->luaInstance ->lua_gui .update ();
315
321
}
322
+
323
+ if (app->luaInstance ->lua_gui .mainWindow == nullptr ) // app has no GUI
324
+ {
325
+ app->kill ();
326
+ }
316
327
}
317
328
318
329
threadsync.unlock ();
@@ -348,9 +359,6 @@ namespace AppManager {
348
359
349
360
// Kill the app
350
361
app->kill ();
351
-
352
- // Remove app from stack
353
- appStack.pop_back ();
354
362
}
355
363
356
364
bool isAnyVisibleApp () {
0 commit comments