mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 01:54:47 -07:00
Adds OS-level URL-scheme handlers so users can click a link in a browser,
chat client, or third-party tool to launch Cockatrice straight into a
server / game / Oracle update.
Supported URL forms:
cockatrice://joingame?hostname=H&port=P&roomid=R&gameid=G[&spectate=1]
cockatrice-oracle://update[?spoilers=1]
Credentials passed via URL (username/password query params) are deliberately
ignored — URLs leak through shell history, browser history, EDR capture, etc.
If the target server requires auth and no saved credentials match, the Connect
dialog opens pre-filled with the URL's host/port so the user types their
password locally.
OS integration
- Linux: MimeType=x-scheme-handler/cockatrice (and -oracle) added to the
.desktop files; Exec=cockatrice %u passes the URL through.
- Windows: NSIS installer writes HKCR\cockatrice and HKCR\cockatrice-oracle
registry entries; uninstaller removes them.
- macOS: per-app Info.cockatrice.plist / Info.oracle.plist declare
CFBundleURLTypes; a QFileOpenEvent filter is installed on QApplication
before any nested event loop so cold-start URLs aren't lost.
New abstractions
- Intent (libcockatrice_utility/libcockatrice/utility/intent.h): abstract base
for chained async actions. Guarantees finished() fires at most once,
execute() is idempotent, self-deletes via deleteLater, and
startTimeoutSafetyNet() arms a configurable per-stage deadline. Concrete
intents (IntentConnectToServer, IntentLogin, IntentJoinServerRoom,
IntentJoinServerGame) compose the joingame flow via UrlParser.
- SingleInstanceManager: async per-user local-socket primary/secondary
handshake; URL forwarded from secondary to primary with QDataStream framing
both ways. shared_ptr-backed resolved flag survives every lambda capture.
- UrlSchemeEventFilter (new libcockatrice_utility_gui sibling library): QObject
event filter that translates macOS QFileOpenEvent into a urlReceived(QString)
signal. Lives in its own Gui-bearing lib so libcockatrice_utility stays
Core+Network only and doesn't drag Qt::Gui into servatrice.
- UrlUtils (header-only): pure URL parsing, fully unit-tested.
Wiring
- MainWindow::handleUrl(QString) — single entry point for any URL source.
- DlgConnect::prefillNewHost(host, port) — pre-fills new-host inputs.
- ServersSettings::findSavedCredsByHostPort — case-insensitive saved-creds
lookup.
- TabSupervisor::requestJoinRoom + roomJoinedById / roomJoinFailedById signals,
TabServer::roomAlreadyJoined for the short-circuit "already in this room"
path — single source of truth for duplicate-join handling.
Tests
- 36 new unit tests across four single-purpose targets in tests/:
- url_utils_test (22 tests) — scheme matching, port/room/game validation,
spectator flag, credentials ignored, case-insensitivity.
- url_scheme_event_filter_test (3 tests) — QFileOpenEvent capture.
- intent_test (7 tests) — self-delete, abort propagation, parent-destruction-
mid-flight, finish-once gate, execute() idempotence.
- single_instance_manager_test (4 tests) — per-user socket naming, becoming-
primary alone, forwarding to an existing primary, single-emission of
roleResolved.
Build tooling (incidental)
- Dockerfile.format, docker-compose.format.yml, Makefile — a docker-based
runner for format.sh that mirrors CI's desktop-lint step.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
89 lines
4.1 KiB
CMake
89 lines
4.1 KiB
CMake
# NOTE: Qt modules for tests are defined centrally in cmake/FindQtRuntime.cmake (the _TEST_NEEDED variable).
|
|
# If a new test needs additional Qt modules, add them there — not in individual test CMakeLists.txt files.
|
|
enable_testing()
|
|
|
|
add_test(NAME dummy_test COMMAND dummy_test)
|
|
add_test(NAME expression_test COMMAND expression_test)
|
|
add_test(NAME test_age_formatting COMMAND test_age_formatting)
|
|
add_test(NAME password_hash_test COMMAND password_hash_test)
|
|
add_test(NAME url_utils_test COMMAND url_utils_test)
|
|
add_test(NAME url_scheme_event_filter_test COMMAND url_scheme_event_filter_test)
|
|
add_test(NAME intent_test COMMAND intent_test)
|
|
add_test(NAME single_instance_manager_test COMMAND single_instance_manager_test)
|
|
|
|
add_test(NAME deck_hash_performance_test COMMAND deck_hash_performance_test)
|
|
set_tests_properties(deck_hash_performance_test PROPERTIES TIMEOUT 5)
|
|
|
|
# Find GTest
|
|
|
|
add_executable(dummy_test dummy_test.cpp)
|
|
add_executable(expression_test expression_test.cpp)
|
|
add_executable(test_age_formatting test_age_formatting.cpp)
|
|
add_executable(password_hash_test password_hash_test.cpp)
|
|
add_executable(deck_hash_performance_test deck_hash_performance_test.cpp)
|
|
add_executable(url_utils_test url_utils_test.cpp)
|
|
add_executable(url_scheme_event_filter_test url_scheme_event_filter_test.cpp)
|
|
add_executable(intent_test intent_test.cpp)
|
|
add_executable(single_instance_manager_test single_instance_manager_test.cpp)
|
|
|
|
find_package(GTest)
|
|
|
|
if(NOT GTEST_FOUND)
|
|
if(NOT EXISTS "${CMAKE_BINARY_DIR}/gtest-build")
|
|
message(STATUS "Downloading googletest")
|
|
configure_file(
|
|
"${CMAKE_SOURCE_DIR}/cmake/gtest-CMakeLists.txt.in" "${CMAKE_BINARY_DIR}/gtest-download/CMakeLists.txt"
|
|
)
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download
|
|
)
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download)
|
|
else()
|
|
message(STATUS "GoogleTest directory exists")
|
|
endif()
|
|
|
|
# Add gtest directly to our build
|
|
add_subdirectory(${CMAKE_BINARY_DIR}/gtest-src ${CMAKE_BINARY_DIR}/gtest-build EXCLUDE_FROM_ALL)
|
|
|
|
# Add the gtest include directory, since gtest
|
|
# doesn't add that dependency to its gtest target
|
|
target_include_directories(gtest INTERFACE "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/gtest-src/include>")
|
|
|
|
set(GTEST_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/gtest-src/include")
|
|
set(GTEST_BOTH_LIBRARIES gtest)
|
|
add_dependencies(dummy_test gtest)
|
|
add_dependencies(expression_test gtest)
|
|
add_dependencies(test_age_formatting gtest)
|
|
add_dependencies(password_hash_test gtest)
|
|
add_dependencies(deck_hash_performance_test gtest)
|
|
add_dependencies(url_utils_test gtest)
|
|
add_dependencies(url_scheme_event_filter_test gtest)
|
|
add_dependencies(intent_test gtest)
|
|
add_dependencies(single_instance_manager_test gtest)
|
|
endif()
|
|
|
|
include_directories(${GTEST_INCLUDE_DIRS})
|
|
target_link_libraries(dummy_test Threads::Threads ${GTEST_BOTH_LIBRARIES})
|
|
target_link_libraries(expression_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
|
target_link_libraries(test_age_formatting Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
|
target_link_libraries(
|
|
password_hash_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
|
|
)
|
|
target_link_libraries(
|
|
deck_hash_performance_test libcockatrice_deck_list libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES}
|
|
${TEST_QT_MODULES}
|
|
)
|
|
target_link_libraries(url_utils_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
|
target_link_libraries(
|
|
url_scheme_event_filter_test libcockatrice_utility_gui Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
|
|
)
|
|
target_link_libraries(intent_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
|
target_link_libraries(
|
|
single_instance_manager_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
|
|
)
|
|
|
|
add_subdirectory(card_zone_algorithms)
|
|
add_subdirectory(carddatabase)
|
|
add_subdirectory(loading_from_clipboard)
|
|
add_subdirectory(movecard_tests)
|
|
add_subdirectory(oracle)
|