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>
318 lines
9.1 KiB
CMake
318 lines
9.1 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(Oracle VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
|
|
|
# ------------------------
|
|
# Paths and directories
|
|
# ------------------------
|
|
set(DESKTOPDIR
|
|
share/applications
|
|
CACHE STRING "path to .desktop files"
|
|
)
|
|
|
|
set(ORACLE_MAC_QM_INSTALL_DIR "oracle.app/Contents/Resources/translations")
|
|
set(ORACLE_UNIX_QM_INSTALL_DIR "share/oracle/translations")
|
|
set(ORACLE_WIN32_QM_INSTALL_DIR "translations")
|
|
|
|
# ------------------------
|
|
# Sources
|
|
# ------------------------
|
|
set(oracle_SOURCES
|
|
src/main.cpp
|
|
src/oraclewizard.cpp
|
|
src/oracleimporter.cpp
|
|
src/pages.cpp
|
|
src/pagetemplates.cpp
|
|
src/parsehelpers.cpp
|
|
src/qt-json/json.cpp
|
|
../cockatrice/src/client/settings/cache_settings.cpp
|
|
../cockatrice/src/client/settings/card_counter_settings.cpp
|
|
../cockatrice/src/client/settings/shortcuts_settings.cpp
|
|
../cockatrice/src/client/network/update/client/release_channel.cpp
|
|
../cockatrice/src/interface/theme_manager.cpp
|
|
../cockatrice/src/interface/widgets/quick_settings/settings_button_widget.cpp
|
|
../cockatrice/src/interface/widgets/quick_settings/settings_popup_widget.cpp
|
|
${VERSION_STRING_CPP}
|
|
)
|
|
|
|
# ------------------------
|
|
# Translations
|
|
# ------------------------
|
|
|
|
if(UPDATE_TRANSLATIONS)
|
|
file(GLOB_RECURSE translate_oracle_SRCS src/*.cpp src/*.h ../cockatrice/src/settingscache.cpp)
|
|
set(translate_SRCS ${translate_oracle_SRCS})
|
|
set(oracle_TS "${CMAKE_CURRENT_SOURCE_DIR}/oracle_en@source.ts")
|
|
else()
|
|
file(GLOB oracle_TS "${CMAKE_CURRENT_SOURCE_DIR}/translations/*.ts")
|
|
endif(UPDATE_TRANSLATIONS)
|
|
|
|
if(WIN32)
|
|
set(oracle_SOURCES ${oracle_SOURCES} oracle.rc)
|
|
endif(WIN32)
|
|
|
|
if(APPLE)
|
|
set(MACOSX_BUNDLE_ICON_FILE appicon.icns)
|
|
set_source_files_properties(
|
|
${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources
|
|
)
|
|
set(oracle_SOURCES ${oracle_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns)
|
|
endif(APPLE)
|
|
|
|
set(oracle_RESOURCES oracle.qrc)
|
|
|
|
# ------------------------
|
|
# Qt resources
|
|
# ------------------------
|
|
if(Qt6_FOUND)
|
|
qt6_add_resources(oracle_RESOURCES_RCC ${oracle_RESOURCES})
|
|
elseif(Qt5_FOUND)
|
|
qt5_add_resources(oracle_RESOURCES_RCC ${oracle_RESOURCES})
|
|
endif()
|
|
|
|
# ------------------------
|
|
# Include directories
|
|
# ------------------------
|
|
include_directories(../cockatrice/src)
|
|
|
|
# ------------------------
|
|
# Optional libraries
|
|
# ------------------------
|
|
# ZLIB
|
|
find_package(ZLIB)
|
|
if(ZLIB_FOUND)
|
|
include_directories(${ZLIB_INCLUDE_DIRS})
|
|
add_definitions("-DHAS_ZLIB")
|
|
list(APPEND oracle_SOURCES src/zip/unzip.cpp src/zip/zipglobal.cpp)
|
|
else()
|
|
message(STATUS "Oracle: zlib not found; ZIP support disabled")
|
|
endif()
|
|
|
|
# LZMA
|
|
find_package(LibLZMA)
|
|
if(LIBLZMA_FOUND)
|
|
include_directories(${LIBLZMA_INCLUDE_DIRS})
|
|
add_definitions("-DHAS_LZMA")
|
|
list(APPEND oracle_SOURCES src/lzma/decompress.cpp)
|
|
else()
|
|
message(STATUS "Oracle: LibLZMA not found; xz support disabled")
|
|
endif()
|
|
|
|
# ------------------------
|
|
# Build executable
|
|
# ------------------------
|
|
|
|
set(ORACLE_MAC_QM_INSTALL_DIR "oracle.app/Contents/Resources/translations")
|
|
set(ORACLE_UNIX_QM_INSTALL_DIR "share/oracle/translations")
|
|
set(ORACLE_WIN32_QM_INSTALL_DIR "translations")
|
|
|
|
if(Qt6_FOUND)
|
|
# Qt6 Translations are linked after the executable is created in manual mode
|
|
qt6_add_executable(
|
|
oracle
|
|
WIN32
|
|
MACOSX_BUNDLE
|
|
${oracle_SOURCES}
|
|
${oracle_RESOURCES_RCC}
|
|
${oracle_MOC_SRCS}
|
|
MANUAL_FINALIZATION
|
|
)
|
|
elseif(Qt5_FOUND)
|
|
# Qt5 Translations need to be linked at executable creation time
|
|
if(Qt5LinguistTools_FOUND)
|
|
if(UPDATE_TRANSLATIONS)
|
|
qt5_create_translation(oracle_QM ${translate_SRCS} ${oracle_TS})
|
|
else()
|
|
qt5_add_translation(oracle_QM ${oracle_TS})
|
|
endif()
|
|
endif()
|
|
add_executable(oracle WIN32 MACOSX_BUNDLE ${oracle_MOC_SRCS} ${oracle_QM} ${oracle_RESOURCES_RCC} ${oracle_SOURCES})
|
|
if(UNIX)
|
|
if(APPLE)
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_MAC_QM_INSTALL_DIR})
|
|
else()
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_UNIX_QM_INSTALL_DIR})
|
|
endif()
|
|
elseif(WIN32)
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_WIN32_QM_INSTALL_DIR})
|
|
endif()
|
|
endif()
|
|
|
|
# ------------------------
|
|
# Link libraries
|
|
# ------------------------
|
|
target_link_libraries(
|
|
oracle
|
|
PUBLIC libcockatrice_card
|
|
PUBLIC libcockatrice_settings
|
|
PUBLIC libcockatrice_network
|
|
PUBLIC libcockatrice_utility_gui
|
|
PUBLIC ${ORACLE_QT_MODULES}
|
|
)
|
|
|
|
if(ZLIB_FOUND)
|
|
target_link_libraries(oracle PUBLIC ${ZLIB_LIBRARIES})
|
|
endif()
|
|
|
|
if(LIBLZMA_FOUND)
|
|
target_link_libraries(oracle PUBLIC ${LIBLZMA_LIBRARIES})
|
|
endif()
|
|
|
|
# ------------------------
|
|
# Install rules
|
|
# ------------------------
|
|
if(UNIX)
|
|
if(APPLE)
|
|
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME}")
|
|
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.cockatrice.${PROJECT_NAME}")
|
|
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME}-${PROJECT_VERSION}")
|
|
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
|
|
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION})
|
|
set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
|
|
set_target_properties(oracle PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/Info.oracle.plist)
|
|
|
|
install(TARGETS oracle BUNDLE DESTINATION ./)
|
|
else()
|
|
# Assume linux
|
|
install(TARGETS oracle RUNTIME DESTINATION bin/)
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/oracle.png DESTINATION ${ICONDIR}/hicolor/48x48/apps)
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/oracle.svg DESTINATION ${ICONDIR}/hicolor/scalable/apps)
|
|
endif()
|
|
elseif(WIN32)
|
|
install(TARGETS oracle RUNTIME DESTINATION ./)
|
|
endif()
|
|
|
|
if(NOT WIN32 AND NOT APPLE)
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/oracle.desktop DESTINATION ${DESKTOPDIR})
|
|
endif(NOT WIN32 AND NOT APPLE)
|
|
|
|
# ------------------------
|
|
# Qt plugin handling
|
|
# ------------------------
|
|
if(APPLE)
|
|
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
|
set(plugin_dest_dir oracle.app/Contents/Plugins)
|
|
set(qtconf_dest_dir oracle.app/Contents/Resources)
|
|
|
|
# Qt plugins: iconengines, platforms, styles, tls (Qt6)
|
|
install(
|
|
DIRECTORY "${QT_PLUGINS_DIR}/"
|
|
DESTINATION ${plugin_dest_dir}
|
|
COMPONENT Runtime
|
|
FILES_MATCHING
|
|
PATTERN "*.dSYM" EXCLUDE
|
|
PATTERN "*_debug.dylib" EXCLUDE
|
|
PATTERN "iconengines/*.dylib"
|
|
PATTERN "platforms/*.dylib"
|
|
PATTERN "styles/*.dylib"
|
|
PATTERN "tls/*.dylib"
|
|
)
|
|
|
|
install(
|
|
CODE "
|
|
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
|
Plugins = Plugins
|
|
Translations = Resources/translations\")
|
|
"
|
|
COMPONENT Runtime
|
|
)
|
|
|
|
install(
|
|
CODE "
|
|
file(GLOB_RECURSE QTPLUGINS
|
|
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dylib\")
|
|
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
|
include(BundleUtilities)
|
|
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
|
"
|
|
COMPONENT Runtime
|
|
)
|
|
endif()
|
|
|
|
if(WIN32)
|
|
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
|
set(plugin_dest_dir Plugins)
|
|
set(qtconf_dest_dir .)
|
|
list(APPEND libSearchDirs ${QT_LIBRARY_DIR})
|
|
|
|
install(
|
|
DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${CMAKE_BUILD_TYPE}/"
|
|
DESTINATION ./
|
|
FILES_MATCHING
|
|
PATTERN "*.dll"
|
|
)
|
|
|
|
# Qt plugins: iconengines, platforms, styles, tls (Qt6)
|
|
install(
|
|
DIRECTORY "${QT_PLUGINS_DIR}/"
|
|
DESTINATION ${plugin_dest_dir}
|
|
COMPONENT Runtime
|
|
FILES_MATCHING
|
|
PATTERN "iconengines/qsvgicon.dll"
|
|
PATTERN "platforms/qdirect2d.dll"
|
|
PATTERN "platforms/qminimal.dll"
|
|
PATTERN "platforms/qoffscreen.dll"
|
|
PATTERN "platforms/qwindows.dll"
|
|
PATTERN "styles/qcertonlybackend.dll"
|
|
PATTERN "styles/qopensslbackend.dll"
|
|
PATTERN "styles/qschannelbackend.dll"
|
|
PATTERN "styles/qwindowsvistastyle.dll"
|
|
PATTERN "tls/qcertonlybackend.dll"
|
|
PATTERN "tls/qopensslbackend.dll"
|
|
PATTERN "tls/qschannelbackend.dll"
|
|
)
|
|
|
|
install(
|
|
CODE "
|
|
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
|
Plugins = Plugins
|
|
Translations = Resources/translations\")
|
|
"
|
|
COMPONENT Runtime
|
|
)
|
|
|
|
install(
|
|
CODE "
|
|
file(GLOB_RECURSE QTPLUGINS
|
|
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
|
|
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
|
include(BundleUtilities)
|
|
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/Oracle.exe\" \"\${QTPLUGINS}\" \"${libSearchDirs}\")
|
|
"
|
|
COMPONENT Runtime
|
|
)
|
|
endif()
|
|
|
|
# ------------------------
|
|
# Qt translations
|
|
# ------------------------
|
|
if(Qt6_FOUND AND Qt6LinguistTools_FOUND)
|
|
#Qt6 Translations happen after the executable is built up
|
|
if(UPDATE_TRANSLATIONS)
|
|
qt6_add_translations(
|
|
oracle
|
|
TS_FILES
|
|
${oracle_TS}
|
|
SOURCES
|
|
${translate_SRCS}
|
|
QM_FILES_OUTPUT_VARIABLE
|
|
oracle_QM
|
|
)
|
|
else()
|
|
qt6_add_translations(oracle TS_FILES ${oracle_TS} QM_FILES_OUTPUT_VARIABLE oracle_QM)
|
|
endif()
|
|
|
|
if(UNIX)
|
|
if(APPLE)
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_MAC_QM_INSTALL_DIR})
|
|
else()
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_UNIX_QM_INSTALL_DIR})
|
|
endif()
|
|
elseif(WIN32)
|
|
install(FILES ${oracle_QM} DESTINATION ${ORACLE_WIN32_QM_INSTALL_DIR})
|
|
endif()
|
|
endif()
|
|
|
|
if(Qt6_FOUND)
|
|
qt6_finalize_target(oracle)
|
|
endif()
|