From 486cefe14e190553789ece9df822cb69f7fd62af Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Mon, 21 Sep 2020 22:30:58 -0600 Subject: [PATCH] Fix backgrounding and add code to autostart applications --- applications/system-service/application.cpp | 8 +++++--- applications/system-service/application.h | 3 ++- applications/system-service/appsapi.h | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/applications/system-service/application.cpp b/applications/system-service/application.cpp index 635686f34..03affe6f6 100644 --- a/applications/system-service/application.cpp +++ b/applications/system-service/application.cpp @@ -42,7 +42,7 @@ void Application::pause(bool startIfNone){ timer.restart(); delayUpTo(1000); api->disconnectSignals(this, 2); - if(!timer.isValid()){ + if(timer.isValid()){ qDebug() << "Application took too long to background" << name(); kill(m_process->processId(), SIGSTOP); }else{ @@ -81,8 +81,10 @@ void Application::resume(){ kill(m_process->processId(), SIGUSR1); delayUpTo(1000); api->disconnectSignals(this, 1); - // No need to fall through, we've just assumed it continued - qDebug() << "Warning: application took too long to forground" << name(); + if(timer.isValid()){ + // No need to fall through, we've just assumed it continued + qDebug() << "Warning: application took too long to forground" << name(); + } m_backgrounded = false; break; case AppsAPI::Foreground: diff --git a/applications/system-service/application.h b/applications/system-service/application.h index 2c6f8ddfc..7dad81964 100644 --- a/applications/system-service/application.h +++ b/applications/system-service/application.h @@ -259,7 +259,8 @@ private slots: return instance; } void delayUpTo(int milliseconds){ - timer.restart(); + timer.invalidate(); + timer.start(); while(timer.isValid() && !timer.hasExpired(milliseconds)){ QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } diff --git a/applications/system-service/appsapi.h b/applications/system-service/appsapi.h index 398d077f9..cc046eb15 100644 --- a/applications/system-service/appsapi.h +++ b/applications/system-service/appsapi.h @@ -111,6 +111,14 @@ class AppsAPI : public APIBase { path = app->qPath(); } m_startupApplication = path; + for(auto app : applications){ + if(app->autoStart()){ + app->launch(); + if(app->type() == Backgroundable){ + app->pause(); + } + } + } app->launch(); } ~AppsAPI() {