diff --git a/Telegram/SourceFiles/ayu/libs/pipe.hpp b/Telegram/SourceFiles/ayu/libs/pipe.hpp index aef24ffd1..4f4a0b981 100644 --- a/Telegram/SourceFiles/ayu/libs/pipe.hpp +++ b/Telegram/SourceFiles/ayu/libs/pipe.hpp @@ -138,7 +138,7 @@ public: { native_mode = mode & std::ios_base::in ? PIPE_ACCESS_INBOUND : PIPE_ACCESS_OUTBOUND; - handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, 1, buf_size, buf_size, 0, nullptr); + handle = CreateNamedPipeW(std::data(native_name), native_mode, PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, buf_size, buf_size, 0, nullptr); if(handle == INVALID_HANDLE_VALUE) return false; diff --git a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp index 01cd2e039..ebe5a6492 100644 --- a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp +++ b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp @@ -43,19 +43,27 @@ namespace AyuSync { if (!isAgentRunning()) { auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json"); - auto process = nes::process{AgentPath, {configPath.string()}}; + auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none}; process.detach(); } - pipe = std::make_unique(); - std::thread receiverThread(&ayu_sync_controller::receiver, this); + receiverThread.detach(); } void ayu_sync_controller::receiver() { + pipe = std::make_unique(); + while (true) { auto p = pipe->receive(); - invokeHandler(p); + if (p == std::nullopt) { + continue; + } + + std::string s = p->dump(); + LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s))); + + invokeHandler(p.value()); } } diff --git a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h index a9dd95e72..bdc1cf1d7 100644 --- a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h +++ b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h @@ -14,9 +14,9 @@ using json = nlohmann::json; const std::string AgentFilename = #ifdef _WIN32 - "AyuSyncAgent.exe"; + "AyuSync.Agent.exe"; #else - "AyuSyncAgent"; + "AyuSync.Agent"; #endif const std::string AgentPath = "./AyuSync/" + AgentFilename; diff --git a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp index 4db9937b2..d092cf006 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp +++ b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp @@ -11,22 +11,31 @@ template void ayu_pipe_wrapper::send(T obj) { - auto s = json(obj).dump(); - auto length = s.length(); - char lengthBuff[4]; - bit_converter::i32_to_bytes(length, false, lengthBuff); - - os.write(lengthBuff, 4); - os.write(s.c_str(), length); - os.flush(); +// auto s = json(obj).dump(); +// auto length = s.length(); +// char lengthBuff[4]; +// bit_converter::i32_to_bytes(length, false, lengthBuff); +// +// os.write(lengthBuff, 4); +// os.write(s.c_str(), length); +// os.flush(); + throw std::logic_error("not implemented"); } -json ayu_pipe_wrapper::receive() { +std::optional ayu_pipe_wrapper::receive() { + if (!is.is_open()) { + return std::nullopt; + } + char lengthBuff[4]; is.read(lengthBuff, 4); auto length = bit_converter::bytes_to_i32(lengthBuff, false); + if (length <= 0) { + return std::nullopt; + } + auto sb = std::stringbuf(); char buff[4096]; diff --git a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h index 04957cf4e..e1602fea2 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h +++ b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h @@ -18,9 +18,8 @@ public: template void send(T obj); - json receive(); + std::optional receive(); private: - nes::basic_pipe_istream is{"AyuSync"}; - nes::basic_pipe_ostream os{"AyuSync"}; + nes::pipe_istream is{"AyuSync"}; }; diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 20ff89bc8..339e2ad44 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -414,6 +414,8 @@ namespace Settings { AddSkip(container); SetupAyuSync(container); + AddDivider(container); + AddSkip(container); SetupBetaFunctions(container);