1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

WIP refactor ScreenPlayWallpaper

This is Windows only for now:
Make Classes default constructible. We now have:
setup():
- Can return status of the input data. This is most important, because
  we can now properly exit if this fails
- We now use the same ProjectFile struct as we do in InstalledListModel
- Gets called on all platforms
start():
- Platform specific code

Move argument parsing into main
This commit is contained in:
Elias Steurer 2023-01-20 14:42:48 +01:00
parent 1e8ca2e2d8
commit c5ec7e7bff
15 changed files with 274 additions and 316 deletions

21
.vscode/launch.json vendored
View File

@ -18,7 +18,7 @@
},
{
"name": "Windows Debug ScreenPlay",
"name": "ScreenPlay Windows Debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_Debug/bin/ScreenPlay.exe",
@ -34,7 +34,7 @@
"visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml"
},
{
"name": "Windows RelWithDebInfo ScreenPlay",
"name": "ScreenPlay Windows RelWithDebInfo",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_RelWithDebInfo/bin/ScreenPlay.exe",
@ -48,6 +48,23 @@
}
],
"visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml"
},
{
"name": "ScreenPlayWallpaper Windows Debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/../build_ScreenPlay_Qt_6.4.2_MSVC_Debug/bin/ScreenPlayWallpaper.exe",
"args": [],
"preLaunchTask": "CMake: build",
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "Path",
"value": "${env:Path};${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\bin\\;${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\modules\\;${workspaceFolder}\\..\\aqt\\6.4.2\\msvc2019_64\\qml\\;"
}
],
"visualizerFile": "${workspaceFolder}/.vscode/qt.natvis.xml"
}
]
}

View File

@ -31,8 +31,8 @@
#include <optional>
namespace QArchive {
class DiskCompressor;
class DiskExtractor;
class DiskCompressor;
class DiskExtractor;
}
namespace ScreenPlay {
@ -84,7 +84,7 @@ public slots:
QString toLocal(const QString& url) const;
bool exportProject(QString contentPath, QString exportFileName);
bool importProject(QString archivePath, QString extractionPath);
void requestAllLicenses() ;
void requestAllLicenses();
void requestDataProtection();
bool fileExists(const QString& filePath) const;
@ -121,7 +121,6 @@ public slots:
emit debugMessagesChanged(m_debugMessages);
}
private:
QString m_debugMessages {};
QFuture<void> m_requestAllLicensesFuture;

View File

