2024-08-07 14:05:18 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-10-10 20:31:28 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
2026-06-08 20:37:23 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 - 2025 Synergy App Ltd
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2024-08-07 14:05:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2026-02-22 04:23:21 +00:00
|
|
|
#include "common/Enums.h"
|
2025-03-09 04:14:26 +00:00
|
|
|
#include "common/Settings.h"
|
2025-02-10 12:58:23 +00:00
|
|
|
#include "gui/FileTail.h"
|
2026-03-26 14:17:56 +00:00
|
|
|
#include "gui/config/ServerConfig.h"
|
2025-02-10 12:58:23 +00:00
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QObject>
|
2025-08-22 09:33:05 +00:00
|
|
|
#include <QProcess>
|
2024-09-09 10:18:17 +00:00
|
|
|
#include <QTimer>
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow::gui {
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2025-02-06 13:31:18 +00:00
|
|
|
namespace ipc {
|
2025-12-05 17:45:09 +00:00
|
|
|
class CoreIpcClient;
|
2025-02-06 13:31:18 +00:00
|
|
|
class DaemonIpcClient;
|
2026-03-26 12:34:18 +00:00
|
|
|
} // namespace ipc
|
2025-02-06 13:31:18 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class CoreProcess : public QObject
|
|
|
|
|
{
|
2026-02-22 04:23:21 +00:00
|
|
|
using ConnectionState = deskflow::core::ConnectionState;
|
2025-03-09 04:14:26 +00:00
|
|
|
using ProcessMode = Settings::ProcessMode;
|
2026-02-22 04:34:23 +00:00
|
|
|
using ProcessState = deskflow::core::ProcessState;
|
2024-08-07 14:05:18 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2024-10-17 18:04:35 +00:00
|
|
|
enum class Error
|
|
|
|
|
{
|
|
|
|
|
AddressMissing,
|
|
|
|
|
StartFailed
|
|
|
|
|
};
|
2025-10-10 20:07:39 +00:00
|
|
|
|
2026-03-26 14:17:56 +00:00
|
|
|
explicit CoreProcess(const ServerConfig &serverConfig);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
void start(std::optional<ProcessMode> processMode = std::nullopt);
|
|
|
|
|
void stop(std::optional<ProcessMode> processMode = std::nullopt);
|
|
|
|
|
void restart();
|
|
|
|
|
void cleanup();
|
2025-02-07 17:02:20 +00:00
|
|
|
void applyLogLevel();
|
2025-03-03 18:01:32 +00:00
|
|
|
void clearSettings();
|
2025-04-15 20:52:36 +00:00
|
|
|
void retryDaemon();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
// getters
|
2025-03-10 02:50:44 +00:00
|
|
|
Settings::CoreMode mode() const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
return m_mode;
|
|
|
|
|
}
|
|
|
|
|
QString secureSocketVersion() const
|
|
|
|
|
{
|
|
|
|
|
return m_secureSocketVersion;
|
|
|
|
|
}
|
|
|
|
|
bool isStarted() const
|
|
|
|
|
{
|
|
|
|
|
return m_processState == ProcessState::Started;
|
|
|
|
|
}
|
|
|
|
|
ProcessState processState() const
|
|
|
|
|
{
|
|
|
|
|
return m_processState;
|
|
|
|
|
}
|
|
|
|
|
ConnectionState connectionState() const
|
|
|
|
|
{
|
|
|
|
|
return m_connectionState;
|
|
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
// setters
|
2024-10-17 18:04:35 +00:00
|
|
|
void setAddress(const QString &address)
|
|
|
|
|
{
|
2025-10-11 00:56:18 +00:00
|
|
|
m_address = correctedAddress(address);
|
2024-10-17 18:04:35 +00:00
|
|
|
}
|
2025-03-10 02:50:44 +00:00
|
|
|
void setMode(Settings::CoreMode mode)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
m_mode = mode;
|
|
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2025-05-31 15:35:37 +00:00
|
|
|
Q_SIGNALS:
|
2025-08-06 23:05:35 +00:00
|
|
|
void error(deskflow::gui::CoreProcess::Error error);
|
2024-08-07 14:05:18 +00:00
|
|
|
void logLine(const QString &line);
|
2026-02-22 04:23:21 +00:00
|
|
|
void connectionStateChanged(deskflow::core::ConnectionState state);
|
2026-02-22 04:34:23 +00:00
|
|
|
void processStateChanged(deskflow::core::ProcessState state);
|
2024-08-07 14:05:18 +00:00
|
|
|
void secureSocket(bool enabled);
|
2025-04-18 12:56:37 +00:00
|
|
|
void daemonIpcClientConnectionFailed();
|
2026-03-26 12:34:18 +00:00
|
|
|
void connectedClientsChanged(const QStringList &clients);
|
2026-02-23 21:27:39 +00:00
|
|
|
void securityLevelChanged(QString securityLevel);
|
2026-03-26 14:17:56 +00:00
|
|
|
void unrecognisedClient(const QString &clientName);
|
|
|
|
|
void connectionRefused(deskflow::core::ConnectionRefusal reason);
|
|
|
|
|
void retryIn(int seconds);
|
|
|
|
|
void peerFingerprint(const QString &fingerprint);
|
2026-03-30 18:38:03 +00:00
|
|
|
void missingKeyboardLayouts(const QString &layouts);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2025-05-31 15:35:37 +00:00
|
|
|
private Q_SLOTS:
|
2024-08-07 14:05:18 +00:00
|
|
|
void onProcessFinished(int exitCode, QProcess::ExitStatus);
|
|
|
|
|
void onProcessReadyReadStandardOutput();
|
|
|
|
|
void onProcessReadyReadStandardError();
|
2026-03-26 12:34:18 +00:00
|
|
|
void onCoreIpcMessageReceived(const QString &command, const QString &args);
|
2025-02-10 14:12:27 +00:00
|
|
|
void daemonIpcClientConnected();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-09-27 16:17:56 +00:00
|
|
|
void startForegroundProcess(const QStringList &args);
|
2026-04-13 14:57:00 +00:00
|
|
|
void startProcessFromDaemon();
|
2025-02-05 17:57:04 +00:00
|
|
|
void stopForegroundProcess() const;
|
|
|
|
|
void stopProcessFromDaemon();
|
2026-02-21 17:18:07 +00:00
|
|
|
QPair<bool, QString> persistServerConfig() const;
|
2024-08-07 14:05:18 +00:00
|
|
|
void setConnectionState(ConnectionState state);
|
|
|
|
|
void setProcessState(ProcessState state);
|
|
|
|
|
bool checkSecureSocket(const QString &line);
|
|
|
|
|
void handleLogLines(const QString &text);
|
2025-10-11 00:56:18 +00:00
|
|
|
QString correctedAddress(const QString &address) const;
|
2026-03-26 12:34:18 +00:00
|
|
|
void setupDaemonLogTail(const QString &logPath);
|
2026-04-08 09:31:40 +00:00
|
|
|
void checkExistingProcess();
|
2025-10-05 12:57:49 +00:00
|
|
|
static QString makeQuotedArgs(const QString &app, const QStringList &args);
|
2025-10-10 19:52:49 +00:00
|
|
|
static QString processModeToString(const Settings::ProcessMode mode);
|
2025-10-10 20:07:39 +00:00
|
|
|
static QString processStateToString(const CoreProcess::ProcessState state);
|
2025-10-11 00:29:02 +00:00
|
|
|
static QString wrapIpv6(const QString &address);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2026-03-26 14:17:56 +00:00
|
|
|
const ServerConfig &m_serverConfig;
|
2024-08-07 14:05:18 +00:00
|
|
|
QString m_address;
|
|
|
|
|
ProcessState m_processState = ProcessState::Stopped;
|
|
|
|
|
ConnectionState m_connectionState = ConnectionState::Disconnected;
|
2025-03-10 02:50:44 +00:00
|
|
|
Settings::CoreMode m_mode = Settings::CoreMode::None;
|
2024-08-07 14:05:18 +00:00
|
|
|
QMutex m_processMutex;
|
2025-08-22 09:33:05 +00:00
|
|
|
QString m_secureSocketVersion;
|
2024-08-07 14:05:18 +00:00
|
|
|
std::optional<ProcessMode> m_lastProcessMode = std::nullopt;
|
2024-09-09 10:18:17 +00:00
|
|
|
QTimer m_retryTimer;
|
2025-12-05 17:45:09 +00:00
|
|
|
deskflow::gui::ipc::CoreIpcClient *m_coreIpcClient = nullptr;
|
2025-02-06 13:31:18 +00:00
|
|
|
deskflow::gui::ipc::DaemonIpcClient *m_daemonIpcClient = nullptr;
|
2025-02-10 12:58:23 +00:00
|
|
|
FileTail *m_daemonFileTail = nullptr;
|
2025-09-01 12:27:53 +00:00
|
|
|
QProcess *m_process = nullptr;
|
2025-08-22 09:33:05 +00:00
|
|
|
QString m_appPath;
|
2024-08-07 14:05:18 +00:00
|
|
|
};
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|