fix: make ipc connection a singleton (#2069)

This commit is contained in:
Yaroslav Gurov
2025-12-16 16:05:31 +01:00
committed by GitHub
parent f50817c43c
commit 8f508783e3
5 changed files with 67 additions and 143 deletions

View File

@@ -91,17 +91,8 @@ void Logger::deInit()
bool Logger::setServiceLogsEnabled(bool enabled)
{
#ifdef AMNEZIA_DESKTOP
IpcClient *m_IpcClient = new IpcClient;
if (!m_IpcClient->isSocketConnected()) {
if (!IpcClient::init(m_IpcClient)) {
qWarning() << "Error occurred when init IPC client";
return false;
}
}
if (m_IpcClient->Interface()) {
m_IpcClient->Interface()->setLogsEnabled(enabled);
if (auto iface = IpcClient::Interface(); iface) {
iface->setLogsEnabled(enabled);
} else {
qWarning() << "Error occurred setting up service logs";
return false;
@@ -208,19 +199,8 @@ void Logger::clearLogs(bool isServiceLogger)
void Logger::clearServiceLogs()
{
#ifdef AMNEZIA_DESKTOP
IpcClient *m_IpcClient = new IpcClient;
if (!m_IpcClient->isSocketConnected()) {
if (!IpcClient::init(m_IpcClient)) {
qWarning() << "Error occurred when init IPC client";
return;
}
}
if (m_IpcClient->Interface()) {
m_IpcClient->Interface()->clearLogs();
} else {
qWarning() << "Error occurred cleaning up service logs";
if (auto iface = IpcClient::Interface(); iface) {
iface->clearLogs();
}
#endif
}