mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 14:40:56 +00:00
Avoid polling if the Qt window is minimized
This commit is contained in:
@@ -36,15 +36,9 @@ GridView {
|
|||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
// Start polling when this view is shown
|
|
||||||
ComputerManager.startPolling()
|
|
||||||
|
|
||||||
appModel.computerLost.connect(computerLost)
|
appModel.computerLost.connect(computerLost)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Stop polling when this view is not on top
|
|
||||||
ComputerManager.stopPollingAsync()
|
|
||||||
|
|
||||||
appModel.computerLost.disconnect(computerLost)
|
appModel.computerLost.disconnect(computerLost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-17
@@ -2,6 +2,7 @@ import QtQuick 2.9
|
|||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
import QtQuick.Dialogs 1.3
|
import QtQuick.Dialogs 1.3
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
import QtQuick.Window 2.2
|
||||||
|
|
||||||
import ComputerModel 1.0
|
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)
|
function pairingComplete(error)
|
||||||
{
|
{
|
||||||
// Close the PIN dialog
|
// Close the PIN dialog
|
||||||
pairDialog.close()
|
pairDialog.close()
|
||||||
|
|
||||||
// Start polling again
|
|
||||||
ComputerManager.startPolling()
|
|
||||||
|
|
||||||
// Display a failed dialog if we got an error
|
// Display a failed dialog if we got an error
|
||||||
if (error !== null) {
|
if (error !== null) {
|
||||||
errorDialog.text = error
|
errorDialog.text = error
|
||||||
@@ -176,9 +163,6 @@ GridView {
|
|||||||
if (!model.busy) {
|
if (!model.busy) {
|
||||||
var pin = ("0000" + Math.floor(Math.random() * 10000)).slice(-4)
|
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
|
// Kick off pairing in the background
|
||||||
computerModel.pairComputer(index, pin)
|
computerModel.pairComputer(index, pin)
|
||||||
|
|
||||||
|
|||||||
@@ -44,16 +44,10 @@ Item {
|
|||||||
if (visible) {
|
if (visible) {
|
||||||
// Connect the quit completion signal
|
// Connect the quit completion signal
|
||||||
ComputerManager.quitAppCompleted.connect(quitAppCompleted)
|
ComputerManager.quitAppCompleted.connect(quitAppCompleted)
|
||||||
|
|
||||||
// We must be polling or we won't get the quitAppCompleted() callback
|
|
||||||
ComputerManager.startPolling()
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Disconnect the signal
|
// Disconnect the signal
|
||||||
ComputerManager.quitAppCompleted.disconnect(quitAppCompleted)
|
ComputerManager.quitAppCompleted.disconnect(quitAppCompleted)
|
||||||
|
|
||||||
// Stop polling when this view is not on top
|
|
||||||
ComputerManager.stopPollingAsync()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
import QtQuick.Window 2.2
|
||||||
|
|
||||||
import QtQuick.Controls.Material 2.1
|
import QtQuick.Controls.Material 2.1
|
||||||
|
|
||||||
|
import ComputerManager 1.0
|
||||||
import AutoUpdateChecker 1.0
|
import AutoUpdateChecker 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
|
property bool pollingActive: false
|
||||||
|
|
||||||
id: window
|
id: window
|
||||||
visible: true
|
visible: true
|
||||||
width: 1280
|
width: 1280
|
||||||
@@ -21,6 +25,24 @@ ApplicationWindow {
|
|||||||
anchors.fill: parent
|
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)
|
function navigateTo(url, objectName)
|
||||||
{
|
{
|
||||||
var existingItem = stackView.find(function(item, index) {
|
var existingItem = stackView.find(function(item, index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user