mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
feat: register cockatrice:// and cockatrice-oracle:// protocol handlers
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>
This commit is contained in:
parent
762e742be0
commit
371b74732e
54 changed files with 2147 additions and 57 deletions
21
libcockatrice_utility_gui/CMakeLists.txt
Normal file
21
libcockatrice_utility_gui/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(UtilityGui VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
# Sibling of libcockatrice_utility but carries the Qt::Gui dependency so that
|
||||
# libcockatrice_utility (consumed transitively by the headless servatrice) can
|
||||
# stay Core+Network only. Host Gui-needing shared utility code here.
|
||||
|
||||
set(UTILITY_GUI_HEADERS libcockatrice/utility_gui/url_scheme_event_filter.h)
|
||||
|
||||
# Header-only Q_OBJECT classes need a .cpp anchor so AUTOMOC has somewhere to
|
||||
# compile the generated meta-object code. An INTERFACE library skips AUTOMOC,
|
||||
# so we use a STATIC lib + tiny stub.
|
||||
add_library(libcockatrice_utility_gui STATIC ${UTILITY_GUI_HEADERS} libcockatrice/utility_gui/stub.cpp)
|
||||
|
||||
target_include_directories(libcockatrice_utility_gui PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(libcockatrice_utility_gui PUBLIC ${QT_CORE_MODULE} ${QT_GUI_MODULE})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// AUTOMOC anchor for header-only Q_OBJECT classes in libcockatrice_utility_gui.
|
||||
// Intentionally empty — AUTOMOC needs at least one translation unit to live in.
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef LIBCOCKATRICE_URL_SCHEME_EVENT_FILTER_H
|
||||
#define LIBCOCKATRICE_URL_SCHEME_EVENT_FILTER_H
|
||||
|
||||
// Lives in libcockatrice_utility_gui (not libcockatrice_utility) because
|
||||
// QFileOpenEvent is in Qt::Gui, and libcockatrice_utility is intentionally
|
||||
// Core+Network-only so servatrice (headless server, transitively consumes
|
||||
// libcockatrice_utility) does not pull in Qt::Gui.
|
||||
|
||||
#include <QEvent>
|
||||
#include <QFileOpenEvent>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief Event filter that catches QFileOpenEvent URLs matching a scheme
|
||||
* prefix and re-emits them as urlReceived().
|
||||
*
|
||||
* On macOS, when the application is registered as a URL scheme handler, the
|
||||
* OS delivers incoming URLs via QFileOpenEvent on the QApplication object.
|
||||
* Install this filter on QApplication to intercept them:
|
||||
*
|
||||
* @code
|
||||
* UrlSchemeEventFilter filter(QStringLiteral("cockatrice://"));
|
||||
* QObject::connect(&filter, &UrlSchemeEventFilter::urlReceived,
|
||||
* &mainWindow, &MainWindow::handleUrl);
|
||||
* app.installEventFilter(&filter);
|
||||
* @endcode
|
||||
*
|
||||
* Scheme matching is case-insensitive (per RFC 3986). Matching events are
|
||||
* consumed (eventFilter returns true) so they do not propagate to other
|
||||
* QFileOpenEvent handlers. If the app ever handles non-URL file-open events
|
||||
* (e.g. .cor file association), make sure those handlers see the events first
|
||||
* by installing this filter LAST, or by ensuring the prefix uniquely
|
||||
* partitions URL events from file events.
|
||||
*/
|
||||
class UrlSchemeEventFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UrlSchemeEventFilter(const QString &schemePrefix, QObject *parent = nullptr)
|
||||
: QObject(parent), m_prefix(schemePrefix)
|
||||
{
|
||||
}
|
||||
|
||||
signals:
|
||||
void urlReceived(const QString &url);
|
||||
|
||||
public:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override
|
||||
{
|
||||
if (event->type() == QEvent::FileOpen) {
|
||||
const QString url = static_cast<QFileOpenEvent *>(event)->url().toString();
|
||||
if (url.startsWith(m_prefix, Qt::CaseInsensitive)) {
|
||||
emit urlReceived(url);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_prefix;
|
||||
};
|
||||
|
||||
#endif // LIBCOCKATRICE_URL_SCHEME_EVENT_FILTER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue