diff --git a/ScreenPlay/src/screenplaymanager.cpp b/ScreenPlay/src/screenplaymanager.cpp index df9f6182..1ff179a2 100644 --- a/ScreenPlay/src/screenplaymanager.cpp +++ b/ScreenPlay/src/screenplaymanager.cpp @@ -154,6 +154,7 @@ void ScreenPlayManager::createWallpaper( m_settings->checkWallpaperVisible()); QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles); + QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestClose, this, &ScreenPlayManager::removeApp); m_screenPlayWallpapers.append(wallpaper); m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex); increaseActiveWallpaperCounter(); @@ -195,6 +196,7 @@ void ScreenPlayManager::createWidget( type); QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::requestSaveProfiles); + QObject::connect(widget.get(), &ScreenPlayWidget::requestClose, this, &ScreenPlayManager::removeApp); increaseActiveWidgetsCounter(); m_screenPlayWidgets.append(widget); } @@ -269,24 +271,7 @@ bool ScreenPlayManager::removeWallpaperAt(int index) { if (auto appID = m_monitorListModel->getAppIDByMonitorIndex(index)) { - emit requestSaveProfiles(); - - if (!closeWallpaper(*appID)) { - qWarning() << "Could not close socket. Abort!"; - return false; - } - m_monitorListModel->closeWallpaper(*appID); - - const QString appIDCopy = *appID; - if (!removeWallpaperByAppID(appIDCopy)) { - if (m_telemetry) { - m_telemetry->sendEvent("wallpaper", "error_removeWallpaperAt_removeWallpaperByAppID"); - } - qWarning() << "Could not remove Wallpaper " << appIDCopy << " from wallpaper list!"; - return false; - } - emit requestSaveProfiles(); - return true; + return removeApp(*appID); } if (m_telemetry) { m_telemetry->sendEvent("wallpaper", "error_removeWallpaperAt"); @@ -295,6 +280,28 @@ bool ScreenPlayManager::removeWallpaperAt(int index) return false; } +bool ScreenPlayManager::removeApp(const QString &appID) +{ + emit requestSaveProfiles(); + + if (!closeConnection(appID)) { + qWarning() << "Could not close socket. Abort!"; + return false; + } + m_monitorListModel->closeWallpaper(appID); + + const QString appIDCopy = appID; + if (!removeWallpaperByAppID(appIDCopy)) { + if (m_telemetry) { + m_telemetry->sendEvent("wallpaper", "error_removeWallpaperAt_removeWallpaperByAppID"); + } + qWarning() << "Could not remove Wallpaper " << appIDCopy << " from wallpaper list!"; + return false; + } + emit requestSaveProfiles(); + return true; +} + /*! \brief Request a spesific json profile to display in the active wallpaper popup on the right. */ @@ -401,10 +408,10 @@ void ScreenPlayManager::closeAllWidgets() /*! \brief Closes a connection by type. Used only by closeAllWidgets() and closeAllWallpapers() */ -void ScreenPlayManager::closeConntectionByType(const QStringList& list) +void ScreenPlayManager::closeConntectionByType(const QStringList& types) { for (auto& client : m_clients) { - if (list.contains(client->type(), Qt::CaseInsensitive)) { + if (types.contains(client->type(), Qt::CaseInsensitive)) { client->close(); m_clients.removeOne(client); } @@ -412,15 +419,14 @@ void ScreenPlayManager::closeConntectionByType(const QStringList& list) } /*! - \brief Closes a wallpaper by the given \a appID. + \brief Closes a Wallpaper or Widget connection by the given \a appID. */ -bool ScreenPlayManager::closeWallpaper(const QString& appID) +bool ScreenPlayManager::closeConnection(const QString& appID) { for (auto& client : m_clients) { if (client->appID() == appID) { client->close(); - m_clients.removeOne(client); - return true; + return m_clients.removeOne(client); } } return false; diff --git a/ScreenPlay/src/screenplaymanager.h b/ScreenPlay/src/screenplaymanager.h index 9af39b6b..68fe4ba9 100644 --- a/ScreenPlay/src/screenplaymanager.h +++ b/ScreenPlay/src/screenplaymanager.h @@ -100,7 +100,8 @@ private slots: public slots: // moc needs full enum namespace info see QTBUG-58454 - void createWallpaper(const ScreenPlay::InstalledType::InstalledType type, + void createWallpaper( + const ScreenPlay::InstalledType::InstalledType type, const ScreenPlay::FillMode::FillMode fillMode, const QString& absoluteStoragePath, const QString& previewImage, @@ -122,18 +123,19 @@ public slots: void removeAllWallpapers(); void removeAllWidgets(); bool removeWallpaperAt(const int index); + bool removeApp(const QString& appID); void requestProjectSettingsAtMonitorIndex(const int index); - void setWallpaperValueAtMonitorIndex(const int index, const QString& key, const QString &value); + void setWallpaperValueAtMonitorIndex(const int index, const QString& key, const QString& value); void setAllWallpaperValue(const QString& key, const QString& value); ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID) const; void newConnection(); void closeAllWallpapers(); void closeAllWidgets(); - void closeConntectionByType(const QStringList& list); - bool closeWallpaper(const QString& appID); - void setWallpaperValue(const QString& appID, const QString& key, const QString &value); + void closeConntectionByType(const QStringList& types); + bool closeConnection(const QString& appID); + void setWallpaperValue(const QString& appID, const QString& key, const QString& value); void setActiveWallpaperCounter(int activeWallpaperCounter) { diff --git a/ScreenPlay/src/screenplaywallpaper.cpp b/ScreenPlay/src/screenplaywallpaper.cpp index c20e57cd..ebb38083 100644 --- a/ScreenPlay/src/screenplaywallpaper.cpp +++ b/ScreenPlay/src/screenplaywallpaper.cpp @@ -178,7 +178,8 @@ void ScreenPlayWallpaper::setSDKConnection(const std::shared_ptr& }); QObject::connect(&m_pingAliveTimer, &QTimer::timeout, this, [this]() { - qInfo() << "For " << m_pingAliveTimer.interval() << "ms no alive signal received. This means the wallpaper is dead and likely crashed!"; + qInfo() << "For " << m_pingAliveTimer.interval() << "ms no alive signal received. This means the Wallpaper is dead and likely crashed!"; + emit requestClose(m_appID); }); m_pingAliveTimer.start(16000); } diff --git a/ScreenPlay/src/screenplaywallpaper.h b/ScreenPlay/src/screenplaywallpaper.h index e0ad2ab1..bbab12e3 100644 --- a/ScreenPlay/src/screenplaywallpaper.h +++ b/ScreenPlay/src/screenplaywallpaper.h @@ -67,8 +67,10 @@ class ScreenPlayWallpaper : public QObject { Q_PROPERTY(InstalledType::InstalledType type READ type WRITE setType NOTIFY typeChanged) public: - ScreenPlayWallpaper(){} - explicit ScreenPlayWallpaper(const QVector& screenNumber, + ScreenPlayWallpaper() { } + + explicit ScreenPlayWallpaper( + const QVector& screenNumber, const std::shared_ptr& globalVariables, const QString& appID, const QString& absolutePath, @@ -80,7 +82,8 @@ public: const bool checkWallpaperVisible, QObject* parent = nullptr); - void replace(const QString& absolutePath, + void replace( + const QString& absolutePath, const QString& previewImage, const QString& file, const float volume, @@ -158,13 +161,15 @@ signals: void profileJsonObjectChanged(QJsonObject profileJsonObject); void volumeChanged(float volume); void isLoopingChanged(bool isLooping); - void requestSave(); void playbackRateChanged(float playbackRate); + void requestSave(); + void requestClose(const QString& appID); + public slots: void processExit(int exitCode, QProcess::ExitStatus exitStatus); void processError(QProcess::ProcessError error); - void setWallpaperValue(const QString& key, const QString &value, const bool save = false); + void setWallpaperValue(const QString& key, const QString& value, const bool save = false); void setScreenNumber(QVector screenNumber) { diff --git a/ScreenPlay/src/screenplaywidget.cpp b/ScreenPlay/src/screenplaywidget.cpp index 53e9f59e..987d5992 100644 --- a/ScreenPlay/src/screenplaywidget.cpp +++ b/ScreenPlay/src/screenplaywidget.cpp @@ -83,7 +83,8 @@ void ScreenPlayWidget::setSDKConnection(const std::shared_ptr& co }); QObject::connect(&m_pingAliveTimer, &QTimer::timeout, this, [this]() { - qInfo() << "For " << m_pingAliveTimer.interval() << "ms no alive signal received. This means the wallpaper is dead and likely crashed!"; + qInfo() << "For " << m_pingAliveTimer.interval() << "ms no alive signal received. This means the Widget is dead and likely crashed!"; + emit requestClose(m_appID); }); m_pingAliveTimer.start(16000); } diff --git a/ScreenPlay/src/screenplaywidget.h b/ScreenPlay/src/screenplaywidget.h index e3d7212a..219b29e2 100644 --- a/ScreenPlay/src/screenplaywidget.h +++ b/ScreenPlay/src/screenplaywidget.h @@ -155,7 +155,9 @@ signals: void appIDChanged(QString appID); void typeChanged(InstalledType::InstalledType type); void absolutePathChanged(QString absolutePath); + void requestSave(); + void requestClose(const QString& appID); private: const std::shared_ptr m_globalVariables;