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