diff --git a/src/main.cpp b/src/main.cpp index 2b6b4ed7..36c1998f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include "application.hpp" +#include "singletons/nativemessagingmanager.hpp" #include "singletons/pathmanager.hpp" +#include "util/networkmanager.hpp" #include #include @@ -7,20 +9,17 @@ #include #include -#include - -#include "util/networkmanager.hpp" - #ifdef USEWINSDK #include "util/nativeeventhelper.hpp" #endif -#include "fstream" +#include +#include #ifdef Q_OS_WIN -#include "fcntl.h" -#include "io.h" -#include "stdio.h" +#include +#include +#include #endif void runNativeMessagingHost(); @@ -90,15 +89,6 @@ int runGui(int argc, char *argv[]) _exit(0); } -void writeByteArray(QByteArray a) -{ - char *data = a.data(); - uint32_t size; - size = a.size(); - std::cout.write(reinterpret_cast(&size), 4); - std::cout.write(data, a.size()); -} - void runNativeMessagingHost() { #ifdef Q_OS_WIN @@ -106,7 +96,9 @@ void runNativeMessagingHost() _setmode(_fileno(stdout), _O_BINARY); #endif - // std::ofstream xd("C:\\users\\daniel\\desktop\\xd.lmao"); + std::ofstream xD("C:\Users\daniel\Desktop\1"); + + auto &nmm = chatterino::singletons::NativeMessagingManager::getInstance(); while (true) { char size_c[4]; @@ -122,11 +114,12 @@ void runNativeMessagingHost() std::cin.read(b, size); *(b + size) = '\0'; - // xd << b; - // xd.flush(); + nmm.writeByteArray("{\"a\":1}"); + + nmm.sendToGuiProcess(QByteArray(b, size)); + + nmm.writeByteArray("{\"a\":2}"); free(b); - - // writeByteArray(QString("{\"xd\":1}").toUtf8()); } } diff --git a/src/singletons/nativemessagingmanager.cpp b/src/singletons/nativemessagingmanager.cpp index 4cad0e9d..c0c22a4d 100644 --- a/src/singletons/nativemessagingmanager.cpp +++ b/src/singletons/nativemessagingmanager.cpp @@ -8,17 +8,14 @@ #include #include -//#ifdef USEWINSDK -//#include -//#pragma comment(lib, "Advapi32.lib") -//#endif - #include #ifdef Q_OS_WIN #include #endif +#include + #define EXTENSION_ID "aeicjepmjkgmbeohnchmpfjbpchogmjn" #define MESSAGE_SIZE 1024 @@ -37,6 +34,16 @@ NativeMessagingManager &NativeMessagingManager::getInstance() return manager; } +void NativeMessagingManager::writeByteArray(QByteArray a) +{ + char *data = a.data(); + uint32_t size; + size = a.size(); + std::cout.write(reinterpret_cast(&size), 4); + std::cout.write(data, a.size()); + std::cout.flush(); +} + void NativeMessagingManager::registerHost() { // create manifest @@ -61,11 +68,13 @@ void NativeMessagingManager::registerHost() file.write(document.toJson()); file.flush(); +#ifdef XD #ifdef Q_OS_WIN // clang-format off QProcess::execute("REG ADD \"HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.chatterino.chatterino\" /ve /t REG_SZ /d \"" + manifestPath + "\" /f"); // clang-format on #endif +#endif } void NativeMessagingManager::openGuiMessageQueue() @@ -86,7 +95,7 @@ void NativeMessagingManager::sendToGuiProcess(const QByteArray &array) try { messageQueue.try_send(array.data(), array.size(), 1); } catch (ipc::interprocess_exception &ex) { - // rip + qDebug() << "send to gui process:" << ex.what(); } } @@ -107,7 +116,7 @@ void NativeMessagingManager::ReceiverThread::run() QString text = QString::fromUtf8(buf, retSize); qDebug() << text; } catch (ipc::interprocess_exception &ex) { - // rip + qDebug() << "received from gui process:" << ex.what(); } } } diff --git a/src/singletons/nativemessagingmanager.hpp b/src/singletons/nativemessagingmanager.hpp index be010b9c..96908f52 100644 --- a/src/singletons/nativemessagingmanager.hpp +++ b/src/singletons/nativemessagingmanager.hpp @@ -18,6 +18,7 @@ public: void run() override; }; + void writeByteArray(QByteArray a); void registerHost(); void openGuiMessageQueue(); void sendToGuiProcess(const QByteArray &array);