fix: cleanly exit on shutdown (#5537)

Co-authored-by: Mm2PL <mm2pl+gh@kotmisia.pl>
Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
pajlada
2024-08-10 14:24:25 +02:00
committed by GitHub
parent daff83dde8
commit 74d65a345d
23 changed files with 134 additions and 65 deletions
+16 -1
View File
@@ -136,6 +136,21 @@ NativeMessagingServer::NativeMessagingServer()
{
}
NativeMessagingServer::~NativeMessagingServer()
{
if (!ipc::IpcQueue::remove("chatterino_gui"))
{
qCWarning(chatterinoNativeMessage) << "Failed to remove message queue";
}
this->thread.requestInterruption();
this->thread.quit();
// Most likely, the receiver thread will still wait for a message
if (!this->thread.wait(250))
{
this->thread.terminate();
}
}
void NativeMessagingServer::start()
{
this->thread.start();
@@ -161,7 +176,7 @@ void NativeMessagingServer::ReceiverThread::run()
return;
}
while (true)
while (!this->isInterruptionRequested())
{
auto buf = messageQueue->receive();
if (buf.isEmpty())
+1
View File
@@ -36,6 +36,7 @@ public:
NativeMessagingServer(NativeMessagingServer &&) = delete;
NativeMessagingServer &operator=(const NativeMessagingServer &) = delete;
NativeMessagingServer &operator=(NativeMessagingServer &&) = delete;
~NativeMessagingServer();
void start();
+24 -1
View File
@@ -105,6 +105,12 @@ bool isBroadcasterSoftwareActive()
break;
}
if (!p.waitForFinished(1000))
{
qCWarning(chatterinoStreamerMode) << "Force-killing pgrep";
p.kill();
}
return false;
#elif defined(Q_OS_WIN)
if (!IsWindowsVistaOrGreater())
@@ -160,6 +166,8 @@ public:
[[nodiscard]] bool isEnabled() const;
void start();
private:
void settingChanged(StreamerModeSetting value);
void setEnabled(bool enabled);
@@ -194,9 +202,15 @@ bool StreamerMode::isEnabled() const
return this->private_->isEnabled();
}
void StreamerMode::start()
{
this->private_->start();
}
StreamerModePrivate::StreamerModePrivate(StreamerMode *parent)
: parent_(parent)
{
this->thread_.setObjectName("StreamerMode");
this->timer_.moveToThread(&this->thread_);
QObject::connect(&this->timer_, &QTimer::timeout, [this] {
auto timeouts =
@@ -221,13 +235,22 @@ StreamerModePrivate::StreamerModePrivate(StreamerMode *parent)
QObject::connect(&this->thread_, &QThread::started, [this] {
this->settingChanged(getSettings()->enableStreamerMode.getEnum());
});
}
void StreamerModePrivate::start()
{
this->thread_.start();
}
StreamerModePrivate::~StreamerModePrivate()
{
this->thread_.quit();
this->thread_.wait(50);
if (!this->thread_.wait(500))
{
qCWarning(chatterinoStreamerMode)
<< "Failed waiting for thread, terminating it";
this->thread_.terminate();
}
}
bool StreamerModePrivate::isEnabled() const
+4
View File
@@ -20,6 +20,8 @@ public:
[[nodiscard]] virtual bool isEnabled() const = 0;
virtual void start() = 0;
signals:
void changed(bool enabled);
};
@@ -37,6 +39,8 @@ public:
bool isEnabled() const override;
void start() override;
private:
void updated(bool enabled);