mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 19:11:31 -07:00
371b74732e
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>
125 lines
4.2 KiB
CMake
125 lines
4.2 KiB
CMake
# Find a compatible Qt version
|
|
# Inputs: WITH_SERVER, WITH_CLIENT, WITH_ORACLE, FORCE_USE_QT5
|
|
# Optional Input: QT6_DIR -- Hint as to where Qt6 lives on the system
|
|
# Optional Input: QT5_DIR -- Hint as to where Qt5 lives on the system
|
|
# Output: COCKATRICE_QT_VERSION_NAME -- Example values: Qt5, Qt6
|
|
# Output: SERVATRICE_QT_MODULES
|
|
# Output: COCKATRICE_QT_MODULES
|
|
# Output: ORACLE_QT_MODULES
|
|
# Output: TEST_QT_MODULES
|
|
|
|
set(REQUIRED_QT_COMPONENTS Core)
|
|
if(WITH_SERVER)
|
|
set(_SERVATRICE_NEEDED Network Sql WebSockets)
|
|
endif()
|
|
if(WITH_CLIENT)
|
|
set(_COCKATRICE_NEEDED
|
|
Concurrent
|
|
Gui
|
|
Multimedia
|
|
Network
|
|
PrintSupport
|
|
Svg
|
|
WebSockets
|
|
Widgets
|
|
Xml
|
|
)
|
|
endif()
|
|
if(WITH_ORACLE)
|
|
set(_ORACLE_NEEDED Concurrent Network Svg Widgets)
|
|
endif()
|
|
if(TEST)
|
|
# Union of Qt modules required across all test targets (independent of application targets).
|
|
# When adding a new test that needs additional Qt modules, add them here rather than in the test's CMakeLists.txt.
|
|
set(_TEST_NEEDED Concurrent Network Svg Widgets)
|
|
endif()
|
|
|
|
set(REQUIRED_QT_COMPONENTS ${REQUIRED_QT_COMPONENTS} ${_SERVATRICE_NEEDED} ${_COCKATRICE_NEEDED} ${_ORACLE_NEEDED}
|
|
${_TEST_NEEDED}
|
|
)
|
|
list(REMOVE_DUPLICATES REQUIRED_QT_COMPONENTS)
|
|
|
|
if(NOT FORCE_USE_QT5)
|
|
# Linguist is now a component in Qt6 instead of an external package
|
|
find_package(
|
|
Qt6 6.4.2
|
|
COMPONENTS ${REQUIRED_QT_COMPONENTS} Linguist
|
|
QUIET HINTS ${Qt6_DIR}
|
|
)
|
|
endif()
|
|
if(Qt6_FOUND)
|
|
set(COCKATRICE_QT_VERSION_NAME Qt6)
|
|
|
|
list(FIND Qt6LinguistTools_TARGETS Qt6::lrelease QT6_LRELEASE_INDEX)
|
|
if(QT6_LRELEASE_INDEX EQUAL -1)
|
|
message(WARNING "Qt6 lrelease not found.")
|
|
endif()
|
|
|
|
list(FIND Qt6LinguistTools_TARGETS Qt6::lupdate QT6_LUPDATE_INDEX)
|
|
if(QT6_LUPDATE_INDEX EQUAL -1)
|
|
message(WARNING "Qt6 lupdate not found.")
|
|
endif()
|
|
else()
|
|
find_package(
|
|
Qt5 5.15.2
|
|
COMPONENTS ${REQUIRED_QT_COMPONENTS}
|
|
QUIET HINTS ${Qt5_DIR}
|
|
)
|
|
if(Qt5_FOUND)
|
|
set(COCKATRICE_QT_VERSION_NAME Qt5)
|
|
else()
|
|
message(FATAL_ERROR "No suitable version of Qt was found")
|
|
endif()
|
|
|
|
# Qt5 Linguist is in a separate package
|
|
find_package(Qt5LinguistTools QUIET)
|
|
if(Qt5LinguistTools_FOUND)
|
|
if(NOT Qt5_LRELEASE_EXECUTABLE)
|
|
message(WARNING "Qt5 lrelease not found.")
|
|
endif()
|
|
if(NOT Qt5_LUPDATE_EXECUTABLE)
|
|
message(WARNING "Qt5 lupdate not found.")
|
|
endif()
|
|
else()
|
|
message(WARNING "Linguist Tools not found, cannot handle translations")
|
|
endif()
|
|
endif()
|
|
|
|
if(Qt5_POSITION_INDEPENDENT_CODE OR Qt6_FOUND)
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
endif()
|
|
|
|
# Establish Qt Plugins directory & Library directories
|
|
get_target_property(QT_LIBRARY_DIR ${COCKATRICE_QT_VERSION_NAME}::Core LOCATION)
|
|
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} DIRECTORY)
|
|
if(Qt6_FOUND)
|
|
get_filename_component(QT_PLUGINS_DIR "${Qt6Core_DIR}/../../../${QT6_INSTALL_PLUGINS}" ABSOLUTE)
|
|
get_filename_component(QT_LIBRARY_DIR "${QT_LIBRARY_DIR}/../../.." ABSOLUTE)
|
|
if(UNIX AND APPLE)
|
|
# Mac needs a bit more help finding all necessary components
|
|
list(APPEND QT_LIBRARY_DIR "/usr/local/lib")
|
|
endif()
|
|
elseif(Qt5_FOUND)
|
|
get_filename_component(QT_PLUGINS_DIR "${Qt5Core_DIR}/../../../plugins" ABSOLUTE)
|
|
get_filename_component(QT_LIBRARY_DIR "${QT_LIBRARY_DIR}/.." ABSOLUTE)
|
|
endif()
|
|
message(DEBUG "QT_PLUGINS_DIR = ${QT_PLUGINS_DIR}")
|
|
message(DEBUG "QT_LIBRARY_DIR = ${QT_LIBRARY_DIR}")
|
|
|
|
# Establish exports
|
|
string(REGEX REPLACE "([^;]+)" "${COCKATRICE_QT_VERSION_NAME}::\\1" SERVATRICE_QT_MODULES "${_SERVATRICE_NEEDED}")
|
|
string(REGEX REPLACE "([^;]+)" "${COCKATRICE_QT_VERSION_NAME}::\\1" COCKATRICE_QT_MODULES "${_COCKATRICE_NEEDED}")
|
|
string(REGEX REPLACE "([^;]+)" "${COCKATRICE_QT_VERSION_NAME}::\\1" ORACLE_QT_MODULES "${_ORACLE_NEEDED}")
|
|
string(REGEX REPLACE "([^;]+)" "${COCKATRICE_QT_VERSION_NAME}::\\1" TEST_QT_MODULES "${_TEST_NEEDED}")
|
|
|
|
# Core-only export (useful for headless libs)
|
|
set(QT_CORE_MODULE "${COCKATRICE_QT_VERSION_NAME}::Core")
|
|
|
|
# Network-only export (useful for network-dependent libs that don't need GUI)
|
|
set(QT_NETWORK_MODULE "${COCKATRICE_QT_VERSION_NAME}::Network")
|
|
|
|
# GUI export
|
|
set(QT_GUI_MODULE "${COCKATRICE_QT_VERSION_NAME}::Gui")
|
|
|
|
message(STATUS "Found Qt ${${COCKATRICE_QT_VERSION_NAME}_VERSION} at: ${${COCKATRICE_QT_VERSION_NAME}_DIR}")
|