From fb686ede21413eee5e9f92fce917438388bdc9ce Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 29 Oct 2024 14:09:43 -0400 Subject: [PATCH] refactor: remove desktop legacy --- cmake/Definitions.cmake | 6 +- res/dist/wix/Include.wxi.in | 59 ++++++------ res/dist/wix/Product.wxs | 1 - src/cmd/CMakeLists.txt | 4 +- src/cmd/deskflow-legacy/CMakeLists.txt | 43 --------- src/cmd/deskflow-legacy/deskflow-legacy.cpp | 34 ------- src/cmd/deskflowd/CMakeLists.txt | 2 +- src/lib/deskflow/ArgParser.cpp | 21 ----- src/lib/deskflow/ArgParser.h | 2 - src/lib/deskflow/CMakeLists.txt | 4 - src/lib/deskflow/ToolApp.cpp | 93 ------------------- src/lib/deskflow/ToolApp.h | 32 ------- src/lib/deskflow/ToolArgs.cpp | 26 ------ src/lib/deskflow/ToolArgs.h | 32 ------- src/lib/gui/CMakeLists.txt | 8 ++ src/lib/platform/MSWindowsWatchdog.cpp | 36 ++----- .../unittests/deskflow/ArgParserTests.cpp | 22 ----- 17 files changed, 47 insertions(+), 378 deletions(-) delete mode 100644 src/cmd/deskflow-legacy/CMakeLists.txt delete mode 100644 src/cmd/deskflow-legacy/deskflow-legacy.cpp delete mode 100644 src/lib/deskflow/ToolApp.cpp delete mode 100644 src/lib/deskflow/ToolApp.h delete mode 100644 src/lib/deskflow/ToolArgs.cpp delete mode 100644 src/lib/deskflow/ToolArgs.h diff --git a/cmake/Definitions.cmake b/cmake/Definitions.cmake index b9e918efc..8cc5880d5 100644 --- a/cmake/Definitions.cmake +++ b/cmake/Definitions.cmake @@ -154,23 +154,19 @@ macro(configure_bin_names) "deskflow-daemon" CACHE STRING "Filename of the daemon binary") - set(LEGACY_BINARY_NAME - "deskflow-legacy" - CACHE STRING "Filename of the legacy binary") message(VERBOSE "GUI binary: ${GUI_BINARY_NAME}") message(VERBOSE "Server binary: ${SERVER_BINARY_NAME}") message(VERBOSE "Client binary: ${CLIENT_BINARY_NAME}") message(VERBOSE "Core binary: ${CORE_BINARY_NAME}") message(VERBOSE "Daemon binary: ${DAEMON_BINARY_NAME}") - message(VERBOSE "Legacy binary: ${LEGACY_BINARY_NAME}") + add_definitions(-DGUI_BINARY_NAME="${GUI_BINARY_NAME}") add_definitions(-DSERVER_BINARY_NAME="${SERVER_BINARY_NAME}") add_definitions(-DCLIENT_BINARY_NAME="${CLIENT_BINARY_NAME}") add_definitions(-DCORE_BINARY_NAME="${CORE_BINARY_NAME}") add_definitions(-DDAEMON_BINARY_NAME="${DAEMON_BINARY_NAME}") - add_definitions(-DLEGACY_BINARY_NAME="${LEGACY_BINARY_NAME}") endmacro() diff --git a/res/dist/wix/Include.wxi.in b/res/dist/wix/Include.wxi.in index 2c33c80d5..67d0db1b1 100644 --- a/res/dist/wix/Include.wxi.in +++ b/res/dist/wix/Include.wxi.in @@ -1,30 +1,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/dist/wix/Product.wxs b/res/dist/wix/Product.wxs index c1b932d02..5d679d5ba 100644 --- a/res/dist/wix/Product.wxs +++ b/res/dist/wix/Product.wxs @@ -88,7 +88,6 @@ - diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 8b1ea36f1..7ddccc97e 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -14,7 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -add_subdirectory(deskflowd) if(BUILD_UNIFIED) add_subdirectory(deskflow-core) @@ -23,4 +22,5 @@ else() add_subdirectory(deskflows) endif(BUILD_UNIFIED) -add_subdirectory(deskflow-legacy) +## Only used on windows +add_subdirectory(deskflowd) diff --git a/src/cmd/deskflow-legacy/CMakeLists.txt b/src/cmd/deskflow-legacy/CMakeLists.txt deleted file mode 100644 index 496b5bda2..000000000 --- a/src/cmd/deskflow-legacy/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Deskflow -- mouse and keyboard sharing utility -# Copyright (C) 2024 Chris Rizzitello -# Copyright (C) 2012-2024 Symless Ltd. -# Copyright (C) 2009-2012 Nick Bolton -# -# This package is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# found in the file LICENSE that should have accompanied this file. -# -# This package is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -set(target ${LEGACY_BINARY_NAME}) - -add_executable(${target} "${target}.cpp") -if(WIN32) - target_sources(${target} PRIVATE "${PROJECT_BINARY_DIR}/src/version.rc") -endif() - -target_link_libraries( - ${target} - app - arch - base - client - io - ipc - mt - net - platform - server - ${libs}) - -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - install(TARGETS ${target} DESTINATION ${DESKFLOW_BUNDLE_BINARY_DIR}) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - install(TARGETS ${target} DESTINATION bin) -endif() diff --git a/src/cmd/deskflow-legacy/deskflow-legacy.cpp b/src/cmd/deskflow-legacy/deskflow-legacy.cpp deleted file mode 100644 index d187496de..000000000 --- a/src/cmd/deskflow-legacy/deskflow-legacy.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "arch/Arch.h" -#include "deskflow/ToolApp.h" - -#if SYSAPI_WIN32 -#include "arch/win32/ArchMiscWindows.h" -#endif - -int main(int argc, char **argv) -{ -#if SYSAPI_WIN32 - // record window instance for tray icon, etc - ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); -#endif - - ToolApp app; - return app.run(argc, argv); -} diff --git a/src/cmd/deskflowd/CMakeLists.txt b/src/cmd/deskflowd/CMakeLists.txt index 19dcbb122..c7b10b63f 100644 --- a/src/cmd/deskflowd/CMakeLists.txt +++ b/src/cmd/deskflowd/CMakeLists.txt @@ -15,9 +15,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -set(target ${DAEMON_BINARY_NAME}) # Daemon is only needed on Windows for elevating processes to deal with UAC. if(WIN32) + set(target ${DAEMON_BINARY_NAME}) add_executable(${target} WIN32 deskflowd.cpp "${PROJECT_BINARY_DIR}/src/version.rc" diff --git a/src/lib/deskflow/ArgParser.cpp b/src/lib/deskflow/ArgParser.cpp index 28ab11eef..9e677e52c 100644 --- a/src/lib/deskflow/ArgParser.cpp +++ b/src/lib/deskflow/ArgParser.cpp @@ -23,7 +23,6 @@ #include "deskflow/ArgsBase.h" #include "deskflow/ClientArgs.h" #include "deskflow/ServerArgs.h" -#include "deskflow/ToolArgs.h" #ifdef WINAPI_MSWINDOWS #include @@ -165,26 +164,6 @@ bool ArgParser::parsePlatformArgs( #endif } -bool ArgParser::parseToolArgs(ToolArgs &args, int argc, const char *const *argv) -{ - // We support exactly one argument at a fix position - static const int only_index{1}; - if (isArg(only_index, argc, argv, nullptr, "--get-active-desktop", 0)) { - args.m_printActiveDesktopName = true; - return true; - } else if (isArg(only_index, argc, argv, nullptr, "--get-installed-dir", 0)) { - args.m_getInstalledDir = true; - return true; - } else if (isArg(only_index, argc, argv, nullptr, "--get-profile-dir", 0)) { - args.m_getProfileDir = true; - return true; - } else if (isArg(only_index, argc, argv, nullptr, "--get-arch", 0)) { - args.m_getArch = true; - return true; - } - return false; -} - bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) { if (isArg(i, argc, argv, "-a", "--address", 1)) { diff --git a/src/lib/deskflow/ArgParser.h b/src/lib/deskflow/ArgParser.h index 171c5f436..d0c2abd04 100644 --- a/src/lib/deskflow/ArgParser.h +++ b/src/lib/deskflow/ArgParser.h @@ -26,7 +26,6 @@ class ServerArgs; class ClientArgs; } // namespace deskflow -class ToolArgs; class App; class ArgParser @@ -38,7 +37,6 @@ public: bool parseServerArgs(deskflow::ServerArgs &args, int argc, const char *const *argv); bool parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv); bool parsePlatformArgs(deskflow::ArgsBase &argsBase, const int &argc, const char *const *argv, int &i, bool isServer); - bool parseToolArgs(ToolArgs &args, int argc, const char *const *argv); bool parseGenericArgs(int argc, const char *const *argv, int &i); bool parseDeprecatedArgs(int argc, const char *const *argv, int &i); void setArgsBase(deskflow::ArgsBase &argsBase) diff --git a/src/lib/deskflow/CMakeLists.txt b/src/lib/deskflow/CMakeLists.txt index 1ae880549..a1e4021df 100644 --- a/src/lib/deskflow/CMakeLists.txt +++ b/src/lib/deskflow/CMakeLists.txt @@ -153,10 +153,6 @@ add_library(${lib_name} STATIC ${PLATFORM_CODE} ServerTaskBarReceiver.h StreamChunker.cpp StreamChunker.h - ToolApp.cpp - ToolApp.h - ToolArgs.cpp - ToolArgs.h XDeskflow.cpp XDeskflow.h XScreen.cpp diff --git a/src/lib/deskflow/ToolApp.cpp b/src/lib/deskflow/ToolApp.cpp deleted file mode 100644 index 80fce9345..000000000 --- a/src/lib/deskflow/ToolApp.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "deskflow/ToolApp.h" - -#include "arch/Arch.h" -#include "base/Log.h" -#include "base/String.h" -#include "deskflow/ArgParser.h" - -#include - -#if SYSAPI_WIN32 -#include "platform/MSWindowsSession.h" -#endif - -enum -{ - kErrorOk, - kErrorArgs, - kErrorException, - kErrorUnknown -}; - -UInt32 ToolApp::run(int argc, char **argv) -{ - if (argc <= 1) { - std::cerr << "no args" << std::endl; - return kErrorArgs; - } - - try { - ArgParser argParser(this); - bool result = argParser.parseToolArgs(m_args, argc, argv); - - if (!result) { - m_bye(kExitArgs); - } - - if (m_args.m_printActiveDesktopName) { -#if SYSAPI_WIN32 - MSWindowsSession session; - String name = session.getActiveDesktopName(); - if (name.empty()) { - LOG((CLOG_CRIT "failed to get active desktop name")); - return kExitFailed; - } else { - String output = deskflow::string::sprintf("activeDesktop:%s", name.c_str()); - LOG((CLOG_INFO "%s", output.c_str())); - } -#endif - } else if (m_args.m_getInstalledDir) { - std::cout << ARCH->getInstalledDirectory() << std::endl; - } else if (m_args.m_getProfileDir) { - std::cout << ARCH->getProfileDirectory() << std::endl; - } else if (m_args.m_getArch) { - std::cout << ARCH->getPlatformName() << std::endl; - } else { - throw XDeskflow("Nothing to do"); - } - } catch (std::exception &e) { - LOG((CLOG_CRIT "an error occurred: %s\n", e.what())); - return kExitFailed; - } catch (...) { - LOG((CLOG_CRIT "an unknown error occurred\n")); - return kExitFailed; - } - -#if WINAPI_XWINDOWS - // HACK: avoid sigsegv on linux - m_bye(kErrorOk); -#endif - - return kErrorOk; -} - -void ToolApp::help() -{ -} diff --git a/src/lib/deskflow/ToolApp.h b/src/lib/deskflow/ToolApp.h deleted file mode 100644 index 69f73071c..000000000 --- a/src/lib/deskflow/ToolApp.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "common/basic_types.h" -#include "deskflow/App.h" -#include "deskflow/ToolArgs.h" - -class ToolApp : public MinimalApp -{ -public: - UInt32 run(int argc, char **argv); - void help(); - -private: - ToolArgs m_args; -}; diff --git a/src/lib/deskflow/ToolArgs.cpp b/src/lib/deskflow/ToolArgs.cpp deleted file mode 100644 index 7860883e1..000000000 --- a/src/lib/deskflow/ToolArgs.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "deskflow/ToolArgs.h" - -ToolArgs::ToolArgs() - : m_printActiveDesktopName(false), - m_getInstalledDir(false), - m_getProfileDir(false), - m_getArch(false) -{ -} diff --git a/src/lib/deskflow/ToolArgs.h b/src/lib/deskflow/ToolArgs.h deleted file mode 100644 index 8af13c34a..000000000 --- a/src/lib/deskflow/ToolArgs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "base/String.h" - -class ToolArgs -{ -public: - ToolArgs(); - -public: - bool m_printActiveDesktopName; - bool m_getInstalledDir; - bool m_getProfileDir; - bool m_getArch; -}; diff --git a/src/lib/gui/CMakeLists.txt b/src/lib/gui/CMakeLists.txt index 3112a11c0..91fe15d8d 100644 --- a/src/lib/gui/CMakeLists.txt +++ b/src/lib/gui/CMakeLists.txt @@ -48,3 +48,11 @@ target_link_libraries( Qt6::Core Qt6::Widgets Qt6::Network) + +if(WIN32) + target_link_libraries( + ${target} + base + arch + ) +endif() diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index 372bab28a..95e5aab3c 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -603,38 +603,14 @@ void MSWindowsWatchdog::getActiveDesktop(LPSECURITY_ATTRIBUTES security) { String installedDir = ARCH->getInstalledDirectory(); if (!installedDir.empty()) { - String deskflowLegacyCommand; - deskflowLegacyCommand.append("\"").append(installedDir).append("\\").append(LEGACY_BINARY_NAME).append("\""); - deskflowLegacyCommand.append(" --get-active-desktop"); - - m_session.updateActiveSession(); - bool elevateProcess = m_elevateProcess; - m_elevateProcess = true; - HANDLE userToken = getUserToken(security); - m_elevateProcess = elevateProcess; - - BOOL createRet = startProcessAsUser(deskflowLegacyCommand, userToken, security); - auto pid = m_processInfo.dwProcessId; - if (!createRet) { - DWORD rc = GetLastError(); - RevertToSelf(); + MSWindowsSession session; + String name = session.getActiveDesktopName(); + if (name.empty()) { + LOG((CLOG_CRIT "failed to get active desktop name")); } else { - LOG((CLOG_DEBUG "launched %s to check active desktop", LEGACY_BINARY_NAME)); + String output = deskflow::string::sprintf("activeDesktop:%s", name.c_str()); + LOG((CLOG_INFO "%s", output.c_str())); } - - ARCH->lockMutex(m_mutex); - int waitTime = 0; - while (!m_ready) { - if (waitTime >= MAXIMUM_WAIT_TIME) { - break; - } - - ARCH->waitCondVar(m_condVar, m_mutex, 1.0); - waitTime++; - } - m_ready = false; - ARCH->unlockMutex(m_mutex); - closeProcessHandles(pid); } } diff --git a/src/test/unittests/deskflow/ArgParserTests.cpp b/src/test/unittests/deskflow/ArgParserTests.cpp index d50da3d93..8f4624a3a 100644 --- a/src/test/unittests/deskflow/ArgParserTests.cpp +++ b/src/test/unittests/deskflow/ArgParserTests.cpp @@ -22,7 +22,6 @@ #include "deskflow/ArgsBase.h" #include "deskflow/ClientArgs.h" #include "deskflow/ServerArgs.h" -#include "deskflow/ToolArgs.h" #include @@ -211,27 +210,6 @@ TEST(ArgParserTests, assembleCommand_stringArrayWithSpace_returnCommand) EXPECT_EQ("\"stub1 space\" stub2 \"stub3 space\"", command); } -TEST(ArgParserTests, parseToolArgs_matches_correspondingly) -{ - ArgParser parser(nullptr); - std::map> tests = { - {"--get-active-desktop", [](ToolArgs const &a) { return a.m_printActiveDesktopName; }}, - {"--get-installed-dir", [](ToolArgs const &a) { return a.m_getInstalledDir; }}, - {"--get-profile-dir", [](ToolArgs const &a) { return a.m_getProfileDir; }}, - {"--get-arch", [](ToolArgs const &a) { return a.m_getArch; }} - }; - for (auto const &test : tests) { - ToolArgs toolArgs; - EXPECT_FALSE(test.second(toolArgs)); - std::array twoArgs{LEGACY_BINARY_NAME, test.first}; - EXPECT_TRUE(parser.parseToolArgs(toolArgs, 2, twoArgs.data())); - EXPECT_TRUE(test.second(toolArgs)); - } - ToolArgs toolArgs; - std::array twoArgs{LEGACY_BINARY_NAME, "--garbage"}; - EXPECT_FALSE(parser.parseToolArgs(toolArgs, 2, twoArgs.data())); -} - TEST(ArgParserTests, parseServerArgs_parses_each_category) { ArgParser parser(nullptr);