2022-11-29 19:00:37 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2022-11-29 19:00:37 +00:00
|
|
|
*/
|
2025-01-24 00:11:17 +00:00
|
|
|
|
2022-11-29 19:00:37 +00:00
|
|
|
#include "arch/Arch.h"
|
|
|
|
|
#include "base/EventQueue.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "base/Log.h"
|
2025-08-19 13:55:31 +00:00
|
|
|
#include "common/ExitCodes.h"
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/ClientApp.h"
|
2025-08-22 20:22:56 +00:00
|
|
|
#include "deskflow/CoreArgParser.h"
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/ServerApp.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
#if SYSAPI_WIN32
|
|
|
|
|
#include "arch/win32/ArchMiscWindows.h"
|
2025-04-24 01:23:13 +00:00
|
|
|
#include <QCoreApplication>
|
2024-07-02 19:07:06 +00:00
|
|
|
#endif
|
2022-11-29 19:00:37 +00:00
|
|
|
|
2025-09-25 01:35:20 +00:00
|
|
|
#include <QFileInfo>
|
2025-08-18 22:02:30 +00:00
|
|
|
#include <QSharedMemory>
|
2025-08-22 20:22:56 +00:00
|
|
|
#include <QTextStream>
|
2025-02-05 17:57:30 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2025-08-22 20:22:56 +00:00
|
|
|
void showHelp(const CoreArgParser &parser)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-09-26 02:52:29 +00:00
|
|
|
QTextStream(stdout) << parser.helpText();
|
2022-11-29 19:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2025-08-18 22:02:30 +00:00
|
|
|
Arch arch;
|
|
|
|
|
arch.init();
|
|
|
|
|
|
|
|
|
|
Log log;
|
|
|
|
|
|
2025-08-22 20:22:56 +00:00
|
|
|
QStringList args;
|
|
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
|
args.append(argv[i]);
|
|
|
|
|
|
|
|
|
|
CoreArgParser parser(args);
|
|
|
|
|
|
|
|
|
|
// Comment below until we are ready use only this parser
|
|
|
|
|
// if (!parser.errorText().isEmpty()) {
|
|
|
|
|
// QTextStream(stdout) << parser.errorText() << "\nUse --help for more information.";
|
|
|
|
|
// return s_exitFailed;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (parser.help()) {
|
|
|
|
|
showHelp(parser);
|
2025-08-19 13:55:31 +00:00
|
|
|
return s_exitSuccess;
|
2025-08-18 22:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 20:22:56 +00:00
|
|
|
if (parser.version()) {
|
|
|
|
|
QTextStream(stdout) << parser.versionText();
|
2025-08-20 20:37:02 +00:00
|
|
|
return s_exitSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 20:22:56 +00:00
|
|
|
// Before we check any more args we need to check for a duplicate process.
|
2025-08-18 22:02:30 +00:00
|
|
|
// Create a shared memory segment with a unique key
|
|
|
|
|
// This is to prevent a new instance from running if one is already running
|
|
|
|
|
QSharedMemory sharedMemory("deskflow-core");
|
|
|
|
|
|
|
|
|
|
// Attempt to attach first and detach in order to clean up stale shm chunks
|
|
|
|
|
// This can happen if the previous instance was killed or crashed
|
|
|
|
|
if (sharedMemory.attach())
|
|
|
|
|
sharedMemory.detach();
|
|
|
|
|
|
|
|
|
|
// If we can create 1 byte of SHM we are the only instance
|
|
|
|
|
if (!sharedMemory.create(1)) {
|
2025-08-22 01:54:10 +00:00
|
|
|
LOG_WARN("an instance of deskflow core is already running");
|
2025-08-19 13:55:31 +00:00
|
|
|
return s_exitDuplicate;
|
2025-08-18 22:02:30 +00:00
|
|
|
}
|
2025-08-22 20:22:56 +00:00
|
|
|
|
|
|
|
|
parser.parse();
|
|
|
|
|
|
2022-11-29 19:00:37 +00:00
|
|
|
#if SYSAPI_WIN32
|
2025-04-24 01:23:13 +00:00
|
|
|
// HACK to make sure settings gets the correct qApp path
|
|
|
|
|
QCoreApplication m(argc, argv);
|
|
|
|
|
m.deleteLater();
|
|
|
|
|
|
2025-04-27 19:39:23 +00:00
|
|
|
ArchMiscWindows::setInstanceWin32(GetModuleHandle(nullptr));
|
2022-11-29 19:00:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
EventQueue events;
|
2025-09-25 01:35:20 +00:00
|
|
|
const auto processName = QFileInfo(argv[0]).fileName();
|
2022-11-29 19:00:37 +00:00
|
|
|
|
2025-08-22 20:22:56 +00:00
|
|
|
if (parser.serverMode()) {
|
2025-09-25 01:35:20 +00:00
|
|
|
ServerApp app(&events, processName);
|
2024-07-02 19:07:06 +00:00
|
|
|
return app.run(argc, argv);
|
2025-08-22 20:22:56 +00:00
|
|
|
} else if (parser.clientMode()) {
|
2025-09-25 01:35:20 +00:00
|
|
|
ClientApp app(&events, processName);
|
2024-07-02 19:07:06 +00:00
|
|
|
return app.run(argc, argv);
|
|
|
|
|
}
|
2022-11-29 19:00:37 +00:00
|
|
|
|
2025-08-19 13:55:31 +00:00
|
|
|
return s_exitSuccess;
|
2022-11-29 19:00:37 +00:00
|
|
|
}
|