mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-01 23:35:55 +00:00
Add CLI pairing support
This commit is contained in:
parent
692942e5be
commit
aaf59c2d01
@ -132,6 +132,7 @@ macx {
|
|||||||
SOURCES += \
|
SOURCES += \
|
||||||
backend/nvaddress.cpp \
|
backend/nvaddress.cpp \
|
||||||
backend/nvapp.cpp \
|
backend/nvapp.cpp \
|
||||||
|
cli/pair.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
backend/computerseeker.cpp \
|
backend/computerseeker.cpp \
|
||||||
backend/identitymanager.cpp \
|
backend/identitymanager.cpp \
|
||||||
@ -170,6 +171,7 @@ SOURCES += \
|
|||||||
HEADERS += \
|
HEADERS += \
|
||||||
backend/nvaddress.h \
|
backend/nvaddress.h \
|
||||||
backend/nvapp.h \
|
backend/nvapp.h \
|
||||||
|
cli/pair.h \
|
||||||
settings/compatfetcher.h \
|
settings/compatfetcher.h \
|
||||||
settings/mappingfetcher.h \
|
settings/mappingfetcher.h \
|
||||||
utils.h \
|
utils.h \
|
||||||
|
@ -166,6 +166,7 @@ GlobalCommandLineParser::ParseResult GlobalCommandLineParser::parse(const QStrin
|
|||||||
"Available actions:\n"
|
"Available actions:\n"
|
||||||
" quit Quit the currently running app\n"
|
" quit Quit the currently running app\n"
|
||||||
" stream Start streaming an app\n"
|
" stream Start streaming an app\n"
|
||||||
|
" pair Pair a new host\n"
|
||||||
"\n"
|
"\n"
|
||||||
"See 'moonlight <action> --help' for help of specific action."
|
"See 'moonlight <action> --help' for help of specific action."
|
||||||
);
|
);
|
||||||
@ -193,6 +194,8 @@ GlobalCommandLineParser::ParseResult GlobalCommandLineParser::parse(const QStrin
|
|||||||
return QuitRequested;
|
return QuitRequested;
|
||||||
} else if (action == "stream") {
|
} else if (action == "stream") {
|
||||||
return StreamRequested;
|
return StreamRequested;
|
||||||
|
} else if (action == "pair") {
|
||||||
|
return PairRequested;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +245,58 @@ QString QuitCommandLineParser::getHost() const
|
|||||||
return m_Host;
|
return m_Host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PairCommandLineParser::PairCommandLineParser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PairCommandLineParser::~PairCommandLineParser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PairCommandLineParser::parse(const QStringList &args)
|
||||||
|
{
|
||||||
|
CommandLineParser parser;
|
||||||
|
parser.setupCommonOptions();
|
||||||
|
parser.setApplicationDescription(
|
||||||
|
"\n"
|
||||||
|
"Pair with the specified host."
|
||||||
|
);
|
||||||
|
parser.addPositionalArgument("pair", "pair host");
|
||||||
|
parser.addPositionalArgument("host", "Host computer name, UUID, or IP address", "<host>");
|
||||||
|
parser.addValueOption("pin", "4 digit pairing PIN");
|
||||||
|
|
||||||
|
if (!parser.parse(args)) {
|
||||||
|
parser.showError(parser.errorText());
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.handleUnknownOptions();
|
||||||
|
|
||||||
|
// This method will not return and terminates the process if --version or
|
||||||
|
// --help is specified
|
||||||
|
parser.handleHelpAndVersionOptions();
|
||||||
|
|
||||||
|
// Verify that host has been provided
|
||||||
|
auto posArgs = parser.positionalArguments();
|
||||||
|
if (posArgs.length() < 2) {
|
||||||
|
parser.showError("Host not provided");
|
||||||
|
}
|
||||||
|
m_Host = parser.positionalArguments().at(1);
|
||||||
|
m_PredefinedPin = parser.value("pin");
|
||||||
|
if (!m_PredefinedPin.isEmpty() && m_PredefinedPin.length() != 4) {
|
||||||
|
parser.showError("PIN must be 4 digits");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PairCommandLineParser::getHost() const
|
||||||
|
{
|
||||||
|
return m_Host;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PairCommandLineParser::getPredefinedPin() const
|
||||||
|
{
|
||||||
|
return m_PredefinedPin;
|
||||||
|
}
|
||||||
|
|
||||||
StreamCommandLineParser::StreamCommandLineParser()
|
StreamCommandLineParser::StreamCommandLineParser()
|
||||||
{
|
{
|
||||||
m_WindowModeMap = {
|
m_WindowModeMap = {
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
NormalStartRequested,
|
NormalStartRequested,
|
||||||
StreamRequested,
|
StreamRequested,
|
||||||
QuitRequested,
|
QuitRequested,
|
||||||
|
PairRequested,
|
||||||
};
|
};
|
||||||
|
|
||||||
GlobalCommandLineParser();
|
GlobalCommandLineParser();
|
||||||
@ -35,6 +36,22 @@ private:
|
|||||||
QString m_Host;
|
QString m_Host;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PairCommandLineParser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PairCommandLineParser();
|
||||||
|
virtual ~PairCommandLineParser();
|
||||||
|
|
||||||
|
void parse(const QStringList &args);
|
||||||
|
|
||||||
|
QString getHost() const;
|
||||||
|
QString getPredefinedPin() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_Host;
|
||||||
|
QString m_PredefinedPin;
|
||||||
|
};
|
||||||
|
|
||||||
class StreamCommandLineParser
|
class StreamCommandLineParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
91
app/gui/CliPair.qml
Normal file
91
app/gui/CliPair.qml
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Controls 2.2
|
||||||
|
|
||||||
|
import ComputerManager 1.0
|
||||||
|
import SdlGamepadKeyNavigation 1.0
|
||||||
|
|
||||||
|
Item {
|
||||||
|
function onSearchingComputer() {
|
||||||
|
stageLabel.text = qsTr("Establishing connection to PC...")
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPairing(pcName, pin) {
|
||||||
|
stageLabel.text = qsTr("Pairing... Please enter '%1' on %2.").arg(pin).arg(pcName)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFailed(message) {
|
||||||
|
stageIndicator.visible = false
|
||||||
|
errorDialog.text = message
|
||||||
|
errorDialog.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSuccess(appName) {
|
||||||
|
stageIndicator.visible = false
|
||||||
|
pairCompleteDialog.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow user to back out of pairing
|
||||||
|
Keys.onEscapePressed: {
|
||||||
|
Qt.quit()
|
||||||
|
}
|
||||||
|
Keys.onBackPressed: {
|
||||||
|
Qt.quit()
|
||||||
|
}
|
||||||
|
Keys.onCancelPressed: {
|
||||||
|
Qt.quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
StackView.onActivated: {
|
||||||
|
if (!launcher.isExecuted()) {
|
||||||
|
toolBar.visible = false
|
||||||
|
|
||||||
|
// Normally this is enabled by PcView, but we will won't
|
||||||
|
// load PcView when streaming from the command-line.
|
||||||
|
SdlGamepadKeyNavigation.enable()
|
||||||
|
|
||||||
|
launcher.searchingComputer.connect(onSearchingComputer)
|
||||||
|
launcher.pairing.connect(onPairing)
|
||||||
|
launcher.failed.connect(onFailed)
|
||||||
|
launcher.success.connect(onSuccess)
|
||||||
|
launcher.execute(ComputerManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: 5
|
||||||
|
id: stageIndicator
|
||||||
|
|
||||||
|
BusyIndicator {
|
||||||
|
id: stageSpinner
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
id: stageLabel
|
||||||
|
height: stageSpinner.height
|
||||||
|
font.pointSize: 20
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
|
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorMessageDialog {
|
||||||
|
id: errorDialog
|
||||||
|
|
||||||
|
onClosed: {
|
||||||
|
Qt.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigableMessageDialog {
|
||||||
|
id: pairCompleteDialog
|
||||||
|
closePolicy: Popup.CloseOnEscape
|
||||||
|
|
||||||
|
text:qsTr("Pairing completed successfully")
|
||||||
|
standardButtons: Dialog.Ok
|
||||||
|
onClosed: {
|
||||||
|
Qt.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
app/main.cpp
10
app/main.cpp
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "cli/quitstream.h"
|
#include "cli/quitstream.h"
|
||||||
#include "cli/startstream.h"
|
#include "cli/startstream.h"
|
||||||
|
#include "cli/pair.h"
|
||||||
#include "cli/commandlineparser.h"
|
#include "cli/commandlineparser.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -610,6 +611,15 @@ int main(int argc, char *argv[])
|
|||||||
engine.rootContext()->setContextProperty("launcher", launcher);
|
engine.rootContext()->setContextProperty("launcher", launcher);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case GlobalCommandLineParser::PairRequested:
|
||||||
|
{
|
||||||
|
initialView = "qrc:/gui/CliPair.qml";
|
||||||
|
PairCommandLineParser pairParser;
|
||||||
|
pairParser.parse(app.arguments());
|
||||||
|
auto launcher = new CliPair::Launcher(pairParser.getHost(), pairParser.getPredefinedPin(), &app);
|
||||||
|
engine.rootContext()->setContextProperty("launcher", launcher);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("initialView", initialView);
|
engine.rootContext()->setContextProperty("initialView", initialView);
|
||||||
|
@ -18,5 +18,6 @@
|
|||||||
<file>gui/NavigableMessageDialog.qml</file>
|
<file>gui/NavigableMessageDialog.qml</file>
|
||||||
<file>gui/NavigableDialog.qml</file>
|
<file>gui/NavigableDialog.qml</file>
|
||||||
<file>gui/CenteredGridView.qml</file>
|
<file>gui/CenteredGridView.qml</file>
|
||||||
|
<file>gui/CliPair.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user