diff --git a/app/cli/commandlineparser.cpp b/app/cli/commandlineparser.cpp index e09215f1..9cb1368e 100644 --- a/app/cli/commandlineparser.cpp +++ b/app/cli/commandlineparser.cpp @@ -546,7 +546,8 @@ void ListCommandLineParser::parse(const QStringList &args) parser.addPositionalArgument("list", "list available apps"); parser.addPositionalArgument("host", "Host computer name, UUID, or IP address", ""); - parser.addFlagOption("csv", "Print as CSV with additional information"); + parser.addFlagOption("csv", "Print as CSV with additional information"); + parser.addFlagOption("verbose", "Displays additional information"); if (!parser.parse(args)) { parser.showError(parser.errorText()); @@ -556,6 +557,7 @@ void ListCommandLineParser::parse(const QStringList &args) m_PrintCSV = parser.isSet("csv"); + m_Verbose = parser.isSet("verbose"); // This method will not return and terminates the process if --version or // --help is specified @@ -578,3 +580,8 @@ bool ListCommandLineParser::isPrintCSV() const { return m_PrintCSV; } + +bool ListCommandLineParser::isVerbose() const +{ + return m_Verbose; +} diff --git a/app/cli/commandlineparser.h b/app/cli/commandlineparser.h index 13201dad..0f68599f 100644 --- a/app/cli/commandlineparser.h +++ b/app/cli/commandlineparser.h @@ -84,8 +84,10 @@ public: QString getHost() const; bool isPrintCSV() const; + bool isVerbose() const; private: QString m_Host; bool m_PrintCSV; + bool m_Verbose; }; diff --git a/app/cli/listapps.cpp b/app/cli/listapps.cpp index 9b8ddbf4..7e82b435 100644 --- a/app/cli/listapps.cpp +++ b/app/cli/listapps.cpp @@ -54,7 +54,7 @@ public: NvApp app; switch (event.type) { - // Occurs when CliListAppsSegue becomes visible and the UI calls launcher's execute() + // Occurs when CLI main calls execute case Event::Executed: if (m_State == StateInit) { m_State = StateSeekComputer; @@ -72,14 +72,17 @@ public: m_BoxArtManager = new BoxArtManager(q); - emit q->searchingComputer(); + if (m_Arguments.isVerbose()) { + fprintf(stdout, "Establishing connection to PC...\n"); + } } break; // Occurs when computer search timed out case Event::ComputerSeekTimedout: if (m_State == StateSeekComputer) { - m_State = StateFailure; - emit q->failed(QString("Failed to connect to %1").arg(m_ComputerName)); + fprintf(stderr, "%s\n", qPrintable(QString("Failed to connect to %1").arg(m_ComputerName))); + + QCoreApplication::exit(-1); } break; // Occurs when searched computer is found @@ -89,20 +92,23 @@ public: m_State = StateSeekApp; m_Computer = event.computer; m_TimeoutTimer->start(APP_SEEK_TIMEOUT); - emit q->searchingApps(); + if (m_Arguments.isVerbose()) { + fprintf(stdout, "Loading app list...\n"); + } } else { m_State = StateFailure; - QString msg = QObject::tr("Computer %1 has not been paired. " - "Please open Moonlight to pair before retrieving games list.") - .arg(event.computer->name); - emit q->failed(msg); + fprintf(stderr, "%s\n", qPrintable(QObject::tr("Computer %1 has not been paired. " + "Please open Moonlight to pair before retrieving games list.") + .arg(event.computer->name))); + + QCoreApplication::exit(-1); } } break; // Occurs when a computer is updated case Event::ComputerUpdated: if (m_State == StateSeekApp) { - m_PrintCSV ? printAppsCSV(m_Computer->appList) : printApps(m_Computer->appList); + m_Arguments.isPrintCSV() ? printAppsCSV(m_Computer->appList) : printApps(m_Computer->appList); QCoreApplication::exit(0); } @@ -142,10 +148,10 @@ public: NvComputer *m_Computer; State m_State; QTimer *m_TimeoutTimer; - bool m_PrintCSV; + ListCommandLineParser m_Arguments; }; -Launcher::Launcher(QString computer, bool printCSV, QObject *parent) +Launcher::Launcher(QString computer, ListCommandLineParser arguments, QObject *parent) : QObject(parent), m_DPtr(new LauncherPrivate(this)) { @@ -154,7 +160,7 @@ Launcher::Launcher(QString computer, bool printCSV, QObject *parent) d->m_State = StateInit; d->m_TimeoutTimer = new QTimer(this); d->m_TimeoutTimer->setSingleShot(true); - d->m_PrintCSV = printCSV; + d->m_Arguments = arguments; connect(d->m_TimeoutTimer, &QTimer::timeout, this, &Launcher::onComputerSeekTimeout); } diff --git a/app/cli/listapps.h b/app/cli/listapps.h index b982a11a..a590d531 100644 --- a/app/cli/listapps.h +++ b/app/cli/listapps.h @@ -1,5 +1,7 @@ #pragma once +#include "commandlineparser.h" + #include #include @@ -17,17 +19,12 @@ class Launcher : public QObject Q_DECLARE_PRIVATE_D(m_DPtr, Launcher) public: - explicit Launcher(QString computer, bool printCSV, QObject *parent = nullptr); + explicit Launcher(QString computer, ListCommandLineParser arguments, QObject *parent = nullptr); ~Launcher(); Q_INVOKABLE void execute(ComputerManager *manager); Q_INVOKABLE bool isExecuted() const; -signals: - void searchingComputer(); - void searchingApps(); - void failed(QString text); - private slots: void onComputerFound(NvComputer *computer); void onComputerUpdated(NvComputer *computer); @@ -35,7 +32,7 @@ private slots: private: QScopedPointer m_DPtr; - bool m_Print_CSV; + ListCommandLineParser m_Arguments; }; } diff --git a/app/gui/CliListAppsSegue.qml b/app/gui/CliListAppsSegue.qml deleted file mode 100644 index 5bac64df..00000000 --- a/app/gui/CliListAppsSegue.qml +++ /dev/null @@ -1,57 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 2.2 - -import ComputerManager 1.0 -import Session 1.0 - -Item { - function onSearchingComputer() { - stageLabel.text = qsTr("Establishing connection to PC...") - } - - function onSearchingApps() { - stageLabel.text = qsTr("Loading app list...") - } - - function onFailure(message) { - errorDialog.text = message - errorDialog.open() - } - - StackView.onActivated: { - if (!launcher.isExecuted()) { - toolBar.visible = false - launcher.searchingComputer.connect(onSearchingComputer) - launcher.searchingComputer.connect(onSearchingApps) - launcher.failed.connect(onFailure) - launcher.execute(ComputerManager) - } - } - - Row { - anchors.centerIn: parent - spacing: 5 - - BusyIndicator { - id: stageSpinner - } - - Label { - id: stageLabel - height: stageSpinner.height - text: stageText - font.pointSize: 20 - verticalAlignment: Text.AlignVCenter - - wrapMode: Text.Wrap - } - } - - ErrorMessageDialog { - id: errorDialog - - onClosed: { - Qt.quit() - } - } -} diff --git a/app/main.cpp b/app/main.cpp index 72fae03a..40995be4 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -38,6 +38,7 @@ #include "gui/computermodel.h" #include "gui/appmodel.h" #include "backend/autoupdatechecker.h" +#include "backend/computermanager.h" #include "backend/systemproperties.h" #include "streaming/session.h" #include "settings/streamingpreferences.h" @@ -585,6 +586,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; QString initialView; + bool hasGUI = true; GlobalCommandLineParser parser; switch (parser.parse(app.arguments())) { @@ -623,21 +625,24 @@ int main(int argc, char *argv[]) } case GlobalCommandLineParser::ListRequested: { - initialView = "qrc:/gui/CliListAppsSegue.qml"; ListCommandLineParser listParser; listParser.parse(app.arguments()); - auto launcher = new CliListApps::Launcher(listParser.getHost(), listParser.isPrintCSV(), &app); - engine.rootContext()->setContextProperty("launcher", launcher); + auto launcher = new CliListApps::Launcher(listParser.getHost(), listParser, &app); + launcher->execute(new ComputerManager(&app)); + hasGUI = false; break; } } - engine.rootContext()->setContextProperty("initialView", initialView); + if (hasGUI) { + engine.rootContext()->setContextProperty("initialView", initialView); + + // Load the main.qml file + engine.load(QUrl(QStringLiteral("qrc:/gui/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + } - // Load the main.qml file - engine.load(QUrl(QStringLiteral("qrc:/gui/main.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; int err = app.exec(); // Give worker tasks time to properly exit. Fixes PendingQuitTask diff --git a/app/qml.qrc b/app/qml.qrc index 12b68622..5c2c369f 100644 --- a/app/qml.qrc +++ b/app/qml.qrc @@ -10,7 +10,6 @@ gui/NavigableToolButton.qml gui/NavigableItemDelegate.qml gui/NavigableMenuItem.qml - gui/CliListAppsSegue.qml gui/CliQuitStreamSegue.qml gui/CliStartStreamSegue.qml gui/AutoResizingComboBox.qml