refactor(core): Convert app to Qt app
This commit is contained in:
parent
d8e9ac27f5
commit
8a77e5f130
3 changed files with 84 additions and 43 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016, 2025 - 2026 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
|
@ -21,15 +21,27 @@
|
|||
#include <QCoreApplication>
|
||||
#endif
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QSharedMemory>
|
||||
#include <QTextStream>
|
||||
#include <QThread>
|
||||
|
||||
void showHelp(const CoreArgParser &parser)
|
||||
{
|
||||
QTextStream(stdout) << parser.helpText();
|
||||
}
|
||||
|
||||
App *createApp(const CoreArgParser &parser, EventQueue &events, const QString &processName)
|
||||
{
|
||||
if (parser.serverMode()) {
|
||||
return new ServerApp(&events, processName);
|
||||
} else if (parser.clientMode()) {
|
||||
return new ClientApp(&events, processName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
|
|
@ -86,13 +98,18 @@ int main(int argc, char **argv)
|
|||
EventQueue events;
|
||||
const auto processName = QFileInfo(argv[0]).fileName();
|
||||
|
||||
if (parser.serverMode()) {
|
||||
ServerApp app(&events, processName);
|
||||
return app.run();
|
||||
} else if (parser.clientMode()) {
|
||||
ClientApp app(&events, processName);
|
||||
return app.run();
|
||||
}
|
||||
App *coreApp = createApp(parser, events, processName);
|
||||
|
||||
return s_exitSuccess;
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::setApplicationName(QStringLiteral("%1 Core").arg(kAppName));
|
||||
|
||||
QThread coreThread;
|
||||
QObject::connect(&coreThread, &QThread::finished, &app, &QCoreApplication::quit);
|
||||
coreApp->run(coreThread);
|
||||
|
||||
const auto exitCode = QCoreApplication::exec();
|
||||
coreThread.wait();
|
||||
|
||||
LOG_DEBUG("core exited, code: %d", exitCode);
|
||||
return exitCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2025 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2026 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
|
@ -57,8 +57,17 @@ App::~App()
|
|||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
int App::run()
|
||||
void App::run(QThread &coreThread)
|
||||
{
|
||||
LOG_NOTE("starting core");
|
||||
|
||||
// Important: Move the daemon app to the daemon thread before creating any more Qt objects
|
||||
// owned by the daemon app, as they will be created on the daemon thread.
|
||||
moveToThread(&coreThread);
|
||||
|
||||
connect(&coreThread, &QThread::started, this, [this, &coreThread]() {
|
||||
LOG_DEBUG("core thread started");
|
||||
|
||||
#if MAC_OS_X_VERSION_10_7
|
||||
// dock hide only supported on lion :(
|
||||
ProcessSerialNumber psn = {0, kCurrentProcess};
|
||||
|
|
@ -98,7 +107,19 @@ int App::run()
|
|||
LOG_CRIT("an unknown error occurred\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
if (result == s_exitSuccess) {
|
||||
LOG_INFO("core stopped successfully");
|
||||
} else {
|
||||
// TODO: surface error code to main thread somehow
|
||||
LOG_ERR("core stopped with error code: %d", result);
|
||||
}
|
||||
|
||||
coreThread.quit();
|
||||
LOG_DEBUG("core thread finished");
|
||||
});
|
||||
|
||||
LOG_DEBUG("starting core thread");
|
||||
coreThread.start();
|
||||
}
|
||||
|
||||
void App::setupFileLogging()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2025 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2026 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
|
@ -19,6 +19,9 @@
|
|||
#include "deskflow/unix/AppUtilUnix.h"
|
||||
#endif
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
|
|
@ -30,7 +33,7 @@ class FileLogOutputter;
|
|||
class IEventQueue;
|
||||
class SocketMultiplexer;
|
||||
|
||||
class App : public IApp
|
||||
class App : public QObject, private IApp
|
||||
{
|
||||
public:
|
||||
class XNoEiSupport : public std::runtime_error
|
||||
|
|
@ -72,7 +75,7 @@ public:
|
|||
return m_appUtil;
|
||||
}
|
||||
|
||||
int run();
|
||||
void run(QThread &coreThread);
|
||||
void setupFileLogging();
|
||||
void loggingFilterWarning() const;
|
||||
void initApp() override;
|
||||
|
|
|
|||
Loading…
Reference in a new issue