mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-26 04:33:06 +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:
parent
a5e07f5694
commit
c4ec91bd13
@ -98,14 +98,12 @@ Popup {
|
||||
if (installedType === InstalledType.VideoWallpaper) {
|
||||
videoControlWrapper.state = "visible"
|
||||
customPropertiesGridView.visible = false
|
||||
const wallpaper = ScreenPlay.screenPlayManager.getWallpaperByAppID(
|
||||
appID)
|
||||
const wallpaper = ScreenPlay.screenPlayManager.getWallpaperByAppID(appID)
|
||||
videoControlWrapper.wallpaper = wallpaper
|
||||
} else {
|
||||
videoControlWrapper.state = "hidden"
|
||||
customPropertiesGridView.visible = true
|
||||
ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex(
|
||||
index)
|
||||
ScreenPlay.screenPlayManager.requestProjectSettingsAtMonitorIndex(index)
|
||||
}
|
||||
|
||||
activeMonitorIndex = index
|
||||
@ -135,8 +133,10 @@ Popup {
|
||||
font.family: ScreenPlay.settings.font
|
||||
enabled: monitorSelection.activeMonitors.length == 1
|
||||
onClicked: {
|
||||
ScreenPlay.screenPlayManager.removeWallpaperAt(
|
||||
monitorSelection.activeMonitors[0])
|
||||
if (!ScreenPlay.screenPlayManager.removeWallpaperAt(
|
||||
monitorSelection.activeMonitors[0])) {
|
||||
print("Unable to close singel wallpaper")
|
||||
}
|
||||
}
|
||||
}
|
||||
Button {
|
||||
@ -149,21 +149,26 @@ Popup {
|
||||
font.family: ScreenPlay.settings.font
|
||||
enabled: ScreenPlay.screenPlayManager.activeWallpaperCounter > 0
|
||||
onClicked: {
|
||||
ScreenPlay.screenPlayManager.removeAllWallpapers()
|
||||
if (!ScreenPlay.screenPlayManager.removeAllWallpapers()) {
|
||||
print("Unable to close all wallpaper!")
|
||||
}
|
||||
|
||||
monitors.close()
|
||||
}
|
||||
}
|
||||
Button {
|
||||
id: btnRemoveAllWidgets
|
||||
text: qsTr("Remove ")
|
||||
+ ScreenPlay.screenPlayManager.activeWidgetsCounter + " " + qsTr(
|
||||
"Widgets")
|
||||
+ ScreenPlay.screenPlayManager.activeWidgetsCounter + " " + qsTr("Widgets")
|
||||
Material.background: Material.accent
|
||||
Material.foreground: "white"
|
||||
font.family: ScreenPlay.settings.font
|
||||
enabled: ScreenPlay.screenPlayManager.activeWidgetsCounter > 0
|
||||
onClicked: {
|
||||
ScreenPlay.screenPlayManager.removeAllWidgets()
|
||||
if (!ScreenPlay.screenPlayManager.removeAllWidgets()) {
|
||||
print("Unable to close all widgets!")
|
||||
}
|
||||
|
||||
monitors.close()
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ void ScreenPlayManager::init(
|
||||
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.
|
||||
*/
|
||||
void ScreenPlayManager::createWallpaper(
|
||||
bool ScreenPlayManager::createWallpaper(
|
||||
const InstalledType::InstalledType type,
|
||||
const FillMode::FillMode fillMode,
|
||||
const QString& absoluteStoragePath,
|
||||
@ -148,7 +148,7 @@ void ScreenPlayManager::createWallpaper(
|
||||
m_settings->checkWallpaperVisible());
|
||||
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
@ -172,15 +172,19 @@ void ScreenPlayManager::createWallpaper(
|
||||
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestSave, this, &ScreenPlayManager::requestSaveProfiles);
|
||||
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::requestClose, this, &ScreenPlayManager::removeApp);
|
||||
QObject::connect(wallpaper.get(), &ScreenPlayWallpaper::error, this, &ScreenPlayManager::displayErrorPopup);
|
||||
if (!wallpaper->start()) {
|
||||
return false;
|
||||
}
|
||||
m_screenPlayWallpapers.append(wallpaper);
|
||||
m_monitorListModel->setWallpaperActiveMonitor(wallpaper, monitorIndex);
|
||||
increaseActiveWallpaperCounter();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\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 QPoint& position,
|
||||
const QString& absoluteStoragePath,
|
||||
@ -200,7 +204,7 @@ void ScreenPlayManager::createWidget(
|
||||
|
||||
if (path.isEmpty()) {
|
||||
qWarning() << "Path is empty, Abort! String: " << absoluteStoragePath;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
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::requestClose, this, &ScreenPlayManager::removeApp);
|
||||
QObject::connect(widget.get(), &ScreenPlayWidget::error, this, &ScreenPlayManager::displayErrorPopup);
|
||||
if (!widget->start()) {
|
||||
return false;
|
||||
}
|
||||
increaseActiveWidgetsCounter();
|
||||
m_screenPlayWidgets.append(widget);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -414,13 +422,18 @@ void ScreenPlayManager::newConnection()
|
||||
\li godotWallpaper
|
||||
\endlist
|
||||
*/
|
||||
void ScreenPlayManager::closeAllWallpapers()
|
||||
bool ScreenPlayManager::closeAllWallpapers()
|
||||
{
|
||||
if (m_screenPlayWallpapers.empty() && m_activeWallpaperCounter == 0)
|
||||
return;
|
||||
if (m_screenPlayWallpapers.empty() && m_activeWallpaperCounter == 0) {
|
||||
qWarning() << "Cannot close connection on empty client list!";
|
||||
return true;
|
||||
}
|
||||
|
||||
closeConntectionByType(ScreenPlayUtil::getAvailableWallpaper());
|
||||
if (!closeConntectionByType(ScreenPlayUtil::getAvailableWallpaper())) {
|
||||
return false;
|
||||
}
|
||||
setActiveWallpaperCounter(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -431,13 +444,18 @@ void ScreenPlayManager::closeAllWallpapers()
|
||||
\li standaloneWidget
|
||||
\endlist
|
||||
*/
|
||||
void ScreenPlayManager::closeAllWidgets()
|
||||
bool ScreenPlayManager::closeAllWidgets()
|
||||
{
|
||||
if (m_screenPlayWidgets.empty() && m_activeWidgetsCounter == 0)
|
||||
return;
|
||||
if (m_screenPlayWidgets.empty() && m_activeWidgetsCounter == 0) {
|
||||
qWarning() << "Cannot close connection on empty client list!";
|
||||
return true;
|
||||
}
|
||||
|
||||
closeConntectionByType(ScreenPlayUtil::getAvailableWidgets());
|
||||
if (!closeConntectionByType(ScreenPlayUtil::getAvailableWidgets())) {
|
||||
return false;
|
||||
}
|
||||
setActiveWidgetsCounter(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -445,13 +463,18 @@ void ScreenPlayManager::closeAllWidgets()
|
||||
*/
|
||||
bool ScreenPlayManager::closeConntectionByType(const QStringList& types)
|
||||
{
|
||||
if (m_clients.isEmpty())
|
||||
if (m_clients.isEmpty()) {
|
||||
qWarning() << "Cannot close connection on empty client list!";
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& client : m_clients) {
|
||||
if (types.contains(client->type(), Qt::CaseInsensitive)) {
|
||||
client->close();
|
||||
if (client->close()) {
|
||||
return false;
|
||||
}
|
||||
if (!m_clients.removeOne(client)) {
|
||||
qWarning() << "Cannot close client";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ private slots:
|
||||
|
||||
public slots:
|
||||
// moc needs full enum namespace info see QTBUG-58454
|
||||
void createWallpaper(
|
||||
bool createWallpaper(
|
||||
const ScreenPlay::InstalledType::InstalledType type,
|
||||
const ScreenPlay::FillMode::FillMode fillMode,
|
||||
const QString& absoluteStoragePath,
|
||||
@ -106,7 +106,7 @@ public slots:
|
||||
const QJsonObject& properties,
|
||||
const bool saveToProfilesConfigFile);
|
||||
|
||||
void createWidget(
|
||||
bool createWidget(
|
||||
const ScreenPlay::InstalledType::InstalledType type,
|
||||
const QPoint& position,
|
||||
const QString& absoluteStoragePath,
|
||||
@ -125,8 +125,8 @@ public slots:
|
||||
ScreenPlayWallpaper* getWallpaperByAppID(const QString& appID) const;
|
||||
|
||||
void newConnection();
|
||||
void closeAllWallpapers();
|
||||
void closeAllWidgets();
|
||||
bool closeAllWallpapers();
|
||||
bool closeAllWidgets();
|
||||
bool closeConntectionByType(const QStringList& types);
|
||||
bool closeConnection(const QString& appID);
|
||||
void setWallpaperValue(const QString& appID, const QString& key, const QString& value);
|
||||
|
@ -77,7 +77,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
tmpScreenNumber = QString::number(m_screenNumber.first());
|
||||
}
|
||||
|
||||
const QStringList proArgs {
|
||||
m_appArgumentsList = QStringList {
|
||||
tmpScreenNumber,
|
||||
m_absolutePath,
|
||||
QString { "appID=" + m_appID },
|
||||
@ -88,8 +88,11 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
// Fixes issue 84 media key overlay
|
||||
" --disable-features=HardwareMediaKeyHandling"
|
||||
};
|
||||
}
|
||||
|
||||
m_process.setArguments(proArgs);
|
||||
bool ScreenPlayWallpaper::start()
|
||||
{
|
||||
m_process.setArguments(m_appArgumentsList);
|
||||
m_process.setProgram(m_globalVariables->wallpaperExecutablePath().toString());
|
||||
// We must start detatched otherwise we would instantly close the process
|
||||
// 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();
|
||||
qInfo() << "Starting ScreenPlayWallpaper detached: " << (success ? "success" : "failed!");
|
||||
if (!success) {
|
||||
qInfo() << m_process.errorString();
|
||||
emit requestClose(m_appID);
|
||||
emit error(QString("Could not start Wallpaper: " + m_process.errorString()));
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
const bool checkWallpaperVisible,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
bool start();
|
||||
|
||||
void replace(
|
||||
const QString& absolutePath,
|
||||
const QString& previewImage,
|
||||
@ -249,5 +251,6 @@ private:
|
||||
bool m_isLooping { true };
|
||||
float m_playbackRate { 1.0f };
|
||||
QTimer m_pingAliveTimer;
|
||||
QStringList m_appArgumentsList;
|
||||
};
|
||||
}
|
||||
|
@ -48,15 +48,18 @@ ScreenPlayWidget::ScreenPlayWidget(
|
||||
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
|
||||
}
|
||||
|
||||
const QStringList proArgs {
|
||||
m_appArgumentsList = QStringList {
|
||||
m_absolutePath,
|
||||
QString { "appID=" + m_appID },
|
||||
QVariant::fromValue(m_type).toString(),
|
||||
QString::number(m_position.x()),
|
||||
QString::number(m_position.y()),
|
||||
};
|
||||
}
|
||||
|
||||
m_process.setArguments(proArgs);
|
||||
bool ScreenPlayWidget::start()
|
||||
{
|
||||
m_process.setArguments(m_appArgumentsList);
|
||||
m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
|
||||
|
||||
QObject::connect(&m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
|
||||
@ -65,10 +68,9 @@ ScreenPlayWidget::ScreenPlayWidget(
|
||||
const bool success = m_process.startDetached();
|
||||
qInfo() << "Starting ScreenPlayWWidget detached: " << (success ? "success" : "failed!");
|
||||
if (!success) {
|
||||
qInfo() << m_process.errorString();
|
||||
emit requestClose(m_appID);
|
||||
emit error(QString("Could not start Widget: " + m_process.errorString()));
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -68,6 +68,8 @@ public:
|
||||
const QString& previewImage, const QJsonObject& properties,
|
||||
const InstalledType::InstalledType type);
|
||||
|
||||
bool start();
|
||||
|
||||
ScreenPlayWidget() { }
|
||||
|
||||
QString previewImage() const { return m_previewImage; }
|
||||
@ -155,5 +157,6 @@ private:
|
||||
InstalledType::InstalledType m_type;
|
||||
QString m_absolutePath;
|
||||
QTimer m_pingAliveTimer;
|
||||
QStringList m_appArgumentsList;
|
||||
};
|
||||
}
|
||||
|
@ -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
|
||||
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;
|
||||
obj.insert("command", QJsonValue("quit"));
|
||||
QByteArray command = QJsonDocument(obj).toJson();
|
||||
|
||||
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) {
|
||||
m_socket->disconnectFromServer();
|
||||
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)) {
|
||||
emit requestDecreaseWidgetCount();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ signals:
|
||||
public slots:
|
||||
void readyRead();
|
||||
void sendMessage(const QByteArray& message);
|
||||
void close();
|
||||
bool close();
|
||||
|
||||
void setAppID(QString appID)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user