@ -17,10 +17,10 @@ Q_IMPORT_QML_PLUGIN(ScreenPlayWorkshopPlugin)
int main(int argc, char* argv[])
{
#if defined(Q_OS_WIN)
// https://bugreports.qt.io/browse/QTBUG-72028
qputenv("QT_QPA_PLATFORM", "windows:darkmode=2");
#endif
#if defined(Q_OS_WIN)
// https://bugreports.qt.io/browse/QTBUG-72028
qputenv("QT_QPA_PLATFORM", "windows:darkmode=2");
#endif
QApplication qtGuiApp(argc, argv);
ScreenPlay::App app;

View File

@ -193,8 +193,8 @@ void InstalledListModel::append(const QString& projectJsonFilePath)
beginInsertRows(QModelIndex(), m_screenPlayFiles.size(), m_screenPlayFiles.size());
ProjectFile projectFile;
projectFile.projectJsonFilePath = QFileInfo(projectJsonFilePath);
if(!projectFile.init()){
qWarning() << "Invalid project at "<< projectJsonFilePath;
if (!projectFile.init()) {
qWarning() << "Invalid project at " << projectJsonFilePath;
return;
}
m_screenPlayFiles.append(std::move(projectFile));

View File

@ -158,9 +158,8 @@ void ScreenPlayWallpaper::close()
*/
void ScreenPlayWallpaper::processExit(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitStatus)
if (exitCode != 0)
qWarning() << "WARNING EXIT CODE: " << exitCode;
qWarning() << "WARNING EXIT CODE: " << exitCode << exitStatus;
}
/*!

View File

@ -54,6 +54,11 @@ void ScreenPlaySDK::sendMessage(const QJsonObject& obj)
void ScreenPlaySDK::connected()
{
m_firstConnectionTimer.stop();
if (m_appID.isEmpty() || m_type.isEmpty()) {
qCritical() << "Unable to connect with empyt: " << m_appID << m_type;
emit disconnected();
return;
}
QByteArray welcomeMessage = QString(m_appID + "," + m_type).toUtf8();
m_socket.write(welcomeMessage);

View File

@ -34,13 +34,17 @@ struct ProjectFile {
QString title;
QString description;
// Filenames
QString file;
QString file; // myFancyVideo.mp
QString preview;
QString previewGIF;
// Path to project.json
QFileInfo projectJsonFilePath;
// Folder name
QString folderName;
// Website Wallpaper
QUrl url;
// Video Wallpaper
ScreenPlay::VideoCodec::VideoCodec videoCodec;
QVariant publishedFileID { 0 };
QStringList tags;

View File

@ -2,89 +2,111 @@
namespace ScreenPlay {
bool ProjectFile::init()
{
if(!isValid())
bool ProjectFile::init()
{
if (!isValid())
return false;
const auto jsonObjOpt = ScreenPlayUtil::openJsonFileToObject(projectJsonFilePath.absoluteFilePath());
QDir folder = projectJsonFilePath.dir();
folderName = folder.dirName();
QFileInfo folderInfo(folder.path());
lastModified = folderInfo.birthTime();
if (folderInfo.birthTime().date() == QDateTime::currentDateTime().date())
isNew = true;
if (!jsonObjOpt.has_value())
return false;
const QJsonObject& obj = jsonObjOpt.value();
if (obj.isEmpty())
return false;
// Required:
if (!obj.contains("description"))
return false;
description = obj.value("description").toString();
if (!obj.contains("file"))
return false;
file = obj.value("file").toString();
if (!obj.contains("title"))
return false;
title = obj.value("title").toString();
if (!obj.contains("type"))
return false;
// Optional:
if (obj.contains("previewGIF"))
previewGIF = obj.value("previewGIF").toString();
if (obj.contains("url"))
url = QUrl(obj.value("url").toString());
if (obj.contains("workshopid"))
publishedFileID = obj.value("workshopid").toInt(0);
if (obj.contains("previewThumbnail")) {
preview = obj.value("previewThumbnail").toString();
} else {
if (!obj.contains("preview")) {
return false;
const auto jsonObjOpt = ScreenPlayUtil::openJsonFileToObject(projectJsonFilePath.absoluteFilePath());
QDir folder = projectJsonFilePath.dir();
folderName = folder.dirName();
QFileInfo folderInfo(folder.path());
lastModified = folderInfo.birthTime();
if (folderInfo.birthTime().date() == QDateTime::currentDateTime().date())
isNew = true;
if(!jsonObjOpt.has_value())
return false;
const QJsonObject& obj =jsonObjOpt.value();
if (obj.isEmpty())
return false;
//Required:
if (!obj.contains("description"))
return false;
description = obj.value("description").toString();
if (!obj.contains("file"))
return false;
file = obj.value("file").toString();
if (!obj.contains("title"))
return false;
title = obj.value("title").toString();
if (!obj.contains("type"))
return false;
// Optional:
if (obj.contains("previewGIF"))
previewGIF = obj.value("previewGIF").toString();
if (obj.contains("workshopid"))
publishedFileID = obj.value("workshopid").toInt(0);
if (obj.contains("previewThumbnail")) {
preview = obj.value("previewThumbnail").toString();
} else {
if (!obj.contains("preview")) {
return false;
}
preview = obj.value("preview").toString();
}
preview = obj.value("preview").toString();
}
if (obj.contains("tags")) {
if (obj.value("tags").isArray()) {
auto tagArray = obj.value("tags").toArray();
if (tagArray.size() > 0) {
for (const auto& tag : tagArray) {
tags.append(tag.toString());
}
if (obj.contains("tags")) {
if (obj.value("tags").isArray()) {
auto tagArray = obj.value("tags").toArray();
if (tagArray.size() > 0) {
for (const auto& tag : tagArray) {
tags.append(tag.toString());
}
}
}
}
auto typeParsed = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString());
if (!typeParsed) {
qWarning() << "Type could not parsed from: " << *typeParsed;
auto typeParsed = ScreenPlayUtil::getInstalledTypeFromString(obj.value("type").toString());
if (!typeParsed) {
qWarning() << "Type could not parsed from: " << *typeParsed;
return false;
}
type = typeParsed.value();
if (type == InstalledType::InstalledType::GifWallpaper) {
preview = previewGIF;
}
if (type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) {
if (url.isEmpty()) {
qWarning() << "No url was specified for a websiteWallpaper!";
return false;
}
}
type = *typeParsed;
if (type == InstalledType::InstalledType::GifWallpaper) {
preview = previewGIF;
searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(type);
if (obj.contains("codec")) {
if (auto videoCodecOpt = ScreenPlayUtil::getVideoCodecFromString(obj.value("codec").toString())) {
videoCodec = videoCodecOpt.value();
}
} else if (type == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) {
qWarning("No videoCodec was specified inside the json object!");
if (file.endsWith(".mp4")) {
videoCodec = ScreenPlay::VideoCodec::VideoCodec::H264;
} else if (file.endsWith(".webm")) {
videoCodec = ScreenPlay::VideoCodec::VideoCodec::VP8;
}
searchType = ScreenPlayUtil::getSearchTypeFromInstalledType(type);
return true;
}
bool ProjectFile::isValid()
{
if(!projectJsonFilePath.isFile())
return false;
return true;
}
return true;
}
bool ProjectFile::isValid()
{
if (!projectJsonFilePath.isFile())
return false;
return true;
}
}

View File

@ -25,8 +25,13 @@ int main(int argc, char* argv[])
QApplication app(argc, argv);
// This gives us nice clickable output in QtCreator
qSetMessagePattern("%{if-category}%{category}: %{endif}%{message}\n Loc: [%{file}:%{line}]");
#if defined(Q_OS_WIN)
WinWindow window;
#elif defined(Q_OS_LINUX)
LinuxWindow window;
#elif defined(Q_OS_OSX)
MacWindow window;
#endif
// If we start with only one argument (app path)
// It means we want to test a single wallpaper
@ -34,74 +39,73 @@ 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({ 1 }, "C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/26092021185017", "appID=test", "1", "fill", "videoWallpaper", true, true);
#elif defined(Q_OS_LINUX)
LinuxWindow window({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", false, true);
#elif defined(Q_OS_OSX)
MacWindow window({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true);
#endif
return app.exec();
window.setActiveScreensList({ 0 });
// window.setProjectPath("test");
window.setProjectPath("C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/1958068741");
window.setAppID("test");
window.setVolume(1);
window.setFillMode("fill");
window.setType(ScreenPlay::InstalledType::InstalledType::VideoWallpaper);
window.setCheckWallpaperVisible(true);
window.setDebugMode(true);
} else {
// 8 parameter + 1 OS working directory as the first default paramter
if (argumentList.length() != 9) {
return -3;
}
const auto activeScreensList = ScreenPlayUtil::parseStringToIntegerList(argumentList.at(1));
if (!activeScreensList.has_value()) {
qCritical("Could not activeScreensList");
return -1;
}
auto installedType = ScreenPlay::InstalledType::InstalledType::Unknown;
if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(argumentList.at(6))) {
installedType = typeOpt.value();
} else {
qCritical() << "Cannot parse Wallpaper type from value" << argumentList.at(6);
return -6;
}
bool okParseCheckWallpaperVisible = false;
const bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible);
if (!okParseCheckWallpaperVisible) {
qCritical("Could not parse checkWallpaperVisible");
return -5;
}
bool okParseVolume = 0.0f;
const float volume = argumentList.at(4).toFloat(&okParseVolume);
if (!okParseVolume) {
qCritical("Could not parse Volume");
return -6;
}
QString appID = argumentList.at(3);
if (!appID.startsWith("appID=")) {
qCritical("Invalid appID");
return -6;
}
appID = appID.remove("appID=");
window.setActiveScreensList(activeScreensList.value());
window.setProjectPath(argumentList.at(2));
window.setAppID(appID);
window.setVolume(volume);
window.setFillMode(argumentList.at(5));
window.setType(installedType);
window.setCheckWallpaperVisible(checkWallpaperVisible);
window.setDebugMode(false);
}
// 8 parameter + 1 OS working directory as the first default paramter
if (argumentList.length() != 9) {
return -3;
const auto setupStatus = window.setup();
if (setupStatus != BaseWindow::ExitCode::Success) {
return static_cast<int>(setupStatus);
}
const bool debugMode = false;
const auto activeScreensList = ScreenPlayUtil::parseStringToIntegerList(argumentList.at(1));
if (!activeScreensList.has_value())
return -4;
// See ScreenPlayWallpaper m_appArgumentsList constructor how the args get created
const QString projectFilePath = argumentList.at(2);
const QString appID = argumentList.at(3);
const QString volume = argumentList.at(4);
const QString fillmode = argumentList.at(5);
const QString type = argumentList.at(6);
bool okParseCheckWallpaperVisible = false;
bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible);
if (!okParseCheckWallpaperVisible) {
qFatal("Could not parse checkWallpaperVisible");
return -5;
const auto startStatus = window.start();
if (startStatus != BaseWindow::ExitCode::Success) {
return static_cast<int>(startStatus);
}
#if defined(Q_OS_WIN)
WinWindow window(
activeScreensList.value(),
projectFilePath,
appID,
volume,
fillmode,
type,
checkWallpaperVisible,
debugMode);
#elif defined(Q_OS_LINUX)
LinuxWindow window(
activeScreensList.value(),
projectFilePath,
appID,
volume,
fillmode,
type,
checkWallpaperVisible,
debugMode);
#elif defined(Q_OS_OSX)
MacWindow window(
activeScreensList.value(),
projectFilePath,
appID,
volume,
fillmode,
type,
checkWallpaperVisible,
debugMode);
#endif
return app.exec();
}

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "basewindow.h"
#include "ScreenPlayUtil/projectfile.h"
#include "ScreenPlayUtil/util.h"
/*!
@ -15,23 +16,7 @@
\brief .
*/
BaseWindow::BaseWindow(QObject* parent)
: QObject(parent)
{
}
BaseWindow::BaseWindow(
const QVector<int> activeScreensList,
const QString& projectFilePath,
const QString& type,
const bool checkWallpaperVisible,
const QString& appID,
const bool debugMode)
: QObject(nullptr)
, m_checkWallpaperVisible(checkWallpaperVisible)
, m_activeScreensList(activeScreensList)
, m_debugMode(debugMode)
, m_sdk(std::make_unique<ScreenPlaySDK>(appID, type))
BaseWindow::BaseWindow()
{
QApplication::instance()->installEventFilter(this);
@ -50,74 +35,49 @@ BaseWindow::BaseWindow(
qmlRegisterType<BaseWindow>("ScreenPlay.Wallpaper", 1, 0, "Wallpaper");
if (!appID.contains("appID=")) {
qInfo() << "Invalid appID: " << appID;
qFatal("AppID does not contain appID=");
}
setAppID(appID);
setProjectPath(projectFilePath);
setOSVersion(QSysInfo::productVersion());
}
if (projectFilePath == "test") {
BaseWindow::ExitCode BaseWindow::setup()
{
if (projectPath() == "test") {
setType(ScreenPlay::InstalledType::InstalledType::QMLWallpaper);
setProjectSourceFileAbsolute({ "qrc:/qml/ScreenPlayWallpaper/qml/Test.qml" });
setupLiveReloading();
return;
return BaseWindow::Success;
}
ScreenPlay::ProjectFile projectFile;
projectFile.projectJsonFilePath = QFileInfo(projectPath() + "/project.json");
if (!projectFile.init()) {
qWarning() << "Invalid project at " << projectPath();
return BaseWindow::ParsingError;
}
auto projectOpt = ScreenPlayUtil::openJsonFileToObject(projectFilePath + "/project.json");
if (!projectOpt.has_value()) {
QApplication::exit(-5);
}
const QJsonObject project = projectOpt.value();
if (!project.contains("type")) {
qFatal("No type was specified inside the json object!");
QApplication::exit(-3);
}
if (!project.contains("file") && !project.contains("url")) {
qFatal("No file was specified inside the json object!");
QApplication::exit(-4);
}
if (auto typeOpt = ScreenPlayUtil::getInstalledTypeFromString(project.value("type").toString())) {
setType(typeOpt.value());
if (this->type() == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) {
if (auto videoCodecOpt = ScreenPlayUtil::getVideoCodecFromString(project.value("videoCodec").toString())) {
setVideoCodec(videoCodecOpt.value());
} else {
qCritical() << "Cannot parse Wallpaper video codec from value" << project.value("type");
}
} else if (!project.contains("videoCodec") && this->type() == ScreenPlay::InstalledType::InstalledType::VideoWallpaper) {
qWarning("No videoCodec was specified inside the json object!");
const QString filename = project.value("file").toString();
if (filename.endsWith(".mp4")) {
setVideoCodec(ScreenPlay::VideoCodec::VideoCodec::H264);
} else if (filename.endsWith(".webm")) {
setVideoCodec(ScreenPlay::VideoCodec::VideoCodec::VP8);
}
}
} else {
qCritical() << "Cannot parse Wallpaper type from value" << project.value("type");
}
setProjectSourceFile(projectFile.file);
if (m_type == ScreenPlay::InstalledType::InstalledType::WebsiteWallpaper) {
if (!project.contains("url")) {
qFatal("No url was specified for a websiteWallpaper!");
QApplication::exit(-5);
}
setProjectSourceFileAbsolute(project.value("url").toString());
setProjectSourceFileAbsolute(projectFile.url);
} else {
setProjectSourceFile(project.value("file").toString());
setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectFilePath + "/" + projectSourceFile()));
setProjectSourceFileAbsolute(QUrl::fromLocalFile(projectPath() + "/" + projectSourceFile()));
}
setupLiveReloading();
// Debug mode means we start the ScreenPlayWallpaper
// directly without an running ScreenPlay
if (!debugMode()) {
m_sdk = std::make_unique<ScreenPlaySDK>(appID(), QVariant::fromValue(type()).toString());
// QObject::connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, [this]() {
// destroyThis();
// });
connect(sdk(), &ScreenPlaySDK::sdkDisconnected, this, &BaseWindow::destroyThis);
connect(sdk(), &ScreenPlaySDK::incommingMessage, this, &BaseWindow::messageReceived);
connect(sdk(), &ScreenPlaySDK::replaceWallpaper, this, &BaseWindow::replaceWallpaper);
sdk()->start();
}
return BaseWindow::Success;
}
/*!

View File

@ -24,14 +24,18 @@ class BaseWindow : public QObject {
Q_OBJECT
public:
BaseWindow(QObject* parent = nullptr);
BaseWindow(
const QVector<int> activeScreensList,
const QString& projectFilePath,
const QString& type,
const bool checkWallpaperVisible,
const QString& appID,
const bool debugMode);
BaseWindow();
enum ExitCode {
Success = 0,
ParsingError = 1,
Error = 3,
};
Q_ENUM(ExitCode)
virtual BaseWindow::ExitCode setup() final;
virtual BaseWindow::ExitCode start() = 0;
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
@ -339,7 +343,6 @@ private:
float m_playbackRate { 1.0f };
float m_currentTime { 0.0f };
QString m_contentBasePath;
QString m_projectPath;
QString m_projectSourceFile;
QString m_appID;

View File

@ -20,7 +20,7 @@ WindowsDesktopProperties::WindowsDesktopProperties(QObject* parent)
setIsTiled(settings.value("TileWallpaper").toBool());
QFileInfo defaultBackgroundImageInfo(m_wallpaperPath);
if(defaultBackgroundImageInfo.exists()){
if (defaultBackgroundImageInfo.exists()) {
QImage backgroundImage(defaultBackgroundImageInfo.absoluteFilePath());
setDefaultWallpaperSize(backgroundImage.size());
}

View File

@ -8,8 +8,8 @@
#include <QObject>
#include <QPoint>
#include <QSettings>
#include <QString>
#include <QSize>
#include <QString>
#include <qqml.h>
#include <qt_windows.h>

View File

@ -1,10 +1,17 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "winwindow.h"
#include "ScreenPlayUtil/projectfile.h"
#include "qqml.h"
#include <algorithm>
#include <iostream>
#include <vector>
/*!
\class WinWindow
\inmodule ScreenPlayWallpaper
\brief ScreenPlayWindow used for the Windows implementation.
*/
/*!
\brief Searches for the worker window for our window to parent to.
*/
@ -104,68 +111,21 @@ void WinWindow::setupWindowMouseHook()
}
}
/*!
\class WinWindow
\inmodule ScreenPlayWallpaper
\brief ScreenPlayWindow used for the Windows implementation.
*/
/*!
\brief Creates a window on Windows from the give parameters:
\a activeScreensList
\a projectFilePath
\a appID
\a volume
\a fillmode
\a type
\a checkWallpaperVisible
\a debugMode
*/
WinWindow::WinWindow(
const QVector<int>& activeScreensList,
const QString& projectFilePath,
const QString& appID,
const QString& volume,
const QString& fillmode,
const QString& type,
const bool checkWallpaperVisible,
const bool debugMode)
: BaseWindow(
activeScreensList,
projectFilePath,
type,
checkWallpaperVisible,
appID,
debugMode)
BaseWindow::ExitCode WinWindow::start()
{
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
connect(this, &BaseWindow::reloadQML, this, [this]() {
clearComponentCache();
});
connect(
&m_window, &QQuickView::statusChanged,
this, [](auto status) {
if (status == QQuickView::Status::Error)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);
connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
connect(sdk(), &ScreenPlaySDK::sdkDisconnected, this, &WinWindow::destroyThis);
connect(sdk(), &ScreenPlaySDK::incommingMessage, this, &WinWindow::messageReceived);
connect(sdk(), &ScreenPlaySDK::replaceWallpaper, this, &WinWindow::replaceWallpaper);
connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow);
connect(
&m_window, &QQuickView::statusChanged,
this, [](auto status) {
&m_window, &QQuickView::statusChanged, this, [this](auto status) {
if (status == QQuickView::Status::Error) {
qInfo() << status;
QCoreApplication::exit(-1);
destroyThis();
}
},
Qt::QueuedConnection);
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
connect(this, &BaseWindow::reloadQML, this, &WinWindow::clearComponentCache);
connect(&m_checkForFullScreenWindowTimer, &QTimer::timeout, this, &WinWindow::checkForFullScreenWindow);
const auto screens = QApplication::screens();
for (const auto& screen : screens) {
@ -175,27 +135,18 @@ WinWindow::WinWindow(
m_windowsDesktopProperties = std::make_unique<WindowsDesktopProperties>();
m_windowHandle = reinterpret_cast<HWND>(m_window.winId());
if (!IsWindow(m_windowHandle)) {
qFatal("Could not get a valid window handle!");
qCritical("Could not get a valid window handle!");
return BaseWindow::ExitCode::Error;
}
qRegisterMetaType<WindowsDesktopProperties*>();
qRegisterMetaType<WinWindow*>();
bool ok = false;
float volumeParsed = volume.toFloat(&ok);
if (!ok) {
qFatal("Could not parse volume");
}
setVolume(volumeParsed);
setFillMode(fillmode);
qmlRegisterSingletonInstance<WinWindow>("ScreenPlayWallpaper", 1, 0, "Wallpaper", this);
configureWindowGeometry();
// We do not support autopause for multi monitor wallpaper
if (this->activeScreensList().length() == 1) {
if (checkWallpaperVisible) {
if (checkWallpaperVisible()) {
m_checkForFullScreenWindowTimer.start(10);
}
}
@ -204,9 +155,9 @@ WinWindow::WinWindow(
setupWindowMouseHook();
});
if (!debugMode)
sdk()->start();
return BaseWindow::ExitCode::Success;
}
/*!
\brief Calls ShowWindow function to set the main window in/visible.
*/
@ -228,6 +179,7 @@ void WinWindow::setVisible(bool show)
nice fade out animation first. Then the UI is responsible for calling
WinWindow::terminate().
*/
void WinWindow::destroyThis()
{
emit qmlExit();

View File

@ -26,17 +26,10 @@ class WinWindow : public BaseWindow {
Q_PROPERTY(WindowsDesktopProperties* windowsDesktopProperties READ windowsDesktopProperties WRITE setWindowsDesktopProperties NOTIFY windowsDesktopPropertiesChanged)
public:
explicit WinWindow(
const QVector<int>& activeScreensList,
const QString& projectFilePath,
const QString& appID,
const QString& volume,
const QString& fillmode, const QString& type,
const bool checkWallpaperVisible,
const bool debugMode = false);
WindowsDesktopProperties* windowsDesktopProperties() const { return m_windowsDesktopProperties.get(); }
BaseWindow::ExitCode start() override;
public slots:
void setVisible(bool show) override;
void destroyThis() override;