From 5034a324b4b280254f783c0c611c3773f0368e75 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 28 Jun 2026 11:43:33 -0500 Subject: [PATCH] Fix manual address being clobbered when using the CLI Fixes #1920 --- app/backend/computerseeker.cpp | 35 ++++++++++++++++++++++++---------- app/backend/computerseeker.h | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/backend/computerseeker.cpp b/app/backend/computerseeker.cpp index a9c46ffd..574098a6 100644 --- a/app/backend/computerseeker.cpp +++ b/app/backend/computerseeker.cpp @@ -7,11 +7,9 @@ ComputerSeeker::ComputerSeeker(ComputerManager *manager, QString computerName, Q m_TimeoutTimer(new QTimer(this)) { // If we know this computer, send a WOL packet to wake it up in case it is asleep. - const auto computers = m_ComputerManager->getComputers(); - for (NvComputer* computer : computers) { - if (this->matchComputer(computer)) { - computer->wake(); - } + NvComputer* matchingComputer = findMatchingComputer(); + if (matchingComputer) { + matchingComputer->wake(); } m_TimeoutTimer->setSingleShot(true); @@ -24,11 +22,16 @@ ComputerSeeker::ComputerSeeker(ComputerManager *manager, QString computerName, Q void ComputerSeeker::start(int timeout) { m_TimeoutTimer->start(timeout); - // Seek desired computer by both connecting to it directly (this may fail - // if m_ComputerName is UUID, or the name that doesn't resolve to an IP - // address) and by polling it using mDNS, hopefully one of these methods - // would find the host - m_ComputerManager->addNewHostManually(m_ComputerName); + + // If we don't know this computer by name, address, or UUID, try adding it + // manually and see if we can find it by address, hostname, or mDNS. + // + // NB: We don't do this unconditionally because it will wipe out the user's + // manual address if they pass another reachable hostname/address. + if (!findMatchingComputer()) { + m_ComputerManager->addNewHostManually(m_ComputerName); + } + m_ComputerManager->startPolling(); } @@ -62,6 +65,18 @@ bool ComputerSeeker::matchComputer(NvComputer *computer) const return false; } +NvComputer* ComputerSeeker::findMatchingComputer() const +{ + const auto computers = m_ComputerManager->getComputers(); + for (NvComputer* computer : computers) { + if (this->matchComputer(computer)) { + return computer; + } + } + + return nullptr; +} + bool ComputerSeeker::isOnline(NvComputer *computer) const { return computer->state == NvComputer::CS_ONLINE; diff --git a/app/backend/computerseeker.h b/app/backend/computerseeker.h index 8f5c19ae..98adfabd 100644 --- a/app/backend/computerseeker.h +++ b/app/backend/computerseeker.h @@ -24,6 +24,7 @@ private slots: private: bool matchComputer(NvComputer *computer) const; + NvComputer* findMatchingComputer() const; bool isOnline(NvComputer *computer) const; private: