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

Fix SP Wallpaper and Widgets arguments

we now use regular --args instead of
position based arguments. This is needed
now that we open different types like Godot
wallpaper that have different args.
This commit is contained in:
Elias Steurer 2023-12-20 15:11:16 +01:00
parent 8ebc88980a
commit 70e9b48abf
9 changed files with 295 additions and 152 deletions

View File

@ -83,14 +83,16 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
tmpScreenNumber = QString::number(m_screenNumber.first());
}
const QString screens = "{" + tmpScreenNumber + "}";
m_appArgumentsList = QStringList {
tmpScreenNumber,
m_absolutePath,
QString { "appID=" + m_appID },
QString::number(static_cast<double>(volume)),
QVariant::fromValue(fillMode).toString(),
QVariant::fromValue(type).toString(),
QString::number(m_settings->checkWallpaperVisible()),
"--screens", screens,
"--path", m_absolutePath,
"--appID", m_appID,
"--volume", QString::number(static_cast<double>(volume)),
"--fillmode", QVariant::fromValue(fillMode).toString(),
"--type", QVariant::fromValue(type).toString(),
"--check", QString::number(m_settings->checkWallpaperVisible())
};
// Fixes issue 84 media key overlay in Qt apps
@ -101,7 +103,7 @@ ScreenPlayWallpaper::ScreenPlayWallpaper(
if (m_projectJson.contains("version")) {
const quint64 version = m_projectJson.value("version").toInt();
const QString packageFileName = QString("project-v%1.zip").arg(version);
m_appArgumentsList.append(packageFileName);
m_appArgumentsList.append({ "--projectPackageFile", packageFileName });
}
}
}

View File

@ -46,11 +46,18 @@ ScreenPlayWidget::ScreenPlayWidget(
m_projectSettingsListModel.init(type, projectSettingsListModelProperties);
m_appArgumentsList = QStringList {
"--path",
m_absolutePath,
QString { "appID=" + m_appID },
"--appID",
m_appID,
"--type",
QVariant::fromValue(m_type).toString(),
"--posX",
QString::number(m_position.x()),
"--posY",
QString::number(m_position.y()),
"--debug",
"--false",
};
}

View File

@ -110,7 +110,7 @@ public:
bool writeFileFromQrc(const QString& qrcPath, const QString& absolutePath);
bool copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, const QString& destination);
QString toString(const QStringList& list) const;
std::optional<QVector<int>> parseStringToIntegerList(const QString string) const;
std::optional<QVector<int>> parseStringToIntegerList(const QString& string) const;
float roundDecimalPlaces(const float number) const;
QString generateRandomString(quint32 length = 32);
QString executableAppEnding();

View File

