diff --git a/cockatrice/src/interface/window_main.cpp b/cockatrice/src/interface/window_main.cpp index f0e616615..b49146101 100644 --- a/cockatrice/src/interface/window_main.cpp +++ b/cockatrice/src/interface/window_main.cpp @@ -708,6 +708,12 @@ void MainWindow::applyStartupDestination() return; } + // A cockatrice:// link owns the startup connection while its chain runs; + // connecting here would race (and tear down) the link's own connection. + if (skipStartupAutoConnect) { + return; + } + const int destination = SettingsCache::instance().tabs().getStartupTabIndex(); if (destination != StartupTab::StartupTabServer && destination != StartupTab::StartupTabServerRoom) { return; @@ -936,6 +942,16 @@ void MainWindow::onUrlChainFinished(bool connected) if (connected || !skipStartupAutoConnect || getRemoteClient()->getStatus() != StatusDisconnected) { return; } + + if (startupDestinationConnectsToServer()) { + // Users whose startup tab is a Server / Server Room connect through the + // startup destination, not through auto-connect; retry that instead. + qCInfo(WindowMainStartupAutoconnectLog) << "URL chain ended without a connection; retrying startup destination"; + skipStartupAutoConnect = false; + applyStartupDestination(); + return; + } + qCInfo(WindowMainStartupAutoconnectLog) << "URL chain ended without a connection; retrying startup connect"; skipStartupAutoConnect = false; attemptStartupAutoConnect(); diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 3eca19770..1a3d20d6b 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -331,9 +331,17 @@ int main(int argc, char *argv[]) // URL connects to the server named in the URL, so the window's own startup // auto-connect must not race against it (two connectToServer calls tear // each other down via doDisconnectFromServer). - const bool hasUrlActivation = std::any_of(startupFiles.begin(), startupFiles.end(), [](const QString &file) { + bool hasUrlActivation = std::any_of(startupFiles.begin(), startupFiles.end(), [](const QString &file) { return file.startsWith(QStringLiteral("cockatrice://")); }); +#ifdef Q_OS_MAC + // On macOS the launch can arrive through the URL scheme instead of as a + // positional argument (captured in pendingMacUrls); count those too or the + // window would auto-connect into the link's own connection attempt. + hasUrlActivation = hasUrlActivation || + std::any_of(pendingMacUrls.cbegin(), pendingMacUrls.cend(), + [](const QString &url) { return url.startsWith(QStringLiteral("cockatrice://")); }); +#endif ui.setSkipStartupAutoConnect(hasUrlActivation); auto handleActivation = [&ui](const QString &file) {