mirror-chatterino2/src/singletons/NativeMessaging.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.6 KiB
C++
Raw Normal View History

2018-04-09 22:59:19 +02:00
#pragma once
#include "common/Atomic.hpp"
#include <QString>
#include <QThread>
#include <optional>
#include <vector>
2018-09-17 12:51:16 +02:00
namespace chatterino {
2018-08-02 14:23:27 +02:00
class Application;
class Paths;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
void registerNmHost(const Paths &paths);
std::string &getNmQueueName(const Paths &paths);
Atomic<std::optional<QString>> &nmIpcError();
namespace nm::client {
2018-08-02 14:23:27 +02:00
void sendMessage(const QByteArray &array);
void writeToCout(const QByteArray &array);
} // namespace nm::client
2018-08-02 14:23:27 +02:00
class NativeMessagingServer final
{
public:
NativeMessagingServer();
NativeMessagingServer(const NativeMessagingServer &) = delete;
NativeMessagingServer(NativeMessagingServer &&) = delete;
NativeMessagingServer &operator=(const NativeMessagingServer &) = delete;
NativeMessagingServer &operator=(NativeMessagingServer &&) = delete;
2018-08-02 14:23:27 +02:00
void start();
2018-08-02 14:23:27 +02:00
private:
2018-04-09 22:59:19 +02:00
class ReceiverThread : public QThread
{
public:
ReceiverThread(NativeMessagingServer &parent);
2018-04-09 22:59:19 +02:00
void run() override;
private:
void handleMessage(const QJsonObject &root);
void handleSelect(const QJsonObject &root);
void handleDetach(const QJsonObject &root);
void handleSync(const QJsonObject &root);
NativeMessagingServer &parent_;
2018-04-09 22:59:19 +02:00
};
void syncChannels(const QJsonArray &twitchChannels);
2018-08-02 14:23:27 +02:00
ReceiverThread thread;
/// This vector contains all channels that are open the user's browser.
/// These channels are joined to be able to switch channels more quickly.
std::vector<ChannelPtr> channelWarmer_;
friend ReceiverThread;
2018-04-09 22:59:19 +02:00
};
2018-04-09 22:59:19 +02:00
} // namespace chatterino