mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 19:47:46 -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
|
|
@ -145,6 +145,7 @@ target_link_libraries(
|
|||
PUBLIC libcockatrice_card
|
||||
PUBLIC libcockatrice_settings
|
||||
PUBLIC libcockatrice_network
|
||||
PUBLIC libcockatrice_utility_gui
|
||||
PUBLIC ${ORACLE_QT_MODULES}
|
||||
)
|
||||
|
||||
|
|
@ -167,7 +168,7 @@ if(UNIX)
|
|||
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.plist)
|
||||
set_target_properties(oracle PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/Info.oracle.plist)
|
||||
|
||||
install(TARGETS oracle BUNDLE DESTINATION ./)
|
||||
else()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
Version=1.0
|
||||
Type=Application
|
||||
Name=Cockatrice Oracle downloader
|
||||
Exec=oracle
|
||||
Exec=oracle %u
|
||||
Icon=oracle
|
||||
Categories=Game;CardGame;
|
||||
MimeType=x-scheme-handler/cockatrice-oracle;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#include <QLibraryInfo>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
#include <libcockatrice/utility/url_utils.h>
|
||||
#include <libcockatrice/utility_gui/url_scheme_event_filter.h>
|
||||
|
||||
QTranslator *translator, *qtTranslator;
|
||||
ThemeManager *themeManager;
|
||||
|
|
@ -63,10 +65,26 @@ int main(int argc, char *argv[])
|
|||
QCommandLineOption backgroundOption("b", QCoreApplication::translate("main", "Run in no-confirm background mode"));
|
||||
parser.addOption(spoilersOnlyOption);
|
||||
parser.addOption(backgroundOption);
|
||||
parser.addPositionalArgument(
|
||||
"url", QCoreApplication::translate("main", "Optional cockatrice-oracle:// URL to handle"), "[url]");
|
||||
parser.process(app);
|
||||
isSpoilersOnly = parser.isSet(spoilersOnlyOption);
|
||||
isBackgrounded = parser.isSet(backgroundOption);
|
||||
|
||||
// Handle cockatrice-oracle:// URL passed via the OS URL scheme handler
|
||||
const QString oracleUrl =
|
||||
UrlUtils::findUrlArgument(parser.positionalArguments(), QStringLiteral("cockatrice-oracle://"));
|
||||
if (!oracleUrl.isEmpty()) {
|
||||
const auto action = UrlUtils::parseOracleUrl(oracleUrl);
|
||||
if (action.isUpdate) {
|
||||
isBackgrounded = true;
|
||||
if (action.spoilersOnly)
|
||||
isSpoilersOnly = true;
|
||||
} else {
|
||||
qDebug() << "Oracle: ignoring unknown cockatrice-oracle:// URL:" << oracleUrl;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
translationPath = qApp->applicationDirPath() + "/../Resources/translations";
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
|
@ -88,6 +106,27 @@ int main(int argc, char *argv[])
|
|||
// set name of the app desktop file; used by wayland to load the window icon
|
||||
QGuiApplication::setDesktopFileName("oracle");
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// On macOS the OS delivers a registered URL scheme via QFileOpenEvent,
|
||||
// dispatched on the first event-loop spin. Oracle has no nested event
|
||||
// loop before app.exec(), so installing the filter here (after wizard
|
||||
// construction but before app.exec()) is sufficient — the cold-start URL
|
||||
// event sits in the queue until app.exec() dispatches it, by which point
|
||||
// both the filter and wizard exist.
|
||||
UrlSchemeEventFilter oracleFilter(QStringLiteral("cockatrice-oracle://"));
|
||||
QObject::connect(&oracleFilter, &UrlSchemeEventFilter::urlReceived, &wizard, [&wizard](const QString &url) {
|
||||
const auto action = UrlUtils::parseOracleUrl(url);
|
||||
if (!action.isUpdate) {
|
||||
qDebug() << "Oracle: ignoring unknown cockatrice-oracle:// URL:" << url;
|
||||
return;
|
||||
}
|
||||
if (action.spoilersOnly)
|
||||
isSpoilersOnly = true;
|
||||
QTimer::singleShot(0, &wizard, [&wizard]() { wizard.runInBackground(); });
|
||||
});
|
||||
app.installEventFilter(&oracleFilter);
|
||||
#endif
|
||||
|
||||
wizard.show();
|
||||
|
||||
if (isBackgrounded) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue