mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Client] Skip the startup connection when a macOS URL launch owns the connection
This commit is contained in:
parent
4be2dd2f22
commit
82d71344f1
2 changed files with 25 additions and 1 deletions
|
|
@ -708,6 +708,12 @@ void MainWindow::applyStartupDestination()
|
||||||
return;
|
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();
|
const int destination = SettingsCache::instance().tabs().getStartupTabIndex();
|
||||||
if (destination != StartupTab::StartupTabServer && destination != StartupTab::StartupTabServerRoom) {
|
if (destination != StartupTab::StartupTabServer && destination != StartupTab::StartupTabServerRoom) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -936,6 +942,16 @@ void MainWindow::onUrlChainFinished(bool connected)
|
||||||
if (connected || !skipStartupAutoConnect || getRemoteClient()->getStatus() != StatusDisconnected) {
|
if (connected || !skipStartupAutoConnect || getRemoteClient()->getStatus() != StatusDisconnected) {
|
||||||
return;
|
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";
|
qCInfo(WindowMainStartupAutoconnectLog) << "URL chain ended without a connection; retrying startup connect";
|
||||||
skipStartupAutoConnect = false;
|
skipStartupAutoConnect = false;
|
||||||
attemptStartupAutoConnect();
|
attemptStartupAutoConnect();
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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
|
// auto-connect must not race against it (two connectToServer calls tear
|
||||||
// each other down via doDisconnectFromServer).
|
// 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://"));
|
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);
|
ui.setSkipStartupAutoConnect(hasUrlActivation);
|
||||||
|
|
||||||
auto handleActivation = [&ui](const QString &file) {
|
auto handleActivation = [&ui](const QString &file) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue