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

Add fadeIn not working workaround

See https://bugreports.qt.io/browse/QTBUG-110456

Add exit codes
This commit is contained in:
Elias Steurer 2023-01-22 16:27:18 +01:00
parent 1590be77db
commit a6eb6b0660
10 changed files with 144 additions and 140 deletions

View File

@ -45,6 +45,7 @@ set(SOURCES # cmake-format: sort
set(HEADER
# cmake-format: sort
inc/public/ScreenPlayUtil/exitcodes.h
inc/public/ScreenPlayUtil/AutoPropertyHelpers.h
inc/public/ScreenPlayUtil/ConstRefPropertyHelpers.h
inc/public/ScreenPlayUtil/contenttypes.h

View File

@ -0,0 +1,20 @@
#pragma once
namespace ScreenPlay {
Q_NAMESPACE
enum class WallpaperExitCode {
Ok = 0,
Invalid_ArgumentSize,
Invalid_ActiveScreensList,
Invalid_InstalledType ,
Invalid_CheckWallpaperVisible ,
Invalid_Volume ,
Invalid_AppID ,
Invalid_Setup_ProjectParsingError ,
Invalid_Setup_Error ,
Invalid_Start_Windows_HandleError ,
};
Q_ENUM_NS(WallpaperExitCode)
}

View File

@ -51,14 +51,14 @@ int main(int argc, char* argv[])
} else {
// 8 parameter + 1 OS working directory as the first default paramter
if (argumentList.length() != 9) {
return -3;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_ArgumentSize);
}
const auto activeScreensList = ScreenPlayUtil::parseStringToIntegerList(argumentList.at(1));
if (!activeScreensList.has_value()) {
qCritical("Could not activeScreensList");
return -1;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_ActiveScreensList);
}
auto installedType = ScreenPlay::InstalledType::InstalledType::Unknown;
@ -66,26 +66,26 @@ int main(int argc, char* argv[])
installedType = typeOpt.value();
} else {
qCritical() << "Cannot parse Wallpaper type from value" << argumentList.at(6);
return -6;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_InstalledType);
}
bool okParseCheckWallpaperVisible = false;
const bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible);
if (!okParseCheckWallpaperVisible) {
qCritical("Could not parse checkWallpaperVisible");
return -5;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_CheckWallpaperVisible);
}
bool okParseVolume = 0.0f;
const float volume = argumentList.at(4).toFloat(&okParseVolume);
if (!okParseVolume) {
qCritical("Could not parse Volume");
return -6;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_Volume);
}
QString appID = argumentList.at(3);
if (!appID.startsWith("appID=")) {
qCritical("Invalid appID");
return -6;
return static_cast<int>(ScreenPlay::WallpaperExitCode::Invalid_AppID);
}
appID = appID.remove("appID=");
@ -100,11 +100,11 @@ int main(int argc, char* argv[])
}
const auto setupStatus = window.setup();
if (setupStatus != BaseWindow::ExitCode::Success) {
if (setupStatus != ScreenPlay::WallpaperExitCode::Ok) {
return static_cast<int>(setupStatus);
}
const auto startStatus = window.start();
if (startStatus != BaseWindow::ExitCode::Success) {
if (startStatus != ScreenPlay::WallpaperExitCode::Ok) {
return static_cast<int>(startStatus);
}
return app.exec();

View File

@ -11,6 +11,7 @@ Rectangle {
property bool canFadeByWallpaperFillMode: true
function init() {
fadeInImageSetup()
switch (Wallpaper.type) {
case InstalledType.VideoWallpaper:
if (Wallpaper.videoCodec === VideoCodec.Unknown) {
@ -31,7 +32,6 @@ Rectangle {
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml"
}
fadeIn()
break
case InstalledType.HTMLWallpaper:
loader.setSource(
@ -43,7 +43,6 @@ Rectangle {
break
case InstalledType.QMLWallpaper:
loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
fadeIn()
break
case InstalledType.WebsiteWallpaper:
loader.setSource(
@ -51,7 +50,6 @@ Rectangle {
{
"url": Wallpaper.projectSourceFileAbsolute
})
fadeIn()
break
case InstalledType.GifWallpaper:
loader.setSource(
@ -59,116 +57,18 @@ Rectangle {
"source": Qt.resolvedUrl(
Wallpaper.projectSourceFileAbsolute)
})
fadeIn()
break
}
}
function fadeIn() {
Wallpaper.setVisible(true)
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
imgCover.state = "hideDefaultBackgroundImage"
else
imgCover.opacity = 0
}
anchors.fill: parent
color: {
if (Qt.platform.os !== "windows")
return "black"
else
return Wallpaper.windowsDesktopProperties.color
}
Component.onCompleted: {
init()
}
Connections {
function onQmlExit() {
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
imgCover.state = "exit"
else
Wallpaper.terminate()
}
function onQmlSceneValueReceived(key, value) {
var obj2 = 'import QtQuick; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
newObject.destroy(10000)
}
// Replace wallpaper with QML Scene
function onReloadQML(oldType) {
loader.sourceComponent = undefined
loader.source = ""
Wallpaper.clearComponentCache()
loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
}
// Replace wallpaper with GIF
function onReloadGIF(oldType) {
init()
}
// This function only gets called here (the same function
// is inside the MultimediaWebView.qml) when the previous Wallpaper type
// was not a video
function onReloadVideo(oldType) {
// We need to check if the old type
// was also Video not get called twice
if (oldType === InstalledType.VideoWallpaper)
return
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml"
}
target: Wallpaper
}
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 {
function onRequestFadeIn() {
fadeIn()
}
ignoreUnknownSignals: true
target: loader.item
}
}
Image {
id: imgCover
state: "showDefaultBackgroundImage"
sourceSize.width: Wallpaper.width
sourceSize.height: Wallpaper.height
source: {
if (Qt.platform.os === "windows")
return Qt.resolvedUrl(
"file:///" + Wallpaper.windowsDesktopProperties.wallpaperPath)
else
return ""
}
Component.onCompleted: {
function fadeInImageSetup(){
if (Qt.platform.os !== "windows") {
root.canFadeByWallpaperFillMode = false
return
}
imgCover.source = Qt.resolvedUrl("file:///" + Wallpaper.windowsDesktopProperties.wallpaperPath)
switch (Wallpaper.windowsDesktopProperties.wallpaperStyle) {
case 10:
imgCover.fillMode = Image.PreserveAspectCrop
@ -231,8 +131,99 @@ Rectangle {
root.canFadeByWallpaperFillMode = false
break
}
}
function fadeIn() {
Wallpaper.setVisible(true)
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
imgCover.state = "hideDefaultBackgroundImage"
else
imgCover.opacity = 0
}
anchors.fill: parent
color: {
if (Qt.platform.os !== "windows")
return "black"
else
return Wallpaper.windowsDesktopProperties.color
}
Component.onCompleted: {
init()
}
Connections {
function onQmlExit() {
if (canFadeByWallpaperFillMode && Wallpaper.canFade)
imgCover.state = "exit"
else
Wallpaper.terminate()
}
function onQmlSceneValueReceived(key, value) {
var obj2 = 'import QtQuick; Item {Component.onCompleted: loader.item.'
+ key + ' = ' + value + '; }'
var newObject = Qt.createQmlObject(obj2.toString(), root, "err")
newObject.destroy(10000)
}
// Replace wallpaper with QML Scene
function onReloadQML(oldType) {
loader.sourceComponent = undefined
loader.source = ""
Wallpaper.clearComponentCache()
loader.source = Qt.resolvedUrl(Wallpaper.projectSourceFileAbsolute)
}
// Replace wallpaper with GIF
function onReloadGIF(oldType) {
init()
}
// This function only gets called here (the same function
// is inside the MultimediaWebView.qml) when the previous Wallpaper type
// was not a video
function onReloadVideo(oldType) {
// We need to check if the old type
// was also Video not get called twice
if (oldType === InstalledType.VideoWallpaper)
return
loader.source = "qrc:/qml/ScreenPlayWallpaper/qml/MultimediaView.qml"
}
target: Wallpaper
}
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.Ready ) {
if(loader.item.ready)
root.fadeIn()
}
if (loader.status === Loader.Error) {
loader.source = ""
imgCover.state = "exit"
}
}
}
Image {
id: imgCover
state: "showDefaultBackgroundImage"
sourceSize.width: Wallpaper.width
sourceSize.height: Wallpaper.height
anchors {
top: parent.top
left: parent.left

View File

@ -38,20 +38,20 @@ BaseWindow::BaseWindow()
setOSVersion(QSysInfo::productVersion());
}
BaseWindow::ExitCode BaseWindow::setup()
ScreenPlay::WallpaperExitCode BaseWindow::setup()
{
if (projectPath() == "test") {
setType(ScreenPlay::InstalledType::InstalledType::QMLWallpaper);
setProjectSourceFileAbsolute({ "qrc:/qml/ScreenPlayWallpaper/qml/Test.qml" });
setupLiveReloading();
return BaseWindow::Success;
return ScreenPlay::WallpaperExitCode::Ok;
}
ScreenPlay::ProjectFile projectFile;
projectFile.projectJsonFilePath = QFileInfo(projectPath() + "/project.json");
if (!projectFile.init()) {
qWarning() << "Invalid project at " << projectPath();
return BaseWindow::ParsingError;
return ScreenPlay::WallpaperExitCode::Invalid_Setup_ProjectParsingError;
}
setProjectSourceFile(projectFile.file);
@ -68,13 +68,12 @@ BaseWindow::ExitCode BaseWindow::setup()
// directly without an running ScreenPlay
if (!debugMode()) {
m_sdk = std::make_unique<ScreenPlaySDK>(appID(), QVariant::fromValue(type()).toString());
connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &BaseWindow::destroyThis);
connect(m_sdk.get(), &ScreenPlaySDK::incommingMessage, this, &BaseWindow::messageReceived);
connect(m_sdk.get(), &ScreenPlaySDK::replaceWallpaper, this, &BaseWindow::replaceWallpaper);
sdk()->start();
}
return BaseWindow::Success;
return ScreenPlay::WallpaperExitCode::Ok;
}
/*!

View File

@ -15,7 +15,7 @@
#include <QtQml>
#include "ScreenPlayUtil/util.h"
#include "ScreenPlayUtil/exitcodes.h"
#include "ScreenPlaySDK/screenplaysdk.h"
#include <memory>
@ -26,16 +26,9 @@ class BaseWindow : public QObject {
public:
BaseWindow();
enum ExitCode {
Success = 0,
ParsingError = 1,
Error = 3,
};
Q_ENUM(ExitCode)
virtual ScreenPlay::WallpaperExitCode setup() final;
virtual BaseWindow::ExitCode setup() final;
virtual BaseWindow::ExitCode start() = 0;
virtual ScreenPlay::WallpaperExitCode start() = 0;
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
@ -330,7 +323,7 @@ public slots:
private:
void setupLiveReloading();
private:
protected:
bool m_checkWallpaperVisible { false };
bool m_visualsPaused { false };
bool m_loops { true };

View File

@ -2,7 +2,7 @@
#include "macwindow.h"
BaseWindow::ExitCode MacWindow::start()
ScreenPlay::WallpaperExitCode MacWindow::start()
{
auto* screen = QGuiApplication::screens().at(activeScreensList().at(0));
m_window.setGeometry(screen->geometry());
@ -28,7 +28,7 @@ BaseWindow::ExitCode MacWindow::start()
MacIntegration* macIntegration = new MacIntegration(this);
macIntegration->SetBackgroundLevel(&m_window);
return BaseWindow::ExitCode::Success;
return ScreenPlay::WallpaperExitCode::Ok;
}
void MacWindow::setVisible(bool show)

View File

@ -19,7 +19,7 @@
class MacWindow : public BaseWindow {
Q_OBJECT
public:
BaseWindow::ExitCode start() override;
ScreenPlay::WallpaperExitCode start() override;
signals:

View File

@ -111,7 +111,7 @@ void WinWindow::setupWindowMouseHook()
}
}
BaseWindow::ExitCode WinWindow::start()
ScreenPlay::WallpaperExitCode WinWindow::start()
{
connect(
&m_window, &QQuickView::statusChanged, this, [this](auto status) {
@ -121,6 +121,9 @@ BaseWindow::ExitCode WinWindow::start()
},
Qt::QueuedConnection);
auto* guiAppInst = dynamic_cast<QApplication*>(QApplication::instance());
if(!debugMode()){
connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &WinWindow::destroyThis);
}
connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry);
connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry);
@ -136,7 +139,7 @@ BaseWindow::ExitCode WinWindow::start()
m_windowHandle = reinterpret_cast<HWND>(m_window.winId());
if (!IsWindow(m_windowHandle)) {
qCritical("Could not get a valid window handle!");
return BaseWindow::ExitCode::Error;
return ScreenPlay::WallpaperExitCode::Invalid_Start_Windows_HandleError;
}
qRegisterMetaType<WindowsDesktopProperties*>();
qRegisterMetaType<WinWindow*>();
@ -155,7 +158,7 @@ BaseWindow::ExitCode WinWindow::start()
setupWindowMouseHook();
});
return BaseWindow::ExitCode::Success;
return ScreenPlay::WallpaperExitCode::Ok;
}
/*!
@ -174,12 +177,12 @@ void WinWindow::setVisible(bool show)
}
}
}
/*!
\brief This function fires a qmlExit() signal to the UI for it to handle
nice fade out animation first. Then the UI is responsible for calling
WinWindow::terminate().
*/
void WinWindow::destroyThis()
{
emit qmlExit();
@ -371,9 +374,6 @@ bool WinWindow::hasWindowScaling()
*/
void WinWindow::configureWindowGeometry()
{
qInfo() << "configureWindowGeometry";
setVisible(false);
if (!searchWorkerWindowToParentTo()) {
qFatal("No worker window found");
}

View File

@ -28,7 +28,7 @@ class WinWindow : public BaseWindow {
public:
WindowsDesktopProperties* windowsDesktopProperties() const { return m_windowsDesktopProperties.get(); }
BaseWindow::ExitCode start() override;
ScreenPlay::WallpaperExitCode start() override;
public slots:
void setVisible(bool show) override;