diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index 8da1d0f5..6202261e 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -36,15 +36,9 @@ GridView { onVisibleChanged: { if (visible) { - // Start polling when this view is shown - ComputerManager.startPolling() - appModel.computerLost.connect(computerLost) } else { - // Stop polling when this view is not on top - ComputerManager.stopPollingAsync() - appModel.computerLost.disconnect(computerLost) } } diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index d97dd443..4766e307 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -2,6 +2,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Dialogs 1.3 import QtQuick.Layouts 1.3 +import QtQuick.Window 2.2 import ComputerModel 1.0 @@ -42,25 +43,11 @@ GridView { } } - 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) { // Close the PIN dialog pairDialog.close() - // Start polling again - ComputerManager.startPolling() - // Display a failed dialog if we got an error if (error !== null) { errorDialog.text = error @@ -176,9 +163,6 @@ GridView { if (!model.busy) { var pin = ("0000" + Math.floor(Math.random() * 10000)).slice(-4) - // Stop polling, since pairing may make GFE unresponsive - ComputerManager.stopPollingAsync() - // Kick off pairing in the background computerModel.pairComputer(index, pin) diff --git a/app/gui/QuitSegue.qml b/app/gui/QuitSegue.qml index 5ef6bcc5..455bf993 100644 --- a/app/gui/QuitSegue.qml +++ b/app/gui/QuitSegue.qml @@ -44,16 +44,10 @@ Item { if (visible) { // Connect the quit completion signal ComputerManager.quitAppCompleted.connect(quitAppCompleted) - - // We must be polling or we won't get the quitAppCompleted() callback - ComputerManager.startPolling() } else { // Disconnect the signal ComputerManager.quitAppCompleted.disconnect(quitAppCompleted) - - // Stop polling when this view is not on top - ComputerManager.stopPollingAsync() } } diff --git a/app/gui/main.qml b/app/gui/main.qml index 956d9d36..9e35f912 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -1,12 +1,16 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 +import QtQuick.Window 2.2 import QtQuick.Controls.Material 2.1 +import ComputerManager 1.0 import AutoUpdateChecker 1.0 ApplicationWindow { + property bool pollingActive: false + id: window visible: true width: 1280 @@ -21,6 +25,24 @@ ApplicationWindow { anchors.fill: parent } + onVisibilityChanged: { + // We don't want to just use 'active' here because that will stop polling if + // we lose focus, which might be overzealous for users with multiple screens + // where we may be clearly visible on the other display. Ideally we'll poll + // only if the window is visible to the user (not if obscured by other windows), + // but it seems difficult to do this portably. + var shouldPoll = visibility !== Window.Minimized && visibility !== Window.Hidden + + if (shouldPoll && !pollingActive) { + ComputerManager.startPolling() + pollingActive = true + } + else if (!shouldPoll && pollingActive) { + ComputerManager.stopPollingAsync() + pollingActive = false + } + } + function navigateTo(url, objectName) { var existingItem = stackView.find(function(item, index) {