2020-10-14 08:37:03 +08:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtWebSockets/QWebSocket>
|
|
|
|
#include <ppltasks.h>
|
|
|
|
#include "network.h"
|
|
|
|
|
|
|
|
using namespace Concurrency;
|
|
|
|
|
|
|
|
typedef std::map<long, task_completion_event<QJsonObject>> MapResponse;
|
2020-10-15 07:32:58 +08:00
|
|
|
typedef std::map<long, QJsonObject> MapMethod;
|
2020-10-14 08:37:03 +08:00
|
|
|
|
|
|
|
class DevTools : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit DevTools(QObject* parent = nullptr);
|
|
|
|
~DevTools();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2020-10-16 04:23:41 +08:00
|
|
|
void statusChanged(const QString&);
|
2020-10-14 08:37:03 +08:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void stateChanged(QAbstractSocket::SocketState state);
|
|
|
|
void onTextMessageReceived(QString message);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void startDevTools(QString path, bool headless = false, int port = 9222);
|
|
|
|
void closeDevTools();
|
2020-10-15 07:32:58 +08:00
|
|
|
bool checkMethod(long id);
|
2020-10-14 08:37:03 +08:00
|
|
|
int getSession();
|
2020-10-15 07:32:58 +08:00
|
|
|
bool SendRequest(QString method, QJsonObject params, QJsonObject& root);
|
2020-10-16 04:23:41 +08:00
|
|
|
long methodToReceive(QString method, QJsonObject params = {});
|
2020-10-14 08:37:03 +08:00
|
|
|
QString getStatus();
|
2020-10-18 21:16:06 +08:00
|
|
|
QString getUserAgent();
|
2020-10-14 08:37:03 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool isConnected();
|
|
|
|
bool startChrome(QString path, bool headless = false, int port = 9222);
|
2020-10-18 21:16:06 +08:00
|
|
|
bool GetJsonfromHTTP(QJsonDocument& doc, QString object, int port = 9222);
|
2020-10-14 08:37:03 +08:00
|
|
|
long idIncrement();
|
2020-10-15 07:32:58 +08:00
|
|
|
long idmIncrement();
|
2020-10-16 04:23:41 +08:00
|
|
|
bool compareJson(QJsonValue storedparams, QJsonValue params);
|
2020-10-14 08:37:03 +08:00
|
|
|
int session;
|
|
|
|
QWebSocket webSocket;
|
|
|
|
std::mutex mutex;
|
|
|
|
MapResponse mapqueue;
|
2020-10-15 07:32:58 +08:00
|
|
|
MapMethod mapmethod;
|
2020-10-14 08:37:03 +08:00
|
|
|
long idcounter;
|
2020-10-15 07:32:58 +08:00
|
|
|
long idmethod;
|
2020-10-14 08:37:03 +08:00
|
|
|
PROCESS_INFORMATION processInfo;
|
|
|
|
QString status;
|
2020-10-18 21:16:06 +08:00
|
|
|
QString useragent;
|
2020-10-14 08:37:03 +08:00
|
|
|
};
|