mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-10 13:44:17 +00:00
Properly manage the lifetime of polling in the AppView and PcView
This commit is contained in:
parent
83ca211d75
commit
a47f59d1a4
4 changed files with 33 additions and 22 deletions
|
@ -269,7 +269,7 @@ bool NvComputer::update(NvComputer& that)
|
|||
|
||||
ComputerManager::ComputerManager(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_Polling(false),
|
||||
m_PollingRef(0),
|
||||
m_MdnsBrowser(nullptr)
|
||||
{
|
||||
QSettings settings;
|
||||
|
@ -302,12 +302,10 @@ void ComputerManager::startPolling()
|
|||
{
|
||||
QWriteLocker lock(&m_Lock);
|
||||
|
||||
if (m_Polling) {
|
||||
if (++m_PollingRef > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Polling = true;
|
||||
|
||||
// Start an MDNS query for GameStream hosts
|
||||
m_MdnsBrowser = new QMdnsEngine::Browser(&m_MdnsServer, "_nvstream._tcp.local.", &m_MdnsCache);
|
||||
connect(m_MdnsBrowser, &QMdnsEngine::Browser::serviceAdded,
|
||||
|
@ -400,12 +398,11 @@ void ComputerManager::stopPollingAsync()
|
|||
{
|
||||
QWriteLocker lock(&m_Lock);
|
||||
|
||||
if (!m_Polling) {
|
||||
Q_ASSERT(m_PollingRef > 0);
|
||||
if (--m_PollingRef > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Polling = false;
|
||||
|
||||
// Delete machines that haven't been resolved yet
|
||||
while (!m_PendingResolution.isEmpty()) {
|
||||
MdnsPendingComputer* computer = m_PendingResolution.first();
|
||||
|
@ -456,7 +453,7 @@ ComputerManager::handleComputerStateChanged(NvComputer* computer)
|
|||
void
|
||||
ComputerManager::startPollingComputer(NvComputer* computer)
|
||||
{
|
||||
if (!m_Polling) {
|
||||
if (m_PollingRef == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ private:
|
|||
|
||||
void startPollingComputer(NvComputer* computer);
|
||||
|
||||
bool m_Polling;
|
||||
int m_PollingRef;
|
||||
QReadWriteLock m_Lock;
|
||||
QMap<QString, NvComputer*> m_KnownHosts;
|
||||
QMap<QString, QThread*> m_PollThreads;
|
||||
|
|
|
@ -17,14 +17,20 @@ GridView {
|
|||
cellWidth: 225; cellHeight: 350;
|
||||
focus: true
|
||||
|
||||
Component.onCompleted: {
|
||||
// Start polling when this view is shown
|
||||
ComputerManager.startPolling()
|
||||
}
|
||||
// The StackView will trigger a visibility change when
|
||||
// we're pushed onto it, causing our onVisibleChanged
|
||||
// routine to run, but only if we start as invisible
|
||||
visible: false
|
||||
|
||||
Component.onDestruction: {
|
||||
// Stop polling when this view is destroyed
|
||||
ComputerManager.stopPollingAsync()
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
// Start polling when this view is shown
|
||||
ComputerManager.startPolling()
|
||||
}
|
||||
else {
|
||||
// Stop polling when this view is not on top
|
||||
ComputerManager.stopPollingAsync()
|
||||
}
|
||||
}
|
||||
|
||||
function createModel()
|
||||
|
|
|
@ -19,17 +19,25 @@ GridView {
|
|||
focus: true
|
||||
objectName: "Computers"
|
||||
|
||||
Component.onCompleted: {
|
||||
// Start polling when this view is shown
|
||||
ComputerManager.startPolling()
|
||||
// The StackView will trigger a visibility change when
|
||||
// we're pushed onto it, causing our onVisibleChanged
|
||||
// routine to run, but only if we start as invisible
|
||||
visible: false
|
||||
|
||||
Component.onCompleted: {
|
||||
// Setup signals on CM
|
||||
ComputerManager.computerAddCompleted.connect(addComplete)
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
// Stop polling when this view is destroyed
|
||||
ComputerManager.stopPollingAsync()
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
// Start polling when this view is shown
|
||||
ComputerManager.startPolling()
|
||||
}
|
||||
else {
|
||||
// Stop polling when this view is not top-most
|
||||
ComputerManager.stopPollingAsync()
|
||||
}
|
||||
}
|
||||
|
||||
function pairingComplete(error)
|
||||
|
|
Loading…
Reference in a new issue