1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-15 06:52:34 +02:00

Fix live reloading

The path contain invalid file:///
We now simply save the base path and
use this variable
This commit is contained in:
Elias Steurer 2021-05-12 18:36:37 +02:00
parent 36c6f627cf
commit 8e8b8b0480
4 changed files with 39 additions and 12 deletions

View File

@ -32,9 +32,10 @@ int main(int argc, char* argv[])
// For testing purposes when starting the ScreenPlayWallpaper directly.
if (argumentList.length() == 1) {
#if defined(Q_OS_WIN)
WinWindow window1({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true);
// WinWindow window1({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true);
WinWindow window1({ 0 }, "C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/_tmp_171806", "appID=test", "1", "fill", "videoWallpaper", true, true);
#elif defined(Q_OS_LINUX)
LinuxWindow window({ 0 }, "/home/graphicscore/Desktop/wallpapers/MechaGirl", "appid", "1", "fill", false);
LinuxWindow window({ 0 }, "test", "appid", "1", "fill", false);
#elif defined(Q_OS_OSX)
MacWindow window({ 0 }, "test", "appid", "1", "fill");
#endif

View File

@ -37,7 +37,7 @@ BaseWindow::BaseWindow(
}
setAppID(appID);
setContentBasePath(projectFilePath);
setOSVersion(QSysInfo::productVersion());
if (projectFilePath == "test") {
@ -209,13 +209,22 @@ QString BaseWindow::getApplicationPath()
}
/*!
\brief This public slot is for QML usage.
\brief This public slot is for QML usage. We limit the change event updates
to every 50ms, because the filesystem can be very trigger happy
with multiple change events per second.
*/
void BaseWindow::setupLiveReloading()
{
auto reloadQMLLambda = [this]() { emit reloadQML(type()); };
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, reloadQMLLambda);
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, reloadQMLLambda);
const QFileInfo file { m_fullContentPath };
m_fileSystemWatcher.addPaths({ file.path(), m_fullContentPath });
auto reloadQMLLambda = [this]() {
m_liveReloadLimiter.stop();
emit reloadQML(type());
};
auto timeoutLambda = [this]() {
m_liveReloadLimiter.start(50);
};
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, timeoutLambda);
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, timeoutLambda);
QObject::connect(&m_liveReloadLimiter, &QTimer::timeout, this, reloadQMLLambda);
m_fileSystemWatcher.addPaths({ m_contentBasePath });
}

View File

@ -72,6 +72,7 @@ public:
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
Q_PROPERTY(QString basePath READ basePath WRITE setBasePath NOTIFY basePathChanged)
Q_PROPERTY(QString fullContentPath READ fullContentPath WRITE setFullContentPath NOTIFY fullContentPathChanged)
Q_PROPERTY(QString contentBasePath READ contentBasePath WRITE setContentBasePath NOTIFY contentBasePathChanged)
Q_PROPERTY(QString fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(bool loops READ loops WRITE setLoops NOTIFY loopsChanged)
@ -113,6 +114,7 @@ public:
QString basePath() const { return m_basePath; }
bool debugMode() const { return m_debugMode; }
ScreenPlaySDK* sdk() const { return m_sdk.get(); }
const QString& contentBasePath() const { return m_contentBasePath; }
signals:
void qmlExit();
@ -142,6 +144,8 @@ signals:
void debugModeChanged(bool debugMode);
void sdkChanged(ScreenPlaySDK* sdk);
void contentBasePathChanged(const QString&);
public slots:
virtual void destroyThis() { }
virtual void setVisible(bool show) { Q_UNUSED(show) }
@ -340,6 +344,14 @@ public slots:
emit sdkChanged(sdk);
}
void setContentBasePath(const QString& contentBasePath)
{
if (m_contentBasePath == contentBasePath)
return;
m_contentBasePath = contentBasePath;
emit contentBasePathChanged(m_contentBasePath);
}
private:
void setupLiveReloading();
@ -370,4 +382,6 @@ private:
QString m_basePath;
bool m_debugMode = false;
std::unique_ptr<ScreenPlaySDK> m_sdk;
QString m_contentBasePath;
QTimer m_liveReloadLimiter;
};

View File

@ -123,7 +123,6 @@ void WinWindow::setupWindowMouseHook()
qInfo() << "Faild to install mouse hook!";
return;
}
qInfo() << "Setup mousehook";
}
}
@ -146,6 +145,9 @@ WinWindow::WinWindow(
{
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
connect(this, &BaseWindow::reloadQML, this, [this]() {
clearComponentCache();
});
connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
@ -187,7 +189,7 @@ WinWindow::WinWindow(
}
}
if (hasWindowScaling) {
qInfo() << "scaling";
qInfo() << "Monitor with scaling detected!";
configureWindowGeometry();
}
@ -202,7 +204,8 @@ WinWindow::WinWindow(
setupWindowMouseHook();
});
sdk()->start();
if (!debugMode)
sdk()->start();
}
void WinWindow::setVisible(bool show)