| 518 | } |
| 519 | |
| 520 | void BackendCommander::onStateUpdated(IPC::Command *command) |
| 521 | { |
| 522 | static std::string prevStr; |
| 523 | std::string str; |
| 524 | |
| 525 | IPC::CliCommands::State *cmd = static_cast<IPC::CliCommands::State *>(command); |
| 526 | |
| 527 | if (cliArgs_.cliCommand() == CLI_COMMAND_CONNECT || cliArgs_.cliCommand() == CLI_COMMAND_CONNECT_BEST |
| 528 | || cliArgs_.cliCommand() == CLI_COMMAND_CONNECT_LOCATION || cliArgs_.cliCommand() == CLI_COMMAND_CONNECT_STATIC) { |
| 529 | if (connectId_.isEmpty() && cmd->connectState_.connectState == CONNECT_STATE_CONNECTING) { |
| 530 | connectId_ = cmd->connectId_; |
| 531 | } |
| 532 | |
| 533 | if (cmd->connectState_.connectState == CONNECT_STATE_DISCONNECTED && cmd->connectState_.connectError != NO_CONNECT_ERROR || |
| 534 | cmd->connectState_.connectState == CONNECT_STATE_DISCONNECTED && cmd->connectState_.disconnectReason == DISCONNECTED_BY_KEY_LIMIT || |
| 535 | cmd->connectState_.connectState == CONNECT_STATE_DISCONNECTED && cmd->connectId_.isEmpty()) |
| 536 | { |
| 537 | // Disconnected with error |
| 538 | emit(finished(1, connectStateString(cmd->connectState_, cmd->location_, cmd->tunnelTestState_, false))); |
| 539 | } else if (cmd->connectState_.connectState == CONNECT_STATE_CONNECTED && cmd->tunnelTestState_ != TUNNEL_TEST_STATE_UNKNOWN) { |
| 540 | // connected with a known tunnel test state |
| 541 | emit(finished(0, connectStateString(cmd->connectState_, cmd->location_, cmd->tunnelTestState_, false))); |
| 542 | } else if (cmd->connectId_ != connectId_ && connectId_.isEmpty() && !cmd->connectId_.isEmpty() && |
| 543 | cmd->connectState_.connectState == CONNECT_STATE_CONNECTING || cmd->connectState_.connectState == CONNECT_STATE_DISCONNECTED) |
| 544 | { |
| 545 | emit(finished(1, QObject::tr("Connection has been overridden by another command."))); |
| 546 | } else { |
| 547 | str = connectStateString(cmd->connectState_, cmd->location_, cmd->tunnelTestState_, false).toStdString(); |
| 548 | if (str != prevStr) { |
| 549 | std::cout << str << std::endl; |
| 550 | prevStr = str; |
| 551 | } |
| 552 | // In progress: wait a short period before requesting status again |
| 553 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 554 | sendStateCommand(); |
| 555 | } |
| 556 | } else if (cliArgs_.cliCommand() == CLI_COMMAND_DISCONNECT) { |
| 557 | if (connectId_.isEmpty()) { |
| 558 | connectId_ = cmd->connectId_; |
| 559 | } |
| 560 | |
| 561 | if (cmd->connectState_.connectState == CONNECT_STATE_DISCONNECTED || cmd->connectId_.isEmpty()) { |
| 562 | cmd->connectState_.connectState = CONNECT_STATE_DISCONNECTED; |
| 563 | emit(finished(0, connectStateString(cmd->connectState_, cmd->location_, cmd->tunnelTestState_, false))); |
| 564 | } else if (cmd->connectId_ != connectId_) { |
| 565 | emit(finished(1, QObject::tr("Disconnection has been overridden by another command."))); |
| 566 | } else { |
| 567 | str = connectStateString(cmd->connectState_, cmd->location_, cmd->tunnelTestState_, false).toStdString(); |
| 568 | if (str != prevStr) { |
| 569 | std::cout << str << std::endl; |
| 570 | prevStr = str; |
| 571 | } |
| 572 | // In progress: wait a short period before requesting status again |
| 573 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 574 | sendStateCommand(); |
| 575 | } |
| 576 | } else if (cliArgs_.cliCommand() == CLI_COMMAND_LOGIN) { |
| 577 | if (cmd->loginState_ == LOGIN_STATE_LOGIN_ERROR && cmd->loginError_ == wsnet::LoginResult::kMissingCode2fa) { |
nothing calls this directly
no test coverage detected