Avoid GUI display for App listing

This commit is contained in:
Anselm Busse 2021-04-04 10:43:21 +02:00 committed by Cameron Gutman
parent 0802609fd8
commit 4ee36fd405
7 changed files with 46 additions and 87 deletions

View File

@ -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", "<host>");
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;
}

View File

@ -84,8 +84,10 @@ public:
QString getHost() const;
bool isPrintCSV() const;
bool isVerbose() const;
private:
QString m_Host;
bool m_PrintCSV;
bool m_Verbose;
};

View File

@ -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);
}

View File

@ -1,5 +1,7 @@
#pragma once
#include "commandlineparser.h"
#include <QObject>
#include <QVariant>
@ -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<LauncherPrivate> m_DPtr;
bool m_Print_CSV;
ListCommandLineParser m_Arguments;
};
}

View File

@ -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()
}
}
}

View File

@ -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

View File

@ -10,7 +10,6 @@
<file>gui/NavigableToolButton.qml</file>
<file>gui/NavigableItemDelegate.qml</file>
<file>gui/NavigableMenuItem.qml</file>
<file>gui/CliListAppsSegue.qml</file>
<file>gui/CliQuitStreamSegue.qml</file>
<file>gui/CliStartStreamSegue.qml</file>
<file>gui/AutoResizingComboBox.qml</file>