1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 18:52:30 +01:00

Change creation of wallpaper return false on failure

Move start of wallpaper and widgets into separate function.
This was needed because the error signal would not be
connected by the time of object creation.
This commit is contained in:
Elias Steurer 2021-04-16 10:33:35 +02:00
parent a5e07f5694
commit c4ec91bd13
9 changed files with 86 additions and 41 deletions

View File

@ -98,14 +98,12 @@ Popup {
if (installedType === InstalledType.VideoWallpaper) { if (installedType === InstalledType.VideoWallpaper) {
videoControlWrapper.state = "visible" videoControlWrapper.state = "visible"
customPropertiesGridView.visible = false customPropertiesGridView.visible = false
const wallpaper = ScreenPlay.screenPlayManager.getWallpaperByAppID( const wallpaper = ScreenPlay.screenPlayManager.getWallpaperByAppID(appID)
appID)
videoControlWrapper.wallpaper = wallpaper videoControlWrapper.wallpaper = wallpaper
} else { } else {
videoControlWrapper.state = "hidden" videoControlWrapper.state = "hidden"
customPropertiesGridView.visible = true customPropertiesGridView.visible = true
ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex( ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex(index)
index)
} }
activeMonitorIndex = index activeMonitorIndex = index
@ -135,8 +133,10 @@ Popup {
font.family: ScreenPlay.settings.font font.family: ScreenPlay.settings.font
enabled: monitorSelection.activeMonitors.length == 1 enabled: monitorSelection.activeMonitors.length == 1
onClicked: { onClicked: {
ScreenPlay.screenPlayManager.removeWallpaperAt( if (!ScreenPlay.screenPlayManager.removeWallpaperAt(
monitorSelection.activeMonitors[0]) monitorSelection.activeMonitors[0])) {
print("Unable to close singel wallpaper")
}
} }
} }
Button { Button {
@ -149,21 +149,26 @@ Popup {
font.family: ScreenPlay.settings.font font.family: ScreenPlay.settings.font
enabled: ScreenPlay.screenPlayManager.activeWallpaperCounter > 0 enabled: ScreenPlay.screenPlayManager.activeWallpaperCounter > 0
onClicked: { onClicked: {
ScreenPlay.screenPlayManager.removeAllWallpapers() if (!ScreenPlay.screenPlayManager.removeAllWallpapers()) {
print("Unable to close all wallpaper!")
}
monitors.close() monitors.close()
} }
} }
Button { Button {
id: btnRemoveAllWidgets id: btnRemoveAllWidgets
text: qsTr("Remove ") text: qsTr("Remove ")
+ ScreenPlay.screenPlayManager.activeWidgetsCounter + " " + qsTr( + ScreenPlay.screenPlayManager.activeWidgetsCounter + " " + qsTr("Widgets")
"Widgets")
Material.background: Material.accent Material.background: Material.accent
Material.foreground: "white" Material.foreground: "white"
font.family: ScreenPlay.settings.font font.family: ScreenPlay.settings.font
enabled: ScreenPlay.screenPlayManager.activeWidgetsCounter > 0 enabled: ScreenPlay.screenPlayManager.activeWidgetsCounter > 0
onClicked: { onClicked: {
ScreenPlay.screenPlayManager.removeAllWidgets() if (!ScreenPlay.screenPlayManager.removeAllWidgets()) {
print("Unable to close all widgets!")
}
monitors.close() monitors.close()
} }
} }

View File

@ -101,7 +101,7 @@ void ScreenPlayManager::init(
a \a fillMode, a \a type (htmlWallpaper, qmlWallpaper etc.), a \a saveToProfilesConfigFile bool only set to flase a \a fillMode, a \a type (htmlWallpaper, qmlWallpaper etc.), a \a saveToProfilesConfigFile bool only set to flase
if we call the method when using via the settings on startup to skip a unnecessary save. if we call the method when using via the settings on startup to skip a unnecessary save.
*/ */
void ScreenPlayManager::createWallpaper( bool ScreenPlayManager::createWallpaper(
const InstalledType::InstalledType type, const InstalledType::InstalledType type,
const FillMode::FillMode fillMode, const FillMode::FillMode fillMode,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
@ -148,7 +148,7 @@ void ScreenPlayManager::createWallpaper(
m_settings->checkWallpaperVisible()); m_settings->checkWallpaperVisible());
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex); m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
return; return true;
} }
} }
i++; i++;
@ -172,15 +172,19 @@ void ScreenPlayManager::createWallpaper(
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles); QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestClose, this, &ScreenPlayManager::removeApp); QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestClose, this, &ScreenPlayManager::removeApp);
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::error, this, &ScreenPlayManager::displayErrorPopup); QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::error, this, &ScreenPlayManager::displayErrorPopup);
if (!wallpaper->start()) {
return false;
}
m_screenPlayWallpapers.append(wallpaper); m_screenPlayWallpapers.append(wallpaper);
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex); m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
increaseActiveWallpaperCounter(); increaseActiveWallpaperCounter();
return true;
} }
/*! /*!
\brief Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path). \brief Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path).
*/ */
void ScreenPlayManager::createWidget( bool ScreenPlayManager::createWidget(
const InstalledType::InstalledType type, const InstalledType::InstalledType type,
const QPoint& position, const QPoint& position,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
@ -200,7 +204,7 @@ void ScreenPlayManager::createWidget(
if (path.isEmpty()) { if (path.isEmpty()) {
qWarning() << "Path is empty, Abort! String: " << absoluteStoragePath; qWarning() << "Path is empty, Abort! String: " << absoluteStoragePath;
return; return false;
} }
auto widget = std::make_shared<ScreenPlayWidget>( auto widget = std::make_shared<ScreenPlayWidget>(
@ -215,8 +219,12 @@ void ScreenPlayManager::createWidget(
QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::requestSaveProfiles); QObject::connect(widget.get(), &ScreenPlayWidget::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
QObject::connect(widget.get(), &ScreenPlayWidget::requestClose, this, &ScreenPlayManager::removeApp); QObject::connect(widget.get(), &ScreenPlayWidget::requestClose, this, &ScreenPlayManager::removeApp);
QObject::connect(widget.get(), &ScreenPlayWidget::error, this, &ScreenPlayManager::displayErrorPopup); QObject::connect(widget.get(), &ScreenPlayWidget::error, this, &ScreenPlayManager::displayErrorPopup);
if (!widget->start()) {
return false;
}
increaseActiveWidgetsCounter(); increaseActiveWidgetsCounter();
m_screenPlayWidgets.append(widget); m_screenPlayWidgets.append(widget);
return true;
} }
/*! /*!
@ -414,13 +422,18 @@ void ScreenPlayManager::newConnection()
\li godotWallpaper \li godotWallpaper
\endlist \endlist
*/ */
void ScreenPlayManager::closeAllWallpapers() bool ScreenPlayManager::closeAllWallpapers()
{ {
if (m_screenPlayWallpapers.empty() && m_activeWallpaperCounter == 0) if (m_screenPlayWallpapers.empty() && m_activeWallpaperCounter == 0) {
return; qWarning() << "Cannot close connection on empty client list!";
return true;
}
closeConntectionByType(ScreenPlayUtil::getAvailableWallpaper()); if (!closeConntectionByType(ScreenPlayUtil::getAvailableWallpaper())) {
return false;
}
setActiveWallpaperCounter(0); setActiveWallpaperCounter(0);
return true;
} }
/*! /*!
@ -431,13 +444,18 @@ void ScreenPlayManager::closeAllWallpapers()
\li standaloneWidget \li standaloneWidget
\endlist \endlist
*/ */
void ScreenPlayManager::closeAllWidgets() bool ScreenPlayManager::closeAllWidgets()
{ {
if (m_screenPlayWidgets.empty() && m_activeWidgetsCounter == 0) if (m_screenPlayWidgets.empty() && m_activeWidgetsCounter == 0) {
return; qWarning() << "Cannot close connection on empty client list!";
return true;
}
closeConntectionByType(ScreenPlayUtil::getAvailableWidgets()); if (!closeConntectionByType(ScreenPlayUtil::getAvailableWidgets())) {
return false;
}
setActiveWidgetsCounter(0); setActiveWidgetsCounter(0);
return true;
} }
/*! /*!
@ -445,13 +463,18 @@ void ScreenPlayManager::closeAllWidgets()
*/ */
bool ScreenPlayManager::closeConntectionByType(const QStringList& types) bool ScreenPlayManager::closeConntectionByType(const QStringList& types)
{ {
if (m_clients.isEmpty()) if (m_clients.isEmpty()) {
qWarning() << "Cannot close connection on empty client list!";
return true; return true;
}
for (auto& client : m_clients) { for (auto& client : m_clients) {
if (types.contains(client->type(), Qt::CaseInsensitive)) { if (types.contains(client->type(), Qt::CaseInsensitive)) {
client->close(); if (client->close()) {
return false;
}
if (!m_clients.removeOne(client)) { if (!m_clients.removeOne(client)) {
qWarning() << "Cannot close client";
return false; return false;
} }
} }

View File

@ -94,7 +94,7 @@ private slots:
public slots: public slots:
// moc needs full enum namespace info see QTBUG-58454 // moc needs full enum namespace info see QTBUG-58454
void createWallpaper( bool createWallpaper(
const ScreenPlay::InstalledType::InstalledType type, const ScreenPlay::InstalledType::InstalledType type,
const ScreenPlay::FillMode::FillMode fillMode, const ScreenPlay::FillMode::FillMode fillMode,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
@ -106,7 +106,7 @@ public slots:
const QJsonObject& properties, const QJsonObject& properties,
const bool saveToProfilesConfigFile); const bool saveToProfilesConfigFile);
void createWidget( bool createWidget(
const ScreenPlay::InstalledType::InstalledType type, const ScreenPlay::InstalledType::InstalledType type,
const QPoint& position, const QPoint& position,
const QString& absoluteStoragePath, const QString& absoluteStoragePath,
@ -125,8 +125,8 @@ public slots:
ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID) const; ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID) const;
void newConnection(); void newConnection();
void closeAllWallpapers(); bool closeAllWallpapers();
void closeAllWidgets(); bool closeAllWidgets();
bool closeConntectionByType(const QStringList& types); bool closeConntectionByType(const QStringList& types);
bool closeConnection(const QString& appID); bool closeConnection(const QString& appID);
void setWallpaperValue(const QString& appID, const QString& key, const QString& value); void setWallpaperValue(const QString& appID, const QString& key, const QString& value);

View File

@ -77,7 +77,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
tmpScreenNumber = QString::number(m_screenNumber.first()); tmpScreenNumber = QString::number(m_screenNumber.first());
} }
const QStringList proArgs { m_appArgumentsList = QStringList {
tmpScreenNumber, tmpScreenNumber,
m_absolutePath, m_absolutePath,
QString { "appID=" + m_appID }, QString { "appID=" + m_appID },
@ -88,8 +88,11 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
// Fixes issue 84 media key overlay // Fixes issue 84 media key overlay
" --disable-features=HardwareMediaKeyHandling" " --disable-features=HardwareMediaKeyHandling"
}; };
}
m_process.setArguments(proArgs); bool ScreenPlayWallpaper::start()
{
m_process.setArguments(m_appArgumentsList);
m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString()); m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString());
// We must start detatched otherwise we would instantly close the process // We must start detatched otherwise we would instantly close the process
// and would loose the animted fade-out and the background refresh needed // and would loose the animted fade-out and the background refresh needed
@ -97,10 +100,9 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
const bool success = m_process.startDetached(); const bool success = m_process.startDetached();
qInfo() << "Starting ScreenPlayWallpaper detached: " << (success ? "success" : "failed!"); qInfo() << "Starting ScreenPlayWallpaper detached: " << (success ? "success" : "failed!");
if (!success) { if (!success) {
qInfo() << m_process.errorString();
emit requestClose(m_appID);
emit error(QString("Could not start Wallpaper: " + m_process.errorString())); emit error(QString("Could not start Wallpaper: " + m_process.errorString()));
} }
return success;
} }
/*! /*!

View File

@ -82,6 +82,8 @@ public:
const bool checkWallpaperVisible, const bool checkWallpaperVisible,
QObject* parent = nullptr); QObject* parent = nullptr);
bool start();
void replace( void replace(
const QString& absolutePath, const QString& absolutePath,
const QString& previewImage, const QString& previewImage,
@ -249,5 +251,6 @@ private:
bool m_isLooping { true }; bool m_isLooping { true };
float m_playbackRate { 1.0f }; float m_playbackRate { 1.0f };
QTimer m_pingAliveTimer; QTimer m_pingAliveTimer;
QStringList m_appArgumentsList;
}; };
} }

View File

@ -48,15 +48,18 @@ ScreenPlayWidget::ScreenPlayWidget(
m_projectSettingsListModel.init(type, projectSettingsListModelProperties); m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
} }
const QStringList proArgs { m_appArgumentsList = QStringList {
m_absolutePath, m_absolutePath,
QString { "appID=" + m_appID }, QString { "appID=" + m_appID },
QVariant::fromValue(m_type).toString(), QVariant::fromValue(m_type).toString(),
QString::number(m_position.x()), QString::number(m_position.x()),
QString::number(m_position.y()), QString::number(m_position.y()),
}; };
}
m_process.setArguments(proArgs); bool ScreenPlayWidget::start()
{
m_process.setArguments(m_appArgumentsList);
m_process.setProgram(m_globalVariables->widgetExecutablePath().path()); m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) { QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
@ -65,10 +68,9 @@ ScreenPlayWidget::ScreenPlayWidget(
const bool success = m_process.startDetached(); const bool success = m_process.startDetached();
qInfo() << "Starting ScreenPlayWWidget detached: " << (success ? "success" : "failed!"); qInfo() << "Starting ScreenPlayWWidget detached: " << (success ? "success" : "failed!");
if (!success) { if (!success) {
qInfo() << m_process.errorString();
emit requestClose(m_appID);
emit error(QString("Could not start Widget: " + m_process.errorString())); emit error(QString("Could not start Widget: " + m_process.errorString()));
} }
return success;
} }
/*! /*!

View File

@ -68,6 +68,8 @@ public:
const QString& previewImage, const QJsonObject& properties, const QString& previewImage, const QJsonObject& properties,
const InstalledType::InstalledType type); const InstalledType::InstalledType type);
bool start();
ScreenPlayWidget() { } ScreenPlayWidget() { }
QString previewImage() const { return m_previewImage; } QString previewImage() const { return m_previewImage; }
@ -155,5 +157,6 @@ private:
InstalledType::InstalledType m_type; InstalledType::InstalledType m_type;
QString m_absolutePath; QString m_absolutePath;
QTimer m_pingAliveTimer; QTimer m_pingAliveTimer;
QStringList m_appArgumentsList;
}; };
} }

View File

@ -98,27 +98,34 @@ void ScreenPlay::SDKConnection::sendMessage(const QByteArray& message)
\brief Closes the socket connection. Before it explicitly sends a quit command to make sure \brief Closes the socket connection. Before it explicitly sends a quit command to make sure
the wallpaper closes (fast). This also requestDecreaseWidgetCount() because Widgets. the wallpaper closes (fast). This also requestDecreaseWidgetCount() because Widgets.
*/ */
void ScreenPlay::SDKConnection::close() bool ScreenPlay::SDKConnection::close()
{ {
qInfo() << "Close " << m_type << m_appID; qInfo() << "Close " << m_type << m_appID << m_socket->state();
QJsonObject obj; QJsonObject obj;
obj.insert("command", QJsonValue("quit")); obj.insert("command", QJsonValue("quit"));
QByteArray command = QJsonDocument(obj).toJson(); QByteArray command = QJsonDocument(obj).toJson();
m_socket->write(command); m_socket->write(command);
m_socket->waitForBytesWritten(); if (!m_socket->waitForBytesWritten()) {
qWarning("Faild to send quit command to app");
return false;
}
if (m_socket->state() == QLocalSocket::ConnectedState) { if (m_socket->state() == QLocalSocket::ConnectedState) {
m_socket->disconnectFromServer(); m_socket->disconnectFromServer();
m_socket->close(); m_socket->close();
qDebug() << "### Destroy APPID:\t " << m_appID << " State: " << m_socket->state(); qInfo() << "### Destroy APPID:\t " << m_appID << " State: " << m_socket->state();
} else {
qWarning() << "Cannot disconnect app " << m_appID << " with the state:" << m_socket->state();
return false;
} }
if (m_type.contains("widget", Qt::CaseInsensitive)) { if (m_type.contains("widget", Qt::CaseInsensitive)) {
emit requestDecreaseWidgetCount(); emit requestDecreaseWidgetCount();
} }
return true;
} }
} }

View File

@ -94,7 +94,7 @@ signals:
public slots: public slots:
void readyRead(); void readyRead();
void sendMessage(const QByteArray& message); void sendMessage(const QByteArray& message);
void close(); bool close();
void setAppID(QString appID) void setAppID(QString appID)
{ {