Refactor Native Messages (#4738)

* refactor: move ipc queue into its own class

* refactor: move windows.h related functions to AW

* refactor: make NM-Client methods static

* refactor: json access

* refactor: use struct initializer

* refactor: move `handleMessage` to anon-namespace

* refactor: clean-up includes

* refactor: move action handler to functions

* refactor: cleanup `handleSelect`

* fix: cleanup clang-tidy warnings

* chore: simplify json

* revert: keep handlers as methods

This is more readable and extensible.

* fix: typo

* fix: namespace

* fix: rename define

* refactor: `IpcQueue` to be simpler

* fix: rename cmake option

* fix: use variant when constructing

* fix: make it a ref

* fix: its a pair now
This commit is contained in:
nerix
2023-07-30 13:14:58 +02:00
committed by GitHub
parent c496a68633
commit 378aee7ab1
9 changed files with 301 additions and 186 deletions
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include <memory>
#include <utility>
class QByteArray;
class QString;
namespace chatterino::ipc {
void sendMessage(const char *name, const QByteArray &data);
class IpcQueuePrivate;
class IpcQueue
{
public:
~IpcQueue();
static std::pair<std::unique_ptr<IpcQueue>, QString> tryReplaceOrCreate(
const char *name, size_t maxMessages, size_t maxMessageSize);
// TODO: use std::expected
/// Try to receive a message.
/// In the case of an error, the buffer is empty.
QByteArray receive();
private:
IpcQueue(IpcQueuePrivate *priv);
std::unique_ptr<IpcQueuePrivate> private_;
friend class IpcQueuePrivate;
};
} // namespace chatterino::ipc