2024-08-07 14:05:18 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-02-10 12:58:23 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 - 2025 Symless 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
|
|
|
|
|
|
2025-03-09 04:14:26 +00:00
|
|
|
#include "common/Settings.h"
|
2025-02-10 12:58:23 +00:00
|
|
|
#include "gui/FileTail.h"
|
2024-08-07 14:05:18 +00:00
|
|
|
#include "gui/config/IServerConfig.h"
|
2025-02-10 12:58:23 +00:00
|
|
|
|
|
|
|
|
#include <QFileSystemWatcher>
|
2024-08-07 14:05:18 +00:00
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QObject>
|
2025-08-22 09:33:05 +00:00
|
|
|
#include <QProcess>
|
2024-08-07 14:05:18 +00:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
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 {
|
|
|
|
|
class DaemonIpcClient;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class CoreProcess : public QObject
|
|
|
|
|
{
|
2025-03-09 04:14:26 +00:00
|
|
|
using ProcessMode = Settings::ProcessMode;
|
2024-09-17 19:00:25 +00:00
|
|
|
using IServerConfig = deskflow::gui::IServerConfig;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2024-10-17 18:04:35 +00:00
|
|
|
enum class Error
|
|
|
|
|
{
|
|
|
|
|
AddressMissing,
|
|
|
|
|
StartFailed
|
|
|
|
|
};
|
|
|
|
|
enum class ProcessState
|
|
|
|
|
{
|
2024-09-09 10:18:17 +00:00
|
|
|
Starting,
|
|
|
|
|
Started,
|
|
|
|
|
Stopping,
|
|
|
|
|
Stopped,
|
|
|
|
|
RetryPending
|
|
|
|
|
};
|
2024-10-17 18:04:35 +00:00
|
|
|
enum class ConnectionState
|
|
|
|
|
{
|
|
|
|
|
Disconnected,
|
|
|
|
|
Connecting,
|
|
|
|
|
Connected,
|
|
|
|
|
Listening
|
|
|
|
|
};
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2025-08-22 09:33:05 +00:00
|
|
|
explicit CoreProcess(const IServerConfig &serverConfig);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
void extracted(QString &app, QStringList &args);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
m_address = address.trimmed();
|
|
|
|
|
}
|
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:
|
2024-08-07 14:05:18 +00:00
|
|
|
void starting();
|
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);
|
2025-08-06 23:05:35 +00:00
|
|
|
void connectionStateChanged(deskflow::gui::CoreProcess::ConnectionState state);
|
|
|
|
|
void processStateChanged(deskflow::gui::CoreProcess::ProcessState state);
|
2024-08-07 14:05:18 +00:00
|
|
|
void secureSocket(bool enabled);
|
2025-04-18 12:56:37 +00:00
|
|
|
void daemonIpcClientConnectionFailed();
|
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();
|
2025-02-10 14:12:27 +00:00
|
|
|
void daemonIpcClientConnected();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-02-05 17:57:04 +00:00
|
|
|
void startForegroundProcess(const QString &app, const QStringList &args);
|
|
|
|
|
void startProcessFromDaemon(const QString &app, const QStringList &args);
|
|
|
|
|
void stopForegroundProcess() const;
|
|
|
|
|
void stopProcessFromDaemon();
|
2024-08-10 23:58:24 +00:00
|
|
|
bool addGenericArgs(QStringList &args, const ProcessMode processMode) const;
|
|
|
|
|
bool addServerArgs(QStringList &args, QString &app);
|
|
|
|
|
bool addClientArgs(QStringList &args, QString &app);
|
|
|
|
|
QString persistServerConfig() const;
|
2024-08-07 14:05:18 +00:00
|
|
|
QString modeString() const;
|
|
|
|
|
QString processModeString() const;
|
|
|
|
|
void setConnectionState(ConnectionState state);
|
|
|
|
|
void setProcessState(ProcessState state);
|
|
|
|
|
void checkLogLine(const QString &line);
|
|
|
|
|
bool checkSecureSocket(const QString &line);
|
|
|
|
|
void handleLogLines(const QString &text);
|
|
|
|
|
QString correctedInterface() const;
|
|
|
|
|
QString correctedAddress() const;
|
2025-02-10 12:58:23 +00:00
|
|
|
QString requestDaemonLogPath();
|
2025-05-20 02:19:19 +00:00
|
|
|
void persistLogDir() const;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
void checkOSXNotification(const QString &line);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-08-12 15:39:18 +00:00
|
|
|
const IServerConfig &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-02-20 01:58:06 +00:00
|
|
|
int m_connections = 0;
|
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
|