Textractor/extensions/devtools.h
zeheyler 6b54ec0733 add devtools api and new deepl extension
Added the DevTools API and the wrapper with  the use of the QtWebSockets library.
Added a new DeepL extension which uses the DevTools API.
2020-10-14 03:37:03 +03:00

49 lines
1.2 KiB
C++

#include <fstream>
#include <QtCore>
#include <QtWebSockets/QWebSocket>
#include <ppltasks.h>
#include "network.h"
using namespace Concurrency;
typedef std::map<long, task_completion_event<QJsonObject>> MapResponse;
class DevTools : public QObject {
Q_OBJECT
public:
explicit DevTools(QObject* parent = nullptr);
~DevTools();
Q_SIGNALS:
void statusChanged(const QString &);
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();
void setNavigated(bool value);
bool getNavigated();
void setTranslate(bool value);
bool getTranslate();
int getSession();
bool SendRequest(QString command, QJsonObject params, QJsonObject& result);
QString getStatus();
private:
bool isConnected();
bool startChrome(QString path, bool headless = false, int port = 9222);
bool GetwebSocketDebuggerUrl(QString& url, int port = 9222);
long idIncrement();
int session;
QWebSocket webSocket;
std::mutex mutex;
MapResponse mapqueue;
bool pagenavigated;
bool translateready;
long idcounter;
PROCESS_INFORMATION processInfo;
QString status;
};