Showing the changes to interface/src/scripting/ScreenshareScriptingInterface.cpp (1 of 22 files). Show all
Unified · Split
| @@ -0,0 +1,70 @@ | ||
| 1 | +// | |
| 2 | +// ScreenshareScriptingInterface.cpp | |
| 3 | +// interface/src/scripting/ | |
| 4 | +// | |
| 5 | +// Created by Milad Nazeri on 2019-10-23. | |
| 6 | +// Copyright 2019 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include "ScreenshareScriptingInterface.h" | |
| 13 | +#include <QProcess> | |
| 14 | +#include <QThread> | |
| 15 | +#include <QDesktopServices> | |
| 16 | +#include <QUrl> | |
| 17 | +#include <QCoreApplication> | |
| 18 | + | |
| 19 | + | |
| 20 | +ScreenshareScriptingInterface::ScreenshareScriptingInterface() { | |
| 21 | + | |
| 22 | +}; | |
| 23 | + | |
| 24 | +void ScreenshareScriptingInterface::startScreenshare(QString displayName, QString userName, QString token, QString sessionID, QString apiKey, QString fileLocation) { | |
| 25 | + if (QThread::currentThread() != thread()) { | |
| 26 | + // We must start a new QProcess from the main thread. | |
| 27 | + QMetaObject::invokeMethod( | |
| 28 | + this, "startScreenshare", | |
| 29 | + Q_ARG(QString, displayName), | |
| 30 | + Q_ARG(QString, userName), | |
| 31 | + Q_ARG(QString, token), | |
| 32 | + Q_ARG(QString, sessionID), | |
| 33 | + Q_ARG(QString, apiKey), | |
| 34 | + Q_ARG(QString, fileLocation) | |
| 35 | + ); | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 39 | + qDebug() << "ZRF: Inside startScreenshare(). `SCREENSHARE_EXE_PATH`:" << SCREENSHARE_EXE_PATH; | |
| 40 | + | |
| 41 | + if (displayName.isEmpty() || userName.isEmpty() || token.isEmpty() || sessionID.isEmpty() || apiKey.isEmpty()) { | |
| 42 | + qDebug() << "Screenshare executable can't launch without connection info."; | |
| 43 | + return; | |
| 44 | + } | |
| 45 | + | |
| 46 | + QStringList arguments; | |
| 47 | + arguments << "--userName=" + userName; | |
| 48 | + arguments << "--displayName=" + displayName; | |
| 49 | + arguments << "--token=" + token; | |
| 50 | + arguments << "--apiKey=" + apiKey; | |
| 51 | + arguments << "--sessionID=" + sessionID; | |
| 52 | + | |
| 53 | + QProcess* electronProcess = new QProcess(this); | |
| 54 | + | |
| 55 | + connect(electronProcess, &QProcess::errorOccurred, | |
| 56 | + [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); | |
| 57 | + connect(electronProcess, &QProcess::started, [=]() { qDebug() << "ZRF QProcess::started"; }); | |
| 58 | + connect(electronProcess, &QProcess::stateChanged, | |
| 59 | + [=](QProcess::ProcessState newState) { qDebug() << "ZRF QProcess::stateChanged. `newState`:" << newState; }); | |
| 60 | + connect(electronProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | |
| 61 | + [=](int exitCode, QProcess::ExitStatus exitStatus) { | |
| 62 | + qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus; | |
| 63 | + }); | |
| 64 | + | |
| 65 | + // Note for Milad: | |
| 66 | + // We'll have to have equivalent lines of code for MacOS. | |
| 67 | +#ifdef Q_OS_WIN | |
| 68 | + electronProcess->start(fileLocation, arguments); | |
| 69 | +#endif | |
| 70 | +}; | |