mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-06 19:12:30 +01:00
Fix quit when qml file contains an error
I cannt reproduce this in an empty project but _something_ stopped the quit call in the terminate function. The only workaround I found was using an async loader... Increase ping alive to 3000ms and change it to a static variable Move getAvailableFillModes to globalvariables.h
This commit is contained in:
parent
eedfcdab47
commit
dc35dacb47
@ -57,6 +57,12 @@ class GlobalVariables : public QObject {
|
||||
public:
|
||||
explicit GlobalVariables(QObject* parent = nullptr);
|
||||
|
||||
/*!
|
||||
\brief We need to check if there was an error in the Wallpaper/Widgets.
|
||||
For this we ping it every 1s.
|
||||
*/
|
||||
static const int contentPingAliveIntervalMS = 3000;
|
||||
|
||||
/*!
|
||||
\property GlobalVariables::localStoragePath
|
||||
\brief Returns the localStoragePath.
|
||||
|
@ -40,12 +40,12 @@
|
||||
#include <QProcess>
|
||||
#include <QtWebSockets/QWebSocket>
|
||||
|
||||
#include "ScreenPlayUtil/projectfile.h"
|
||||
#include "ganalytics.h"
|
||||
#include "globalvariables.h"
|
||||
#include "installedlistmodel.h"
|
||||
#include "monitorlistmodel.h"
|
||||
#include "profilelistmodel.h"
|
||||
#include "ScreenPlayUtil/projectfile.h"
|
||||
#include "projectsettingslistmodel.h"
|
||||
#include "screenplaywallpaper.h"
|
||||
#include "screenplaywidget.h"
|
||||
|
@ -91,6 +91,9 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(const QVector<int>& screenNumber,
|
||||
|
||||
m_process.setArguments(proArgs);
|
||||
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
|
||||
// to display the original wallpaper.
|
||||
const bool success = m_process.startDetached();
|
||||
qInfo() << "Starting ScreenPlayWallpaper detached: " << (success ? "success" : "failed!");
|
||||
if (!success) {
|
||||
@ -181,23 +184,23 @@ void ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QString& v
|
||||
void ScreenPlayWallpaper::setSDKConnection(const std::shared_ptr<SDKConnection>& connection)
|
||||
{
|
||||
m_connection = connection;
|
||||
QTimer::singleShot(500, [this]() {
|
||||
|
||||
QTimer::singleShot(1000, [this]() {
|
||||
if (playbackRate() != 1.0) {
|
||||
setWallpaperValue("playbackRate", QString::number(playbackRate()), false);
|
||||
}
|
||||
});
|
||||
|
||||
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!";
|
||||
emit requestClose(m_appID);
|
||||
});
|
||||
m_pingAliveTimer.start(GlobalVariables::contentPingAliveIntervalMS);
|
||||
});
|
||||
// Check every X seconds if the wallpaper is still alive
|
||||
QObject::connect(m_connection.get(), &SDKConnection::pingAliveReceived, this, [this]() {
|
||||
m_pingAliveTimer.stop();
|
||||
m_pingAliveTimer.start(16000);
|
||||
m_pingAliveTimer.start(GlobalVariables::contentPingAliveIntervalMS);
|
||||
});
|
||||
|
||||
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!";
|
||||
emit requestClose(m_appID);
|
||||
});
|
||||
m_pingAliveTimer.start(16000);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -225,7 +228,7 @@ void ScreenPlayWallpaper::replace(
|
||||
obj.insert("command", "replace");
|
||||
obj.insert("type", QVariant::fromValue(type).toString());
|
||||
obj.insert("fillMode", QVariant::fromValue(fillMode).toString());
|
||||
obj.insert("volume", std::floor(volume * 100.0f) / 100.0f);
|
||||
obj.insert("volume", std::floor(volume * 100.0F) / 100.0f);
|
||||
obj.insert("absolutePath", absolutePath);
|
||||
obj.insert("file", file);
|
||||
obj.insert("checkWallpaperVisible", checkWallpaperVisible);
|
||||
|
@ -88,14 +88,14 @@ void ScreenPlayWidget::setSDKConnection(const std::shared_ptr<SDKConnection>& co
|
||||
// Check every X seconds if the widget is still alive
|
||||
QObject::connect(m_connection.get(), &SDKConnection::pingAliveReceived, this, [this]() {
|
||||
m_pingAliveTimer.stop();
|
||||
m_pingAliveTimer.start(16000);
|
||||
m_pingAliveTimer.start(GlobalVariables::contentPingAliveIntervalMS);
|
||||
});
|
||||
|
||||
QObject::connect(&m_pingAliveTimer, &QTimer::timeout, this, [this]() {
|
||||
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);
|
||||
m_pingAliveTimer.start(GlobalVariables::contentPingAliveIntervalMS);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -72,7 +72,7 @@ void ScreenPlay::SDKConnection::readyRead()
|
||||
}
|
||||
} else if (msg.startsWith("{") && msg.endsWith("}")) {
|
||||
QJsonObject obj;
|
||||
QJsonParseError err;
|
||||
QJsonParseError err {};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(QByteArray { msg.toUtf8() }, &err);
|
||||
|
||||
if (err.error != QJsonParseError::NoError)
|
||||
|
@ -58,6 +58,7 @@ bool Util::writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObj
|
||||
}
|
||||
|
||||
if (!configTmp.open(openMode)) {
|
||||
qWarning() << "Could not open out file!" << configTmp.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ void ScreenPlaySDK::init()
|
||||
}
|
||||
|
||||
QObject::connect(&m_pingAliveTimer, &QTimer::timeout, this, &ScreenPlaySDK::pingAlive);
|
||||
m_pingAliveTimer.start(5000);
|
||||
m_pingAliveTimer.start(1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ QString executableEnding();
|
||||
QStringList getAvailableWallpaper();
|
||||
QStringList getAvailableWidgets();
|
||||
QStringList getAvailableTypes();
|
||||
QStringList getAvailableFillModes();
|
||||
bool isWallpaper(const ScreenPlay::InstalledType::InstalledType type);
|
||||
bool isWidget(const ScreenPlay::InstalledType::InstalledType type);
|
||||
}
|
||||
|
@ -29,6 +29,30 @@ std::optional<QJsonObject> openJsonFileToObject(const QString& path)
|
||||
return jsonDocument.object();
|
||||
}
|
||||
|
||||
bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate)
|
||||
{
|
||||
QFile configTmp;
|
||||
configTmp.setFileName(absoluteFilePath);
|
||||
QIODevice::OpenMode openMode;
|
||||
if (truncate) {
|
||||
openMode = QIODevice::ReadWrite | QIODevice::Truncate;
|
||||
} else {
|
||||
openMode = QIODevice::ReadWrite | QIODevice::Append;
|
||||
}
|
||||
|
||||
if (!configTmp.open(openMode)) {
|
||||
qWarning() << "Could not open out file!" << configTmp.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&configTmp);
|
||||
out.setCodec("UTF-8");
|
||||
out << QJsonDocument(object).toJson();
|
||||
|
||||
configTmp.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Opens a json file (absolute path) and tries to convert it to a QString.
|
||||
Returns std::nullopt when not successful.
|
||||
@ -270,4 +294,10 @@ bool isWidget(const ScreenPlay::InstalledType::InstalledType type)
|
||||
return (type == InstalledType::QMLWidget || type == InstalledType::HTMLWidget);
|
||||
}
|
||||
|
||||
QStringList getAvailableFillModes()
|
||||
{
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
|
||||
return { "stretch", "fill", "contain", "cover", "scale-down" };
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,6 +111,15 @@ Rectangle {
|
||||
Loader {
|
||||
id: loader
|
||||
anchors.fill: parent
|
||||
// QML Engine deadlocks in 5.15.2 when a loader cannot load
|
||||
// an item. QApplication::quit(); waits for the destruction forever.
|
||||
asynchronous: true
|
||||
onStatusChanged: {
|
||||
if (loader.status === Loader.Error) {
|
||||
loader.source = ""
|
||||
Wallpaper.terminate()
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
ignoreUnknownSignals: true
|
||||
target: loader.item
|
||||
@ -129,7 +138,6 @@ Rectangle {
|
||||
right: parent.right
|
||||
}
|
||||
state: "in"
|
||||
onStatusChanged: print(status,source)
|
||||
sourceSize.width: Wallpaper.width
|
||||
sourceSize.height: Wallpaper.height
|
||||
source: {
|
||||
|
@ -327,12 +327,10 @@ public slots:
|
||||
|
||||
fillMode = fillMode.toLower();
|
||||
|
||||
QStringList availableFillModes { "stretch", "fill", "contain", "cover", "scale-down" };
|
||||
|
||||
if (!availableFillModes.contains(fillMode)) {
|
||||
if (!ScreenPlayUtil::getAvailableFillModes().contains(fillMode)) {
|
||||
qWarning() << "Unable to set fillmode, the provided value did not match the available values"
|
||||
<< "Provided: " << fillMode
|
||||
<< "Available: " << availableFillModes;
|
||||
<< "Available: " << ScreenPlayUtil::getAvailableFillModes();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -383,7 +381,7 @@ public slots:
|
||||
if (m_visualsPaused == visualsPaused)
|
||||
return;
|
||||
|
||||
qDebug() << "visualsPaused: " << visualsPaused;
|
||||
qInfo() << "visualsPaused: " << visualsPaused;
|
||||
|
||||
m_visualsPaused = visualsPaused;
|
||||
emit visualsPausedChanged(m_visualsPaused);
|
||||
|
@ -74,14 +74,17 @@ LRESULT __stdcall MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
void WinWindow::setupWindowMouseHook()
|
||||
{
|
||||
using ScreenPlay::InstalledType::InstalledType;
|
||||
|
||||
// MUST be called before setting hook for events!
|
||||
if (type() != ScreenPlay::InstalledType::InstalledType::VideoWallpaper) {
|
||||
if (type() != InstalledType::VideoWallpaper && type() != InstalledType::GifWallpaper) {
|
||||
qInfo() << "Enable mousehook";
|
||||
g_winGlobalHook = &m_window;
|
||||
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
if (!(g_mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, hInstance, 0))) {
|
||||
qDebug() << "Faild to install mouse hook!";
|
||||
qInfo() << "Faild to install mouse hook!";
|
||||
return;
|
||||
}
|
||||
qInfo() << "Setup mousehook";
|
||||
}
|
||||
@ -343,7 +346,6 @@ void WinWindow::checkForFullScreenWindow()
|
||||
|
||||
void WinWindow::terminate()
|
||||
{
|
||||
|
||||
ShowWindow(m_windowHandle, SW_HIDE);
|
||||
|
||||
// Force refresh so that we display the regular
|
||||
@ -351,7 +353,7 @@ void WinWindow::terminate()
|
||||
ShowWindow(m_windowHandleWorker, SW_HIDE);
|
||||
ShowWindow(m_windowHandleWorker, SW_SHOW);
|
||||
|
||||
QCoreApplication::quit();
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
void WinWindow::clearComponentCache()
|
||||
|
Loading…
Reference in New Issue
Block a user