From 953908831e22a03292006c3af70d0124219846f0 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Wed, 6 Mar 2024 22:13:45 -0600 Subject: [PATCH] Fix notification bug, switch to beta testing --- debian/changelog | 8 ++++++++ src/main.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 965af27..9a0774f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +lubuntu-update-notifier (1.0.0~beta1) noble; urgency=medium + + * Change from alpha to beta testing phase, this has been tested for a while + and looks pretty stable so far. + * Wait to start until lxqt-notificationd is present. (LP: #2056379) + + -- Aaron Rainbolt Thu, 07 Mar 2024 04:06:13 +0000 + lubuntu-update-notifier (1.0.0~alpha4) noble; urgency=medium * Fix infinite loop when no eligible new release is available. diff --git a/src/main.cpp b/src/main.cpp index 0eb42e1..e2862bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,28 @@ #include #include #include +#include #include +/* + * Detects if at least `count` processes that match `procName` are running. + */ +bool detectProc(QString procName, int count) +{ + QProcess procDetector; + procDetector.setProgram("/usr/bin/bash"); + procDetector.setArguments(QStringList() << "-c" << "ps axo comm | grep " + procName); + procDetector.start(); + procDetector.waitForFinished(); + QString procDetectResult = procDetector.readAllStandardOutput(); + procDetectResult = procDetectResult.trimmed(); + QStringList procDetectResultList = procDetectResult.split('\n'); + if (procDetectResultList.count() >= count) { + return true; + } + return false; +} + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -28,22 +48,30 @@ int main(int argc, char *argv[]) * /dev/shm/lubuntu-update/lubuntu-update-show-win and exit. This will * trigger the existing process to pop up a window. */ - - QProcess procDetector; - procDetector.setProgram("/usr/bin/bash"); - procDetector.setArguments(QStringList() << "-c" << "ps axo comm | grep lubuntu-update"); - procDetector.start(); - procDetector.waitForFinished(); - QString procDetectResult = procDetector.readAllStandardOutput(); - procDetectResult = procDetectResult.trimmed(); - QStringList procDetectResultList = procDetectResult.split('\n'); - if (procDetectResultList.count() > 1) { + if (detectProc("lubuntu-update", 2)) { QFile flagFile("/dev/shm/lubuntu-update/lubuntu-update-show-win"); flagFile.open(QFile::WriteOnly); flagFile.close(); return 0; } + /* + * Wait to run until lxqt-notificationd is running. This avoids a bug that + * causes notifications to show up in the entirely wrong spot. If it takes + * longer than about 30 seconds to show up, we continue on without it for + * the sake of getting security updates. + */ + for (int i = 0;i < 30;i++) { + // "lxqt-notificati" is intentionally truncated here since that's how it shows up in the output of `ps axo comm`. + if (detectProc("lxqt-notificati", 1)) { + // Wait for it to initialize fully - 3 seconds should be way more than enough + QThread::sleep(3); + break; + } else { + QThread::sleep(1); + } + } + // Don't want the updater to stop just because the user closed it :P a.setQuitOnLastWindowClosed(false);