forked from quickshell/quickshell
core: add options to enable QML debugging
This commit is contained in:
parent
5a84e73442
commit
4e92d82992
|
@ -10,6 +10,7 @@
|
||||||
#include <qguiapplication.h>
|
#include <qguiapplication.h>
|
||||||
#include <qhash.h>
|
#include <qhash.h>
|
||||||
#include <qlogging.h>
|
#include <qlogging.h>
|
||||||
|
#include <qqmldebug.h>
|
||||||
#include <qquickwindow.h>
|
#include <qquickwindow.h>
|
||||||
#include <qstandardpaths.h>
|
#include <qstandardpaths.h>
|
||||||
#include <qstring.h>
|
#include <qstring.h>
|
||||||
|
@ -29,6 +30,9 @@ int qs_main(int argc, char** argv) {
|
||||||
auto desktopSettingsAware = true;
|
auto desktopSettingsAware = true;
|
||||||
QHash<QString, QString> envOverrides;
|
QHash<QString, QString> envOverrides;
|
||||||
|
|
||||||
|
int debugPort = -1;
|
||||||
|
bool waitForDebug = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto app = QCoreApplication(argc, argv);
|
const auto app = QCoreApplication(argc, argv);
|
||||||
QCoreApplication::setApplicationName("quickshell");
|
QCoreApplication::setApplicationName("quickshell");
|
||||||
|
@ -44,6 +48,8 @@ int qs_main(int argc, char** argv) {
|
||||||
auto configOption = QCommandLineOption({"c", "config"}, "Name of a configuration in the manifest.", "name");
|
auto configOption = QCommandLineOption({"c", "config"}, "Name of a configuration in the manifest.", "name");
|
||||||
auto pathOption = QCommandLineOption({"p", "path"}, "Path to a configuration file.", "path");
|
auto pathOption = QCommandLineOption({"p", "path"}, "Path to a configuration file.", "path");
|
||||||
auto workdirOption = QCommandLineOption({"d", "workdir"}, "Initial working directory.", "path");
|
auto workdirOption = QCommandLineOption({"d", "workdir"}, "Initial working directory.", "path");
|
||||||
|
auto debugPortOption = QCommandLineOption("debugport", "Enable the QML debugger.", "port");
|
||||||
|
auto debugWaitOption = QCommandLineOption("waitfordebug", "Wait for debugger connection before launching.");
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
parser.addOption(currentOption);
|
parser.addOption(currentOption);
|
||||||
|
@ -51,8 +57,30 @@ int qs_main(int argc, char** argv) {
|
||||||
parser.addOption(configOption);
|
parser.addOption(configOption);
|
||||||
parser.addOption(pathOption);
|
parser.addOption(pathOption);
|
||||||
parser.addOption(workdirOption);
|
parser.addOption(workdirOption);
|
||||||
|
parser.addOption(debugPortOption);
|
||||||
|
parser.addOption(debugWaitOption);
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
|
auto debugPortStr = parser.value(debugPortOption);
|
||||||
|
if (!debugPortStr.isEmpty()) {
|
||||||
|
auto ok = false;
|
||||||
|
debugPort = debugPortStr.toInt(&ok);
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
qCritical() << "Debug port must be a valid port number.";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(debugWaitOption)) {
|
||||||
|
if (debugPort == -1) {
|
||||||
|
qCritical() << "Cannot wait for debugger without a debug port set.";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDebug = true;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto printCurrent = parser.isSet(currentOption);
|
auto printCurrent = parser.isSet(currentOption);
|
||||||
|
|
||||||
|
@ -308,6 +336,13 @@ int qs_main(int argc, char** argv) {
|
||||||
app = new QGuiApplication(argc, argv);
|
app = new QGuiApplication(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debugPort != -1) {
|
||||||
|
QQmlDebuggingEnabler::enableDebugging(true);
|
||||||
|
auto wait = waitForDebug ? QQmlDebuggingEnabler::WaitForClient
|
||||||
|
: QQmlDebuggingEnabler::DoNotWaitForClient;
|
||||||
|
QQmlDebuggingEnabler::startTcpDebugServer(debugPort, wait);
|
||||||
|
}
|
||||||
|
|
||||||
if (!workingDirectory.isEmpty()) {
|
if (!workingDirectory.isEmpty()) {
|
||||||
QDir::setCurrent(workingDirectory);
|
QDir::setCurrent(workingDirectory);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue