Stop polling machines after 5 minutes of inactivity to conserve power

This commit is contained in:
Cameron Gutman
2018-10-12 19:58:29 -07:00
parent 969afac696
commit e53b32fa57
+29 -14
View File
@@ -68,21 +68,36 @@ ApplicationWindow {
} }
} }
onVisibilityChanged: { // This timer keeps us polling for 5 minutes of inactivity
// We don't want to just use 'active' here because that will stop polling if // to allow the user to work with Moonlight on a second display
// we lose focus, which might be overzealous for users with multiple screens // while dealing with configuration issues. This will ensure
// where we may be clearly visible on the other display. Ideally we'll poll // machines come online even if the input focus isn't on Moonlight.
// only if the window is visible to the user (not if obscured by other windows), Timer {
// but it seems difficult to do this portably. id: inactivityTimer
var shouldPoll = visibility !== Window.Minimized && visibility !== Window.Hidden interval: 5 * 60000
onTriggered: {
if (shouldPoll && !pollingActive) { if (!active && pollingActive) {
ComputerManager.startPolling() ComputerManager.stopPollingAsync()
pollingActive = true pollingActive = false
}
} }
else if (!shouldPoll && pollingActive) { }
ComputerManager.stopPollingAsync()
pollingActive = false onActiveChanged: {
if (active) {
// Stop the inactivity timer
inactivityTimer.stop()
// Restart polling if it was stopped
if (!pollingActive) {
ComputerManager.startPolling()
pollingActive = true
}
}
else {
// Start the inactivity timer to stop polling
// if focus does not return within a few minutes.
inactivityTimer.restart()
} }
} }