@ -461,15 +461,21 @@ QStringList Util::getAvailableFillModes() const
/*!
\brief parseIntList parses a list of string separated with a comma
"1,2,3". IMPORTANT: No trailing comma!
"{1,2,3}". IMPORTANT: No trailing comma!
*/
std::optional<QVector<int>> Util::parseStringToIntegerList(const QString string) const
std::optional<QVector<int>> Util::parseStringToIntegerList(const QString& string) const
{
if (string.isEmpty())
return {};
if (!(string.startsWith("{") && string.endsWith("}")))
return {};
QVector<int> list;
QStringList stringList = string.split(",");
QString clean = string;
clean = clean.replace("{", "");
clean = clean.replace("}", "");
QStringList stringList = clean.split(",");
for (const auto& item : stringList) {
bool ok = false;
int val = item.toInt(&ok);

View File

@ -39,16 +39,12 @@ func _ready():
var path
var args = OS.get_cmdline_args()
if args.size() > 1:
if not parse_args():
get_tree().quit()
return
#screen_play_wallpaper.set_projectPath("C:\\Code\\cpp\\ScreenPlay\\ScreenPlay\\Content\\wallpaper_godot_fjord")
path = screen_play_wallpaper.get_projectPath() + "/" + screen_play_wallpaper.get_projectPackageFile()
else:
if not parse_args():
get_tree().quit()
return
print(path)
path = screen_play_wallpaper.get_projectPath() + "/" + screen_play_wallpaper.get_projectPackageFile()
if not load_scene(path):
print("Failed to load the PCK file.")
# No not call terminate here because we did not
@ -95,35 +91,76 @@ func load_scene(path):
func parse_args():
var args = OS.get_cmdline_args()
print("Parse args:", args)
var offset = 0
if args[0] == "res://main.tscn":
offset = 1
# Check if only the default argument is provided
if args.size() == 1:
args = ["--path",
#"C:/Code/cpp/ScreenPlay/ScreenPlay/Content/wallpaper_godot_fjord",
"C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/2023_12_08_205323",
"--appID", "qmz9lq4wglox5DdYaXumVgRSDeZYAUjC",
"--screens", "{0}",
"--volume", "1",
"--check", "0",
"--projectPackageFile","project-v1.zip"
]
# Remove the first argument if it's the main.tscn file
if args.size() > 0 and args[0] == "res://main.tscn":
var new_args = []
for i in range(1, args.size()):
new_args.append(args[i])
args = new_args
# Create a dictionary to hold the key-value pairs
var arg_dict = {}
var i = 0
while i < args.size():
var key = args[i]
if key.begins_with("--"):
key = key.substr(2) # Remove '--' prefix
i += 1
if i < args.size():
arg_dict[key] = args[i]
i += 1
if args.size() < 8: # Adjust this number based on the expected number of arguments
print("Not enough arguments provided!")
# Check for all required arguments
var required_args = ["screens", "path", "appID", "volume", "check", "projectPackageFile"]
for req_arg in required_args:
if not arg_dict.has(req_arg):
print("Missing argument:", req_arg)
return false
# Parse the 'screens' argument
var activeScreensList = []
var screens_str = arg_dict["screens"]
if screens_str.begins_with("{") and screens_str.ends_with("}"):
screens_str = screens_str.substr(1, screens_str.length() - 2) # Remove '{' and '}'
var screens = screens_str.split(",")
for screen in screens:
if screen.is_valid_int():
activeScreensList.append(screen.to_int())
else:
print("Invalid screens argument:", screen)
return false
else:
print("Invalid format for screens argument")
return false
var activeScreensList = []
if args[0 + offset].is_valid_int():
activeScreensList.append(args[0 + offset].to_int())
else:
var potentialInts = args[0 + offset].split(",")
for val in potentialInts:
if not val.is_valid_int():
print("Invalid argument: Not an integer:", val)
return false
else:
activeScreensList.append(val.to_int())
screen_play_wallpaper.set_projectPath(args[1 + offset])
screen_play_wallpaper.set_appID(args[2 + offset].replace("appID=", ""))
screen_play_wallpaper.set_volume(float(args[3 + offset]))
#screen_play_wallpaper.set_fillmode(int(args[4 + offset]))
var type = args[5] # This might need further parsing depending on its expected format
screen_play_wallpaper.set_checkWallpaperVisible(args[6 + offset].to_lower() == "true")
# Assign the values to the respective properties
screen_play_wallpaper.set_projectPath(arg_dict["path"])
screen_play_wallpaper.set_appID(arg_dict["appID"])
screen_play_wallpaper.set_volume(float(arg_dict["volume"]))
screen_play_wallpaper.set_projectPackageFile(arg_dict["projectPackageFile"])
screen_play_wallpaper.set_checkWallpaperVisible(arg_dict["check"] == "1")
screen_play_wallpaper.set_activeScreensList(activeScreensList)
screen_play_wallpaper.set_projectPackageFile(args[7 + offset])
# Print or use the parsed values as needed
print("Parsing done:", activeScreensList, screen_play_wallpaper.get_projectPath(), screen_play_wallpaper.get_appID(), screen_play_wallpaper.get_volume(), type, screen_play_wallpaper.get_checkWallpaperVisible())
print("Parsing done: ", activeScreensList,
" ", screen_play_wallpaper.get_projectPath(),
" ", screen_play_wallpaper.get_appID(),
" ", screen_play_wallpaper.get_volume(),
" ", screen_play_wallpaper.get_projectPackageFile(),
" ", screen_play_wallpaper.get_checkWallpaperVisible())
return true

View File

@ -28,10 +28,6 @@ window/size/borderless=true
window/size/transparent=true
window/energy_saving/keep_screen_on=false
[editor]
run/main_run_args="\"1\" \"C:/Code/Cpp/ScreenPlay/ScreenPlay/Content/wallpaper_godot_fjord\" \"appID=test\" \"1\" \"Cover\" \"GodotWallpaper\" \"1\" \"project-v1.zip\""
[filesystem]
import/blender/enabled=false

View File

@ -38,6 +38,9 @@ int main(int argc, char* argv[])
#endif
QGuiApplication app(argc, argv);
QCoreApplication::setApplicationName("ScreenPlayWallpaper");
QCoreApplication::setApplicationVersion("1.0");
std::unique_ptr<const ScreenPlayUtil::LoggingHandler> logging;
std::unique_ptr<BaseWindow> window;
const auto platformName = QGuiApplication::platformName();
@ -56,11 +59,9 @@ int main(int argc, char* argv[])
// If we start with only one argument (app path)
// It means we want to test a single wallpaper
const QStringList argumentList = app.arguments();
QString appID;
// For testing purposes when starting the ScreenPlayWallpaper directly.
if (argumentList.length() == 1) {
QStringList argumentList;
if (app.arguments().length() == 1) {
QString exampleContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
QStringList contentFolder = {
"/wallpaper_html", // 0
@ -73,65 +74,112 @@ int main(int argc, char* argv[])
const int index = 5;
QString projectPath = exampleContentPath + contentFolder.at(index);
window->setActiveScreensList({ 0 });
window->setProjectPath(projectPath);
window->setAppID("test");
window->setVolume(1);
window->setFillMode("cover");
window->setType(ScreenPlay::ContentTypes::InstalledType::VideoWallpaper);
window->setCheckWallpaperVisible(true);
window->setDebugMode(false);
argumentList.append(
QStringList {
// Docs: Don't forget that arguments must start with the name of the executable (ignored, though).
QGuiApplication::applicationName(),
"--path", projectPath,
"--appID", "qmz9lq4wglox5DdYaXumVgRSDeZYAUjC",
"--screens", "{0}",
"--volume", "1",
"--fillmode", "Contain",
"--type", "VideoWallpaper",
"--check", "0" });
} else {
// 8 parameter + 1 OS working directory as the first default paramter
if (argumentList.length() != 9) {
return static_cast<int>(WallpaperExit::Code::Invalid_ArgumentSize);
}
ScreenPlay::Util util;
const auto activeScreensList = util.parseStringToIntegerList(argumentList.at(1));
if (!activeScreensList.has_value()) {
qCritical("Could not activeScreensList");
return static_cast<int>(WallpaperExit::Code::Invalid_ActiveScreensList);
}
auto installedType = ScreenPlay::ContentTypes::InstalledType::Unknown;
if (auto typeOpt = util.getInstalledTypeFromString(argumentList.at(6))) {
installedType = typeOpt.value();
} else {
qCritical() << "Cannot parse Wallpaper type from value" << argumentList.at(6);
return static_cast<int>(WallpaperExit::Code::Invalid_InstalledType);
}
bool okParseCheckWallpaperVisible = false;
const bool checkWallpaperVisible = argumentList.at(7).toInt(&okParseCheckWallpaperVisible);
if (!okParseCheckWallpaperVisible) {
qCritical("Could not parse checkWallpaperVisible");
return static_cast<int>(WallpaperExit::Code::Invalid_CheckWallpaperVisible);
}
bool okParseVolume = 0.0f;
const float volume = argumentList.at(4).toFloat(&okParseVolume);
if (!okParseVolume) {
qCritical("Could not parse Volume");
return static_cast<int>(WallpaperExit::Code::Invalid_Volume);
}
appID = argumentList.at(3);
if (!appID.startsWith("appID=")) {
qCritical("Invalid appID");
return static_cast<int>(WallpaperExit::Code::Invalid_AppID);
}
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);
argumentList = app.arguments();
}
QCommandLineParser parser;
parser.setApplicationDescription("ScreenPlay Wallpaper");
parser.addHelpOption();
// Define the command line options
QCommandLineOption pathOption("path", "Set the project path.", "path");
QCommandLineOption appIDOption("appID", "Set the application ID.", "appID");
QCommandLineOption screensOption("screens", "Set screens parameter.", "screens");
QCommandLineOption volumeOption("volume", "Set volume level.", "volume");
QCommandLineOption fillmodeOption("fillmode", "Set fill mode.", "fillmode");
QCommandLineOption typeOption("type", "Set the type.", "type");
QCommandLineOption checkOption("check", "Set check value.", "check");
// Add the options to the parser
parser.addOption(pathOption);
parser.addOption(appIDOption);
parser.addOption(screensOption);
parser.addOption(volumeOption);
parser.addOption(fillmodeOption);
parser.addOption(typeOption);
parser.addOption(checkOption);
// Process the actual command line arguments given by the user
parser.process(argumentList);
// Check if all required options are provided
if (!parser.isSet(pathOption)
|| !parser.isSet(appIDOption)
|| !parser.isSet(screensOption)
|| !parser.isSet(volumeOption)
|| !parser.isSet(fillmodeOption)
|| !parser.isSet(typeOption)
|| !parser.isSet(checkOption)) {
qCritical() << "Missing required arguments. Please provide all arguments."
<< argumentList
<< "pathOption" << parser.value(pathOption)
<< "appIDOption" << parser.value(appIDOption)
<< "typeOption" << parser.value(typeOption)
<< "volumeOption" << parser.value(volumeOption)
<< "fillmodeOption" << parser.value(fillmodeOption)
<< "typeOption" << parser.value(typeOption)
<< "checkOption" << parser.value(checkOption);
return -1;
}
QString path = parser.value(pathOption);
QString appID = parser.value(appIDOption);
QString screens = parser.value(screensOption);
QString volume = parser.value(volumeOption);
QString fillmode = parser.value(fillmodeOption);
QString type = parser.value(typeOption);
QString check = parser.value(checkOption);
ScreenPlay::Util util;
auto activeScreensList = util.parseStringToIntegerList(screens);
if (!activeScreensList.has_value()) {
qCritical() << "Could not parse activeScreensList" << screens;
return static_cast<int>(WallpaperExit::Code::Invalid_ActiveScreensList);
}
auto installedType = util.getInstalledTypeFromString(type);
if (!installedType.has_value()) {
qCritical() << "Cannot parse Wallpaper type from value" << type;
return static_cast<int>(WallpaperExit::Code::Invalid_InstalledType);
}
bool okParseCheckWallpaperVisible = false;
const bool checkWallpaperVisible = check.toInt(&okParseCheckWallpaperVisible);
if (!okParseCheckWallpaperVisible) {
qCritical("Could not parse checkWallpaperVisible");
return static_cast<int>(WallpaperExit::Code::Invalid_CheckWallpaperVisible);
}
bool okParseVolume = false;
const float volumeFloat = volume.toFloat(&okParseVolume);
if (!okParseVolume) {
qCritical("Could not parse Volume");
return static_cast<int>(WallpaperExit::Code::Invalid_Volume);
}
// Set the properties of the window object
window->setActiveScreensList(activeScreensList.value());
window->setProjectPath(path);
window->setAppID(appID);
window->setVolume(volumeFloat);
window->setFillMode(fillmode);
window->setType(installedType.value());
window->setCheckWallpaperVisible(checkWallpaperVisible);
window->setDebugMode(false);
const auto setupStatus = window->setup();
if (setupStatus != WallpaperExit::Code::Ok) {
return static_cast<int>(setupStatus);
@ -141,7 +189,7 @@ int main(int argc, char* argv[])
return static_cast<int>(startStatus);
}
emit window->qmlStart();
logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlayWallpaper_" + appID);
logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlayWallpaper_" + parser.value(appIDOption));
const int status = app.exec();
logging.reset();
return status;

View File

@ -8,6 +8,7 @@
#include <QStringList>
#include <QtWebEngineQuick>
#include "ScreenPlayUtil/contenttypes.h"
#include "ScreenPlayUtil/logginghandler.h"
#include "src/widgetwindow.h"
@ -36,62 +37,112 @@ int main(int argc, char* argv[])
QGuiApplication app(argc, argv);
std::unique_ptr<const ScreenPlayUtil::LoggingHandler> logging;
const QStringList argumentList = app.arguments();
QStringList argumentList;
// If we start with only one argument (path, appID, type),
// it means we want to test a single widget
if (argumentList.length() == 1) {
if (app.arguments().length() == 1) {
QString exampleContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
QStringList contentFolder = {
"/widget_weather", // 0
"/widget_system_stats", // 1 (Note: Windows only)
"/widget_hello_world", // 2
"/widget_year_count_down", // 3
"/widget_analog_clock", // 4
"/widget_digital_clock", // 5
"/widget_rss_hackernews", // 6
"/widget_rss_guardian_news", // 7
"/widget_xkcd" // 8
using namespace ScreenPlay;
QList<QPair<QString, ContentTypes::InstalledType>> contentFolder = {
{ "/widget_weather", ContentTypes::InstalledType::QMLWidget }, // 0
{ "/widget_system_stats", ContentTypes::InstalledType::QMLWidget }, // 1 (Note: Windows only)
{ "/widget_hello_world", ContentTypes::InstalledType::QMLWidget }, // 2
{ "/widget_year_count_down", ContentTypes::InstalledType::QMLWidget }, // 3
{ "/widget_analog_clock", ContentTypes::InstalledType::QMLWidget }, // 4
{ "/widget_digital_clock", ContentTypes::InstalledType::QMLWidget }, // 5
{ "/widget_rss_hackernews", ContentTypes::InstalledType::QMLWidget }, // 6
{ "/widget_rss_guardian_news", ContentTypes::InstalledType::QMLWidget }, // 7
{ "/widget_xkcd", ContentTypes::InstalledType::QMLWidget }, // 8
};
const int index = 5;
QString projectPath = exampleContentPath + contentFolder.at(index);
QString projectPath = exampleContentPath + contentFolder.at(index).first;
// Lets center the widget
const auto* screen = QGuiApplication::screens().at(0);
const int offset = -200;
QPoint center((screen->size().width() / 2) + offset, (screen->size().height() / 2) + offset);
const QPoint center((screen->size().width() / 2) + offset, (screen->size().height() / 2) + offset);
const QString type = QVariant::fromValue<ContentTypes::InstalledType>(contentFolder.at(index).second).toString();
WidgetWindow spwmw(projectPath,
"appid",
"qmlWidget",
center,
true);
return app.exec();
argumentList.append(
QStringList {
// Docs: Don't forget that arguments must start with the name of the executable (ignored, though).
QGuiApplication::applicationName(),
"--path", projectPath,
"--appID", "qmz9lq4wglox5DdYaXumVgRSDeZYAUjC",
"--type", type,
"--posX", QString::number(center.x()),
"--posY", QString::number(center.y()),
"--debug", "1" });
} else {
argumentList = app.arguments();
}
if (argumentList.length() != 6) {
return -3;
QCommandLineParser parser;
parser.setApplicationDescription("ScreenPlay Widget");
parser.addHelpOption();
QCommandLineOption pathOption("path", "Project path", "path");
QCommandLineOption appIDOption("appID", "Application ID", "appid");
QCommandLineOption typeOption("type", "Content type", "type");
QCommandLineOption posXOption("posX", "X position", "positionX");
QCommandLineOption posYOption("posY", "Y position", "positionY");
QCommandLineOption debugOption("debug", "debug enabled", "debug");
parser.addOption(pathOption);
parser.addOption(appIDOption);
parser.addOption(typeOption);
parser.addOption(posXOption);
parser.addOption(posYOption);
parser.addOption(debugOption);
parser.process(argumentList);
// Check if all required options are provided
// debug option is optional
if (!parser.isSet(pathOption)
|| !parser.isSet(appIDOption)
|| !parser.isSet(typeOption)
|| !parser.isSet(posXOption)
|| !parser.isSet(posYOption)) {
qCritical() << "Missing required arguments. Please provide all arguments."
<< argumentList
<< "pathOption" << parser.value(pathOption)
<< "appIDOption" << parser.value(appIDOption)
<< "typeOption" << parser.value(typeOption)
<< "posXOption" << parser.value(posXOption)
<< "posYOption" << parser.value(posYOption);
return -1;
}
bool okPosX = false;
int positionX = QVariant(argumentList.at(4)).toInt(&okPosX);
bool okPosX = false, okPosY = false;
const int positionX = parser.value(posXOption).toInt(&okPosX);
if (!okPosX) {
qWarning() << "Could not parse PositionX value to int: " << argumentList.at(4);
positionX = 0;
qWarning() << "Could not parse PositionX value to int: " << parser.value(posXOption);
return -1;
}
bool okPosY = false;
int positionY = QVariant(argumentList.at(5)).toInt(&okPosY);
const int positionY = parser.value(posYOption).toInt(&okPosY);
if (!okPosY) {
qWarning() << "Could not parse PositionY value to int: " << argumentList.at(5);
positionY = 0;
qWarning() << "Could not parse PositionY value to int: " << parser.value(posYOption);
return -1;
}
const QString appID = argumentList.at(2);
bool debugOk = false;
const int debug = parser.value(debugOption).toInt(&debugOk);
if (!debugOk) {
qWarning() << "Could not parse debugOk value to bool: " << parser.value(posYOption);
}
QString appID = parser.value(appIDOption);
QString projectPath = parser.value(pathOption);
QString type = parser.value(typeOption);
WidgetWindow spwmw(
argumentList.at(1), // Project path,
appID, // AppID
argumentList.at(3), // Type
QPoint { positionX, positionY });
projectPath,
appID,
type,
QPoint { positionX, positionY },
debug);
#if defined(Q_OS_MACOS)
MacUtils::showDockIcon(false);

View File

@ -150,12 +150,8 @@ def main():
else:
raise NotImplementedError("Unknown system: {}".format(system()))
if vcpkg_path.exists():
print(f"Deleting exisitng vcpkg: {vcpkg_path}")
shutil.rmtree(str(vcpkg_path))
print(f"Clone into {vcpkg_path}")
execute("git clone --depth 1 https://github.com/microsoft/vcpkg vcpkg",
execute("git clone https://github.com/microsoft/vcpkg vcpkg",
project_source_parent_path, True)
execute("git fetch", vcpkg_path)
execute(f"git checkout {defines.VCPKG_VERSION}", vcpkg_path)