Sync channels with browser (#4741)

* feat: keep channels from browser tabs alive

* chore: add changelog entry

* fix: add comment

* fix: rename key

---------

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2023-08-05 14:23:26 +02:00
committed by GitHub
parent 9e2eb0dd29
commit 1438529e98
3 changed files with 74 additions and 0 deletions
+24
View File
@@ -6,10 +6,15 @@
#include <QString>
#include <QThread>
#include <vector>
namespace chatterino {
class Application;
class Paths;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
void registerNmHost(Paths &paths);
std::string &getNmQueueName(Paths &paths);
@@ -26,21 +31,40 @@ namespace nm::client {
class NativeMessagingServer final
{
public:
NativeMessagingServer();
NativeMessagingServer(const NativeMessagingServer &) = delete;
NativeMessagingServer(NativeMessagingServer &&) = delete;
NativeMessagingServer &operator=(const NativeMessagingServer &) = delete;
NativeMessagingServer &operator=(NativeMessagingServer &&) = delete;
void start();
private:
class ReceiverThread : public QThread
{
public:
ReceiverThread(NativeMessagingServer &parent);
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_;
};
void syncChannels(const QJsonArray &twitchChannels);
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;
};
} // namespace chatterino