Skip to content

Commit 482ca9a

Browse files
committed
Add Wake and Open option for sleeping PCs
Adds a context menu item that sends the Wake-on-LAN packet and automatically opens the PC's app view once it comes online, instead of requiring the user to wake it and then click it separately. Includes a 2-minute timeout with an error dialog if the PC does not come online.
1 parent 224686f commit 482ca9a

1 file changed

Lines changed: 60 additions & 21 deletions

File tree

app/gui/PcView.qml

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ CenteredGridView {
171171
font.bold: true
172172
enabled: false
173173
}
174+
NavigableMenuItem {
175+
text: qsTr("Wake and Open")
176+
onTriggered: wakeAndOpen()
177+
visible: !model.online && model.wakeable
178+
}
174179
NavigableMenuItem {
175180
text: qsTr("View All Apps")
176181
onTriggered: {
@@ -219,29 +224,63 @@ CenteredGridView {
219224
}
220225
}
221226

222-
onClicked: {
223-
if (model.online) {
224-
if (!model.serverSupported) {
225-
errorDialog.text = qsTr("The version of GeForce Experience on %1 is not supported by this build of Moonlight. You must update Moonlight to stream from %1.").arg(model.name)
226-
errorDialog.helpText = ""
227-
errorDialog.open()
228-
}
229-
else if (model.paired) {
230-
// go to game view
231-
var component = Qt.createComponent("AppView.qml")
232-
var appView = component.createObject(stackView, {"computerIndex": index, "objectName": model.name})
233-
stackView.push(appView)
234-
}
235-
else {
236-
var pin = computerModel.generatePinString()
227+
// Set when the user chose "Wake and Open"; we open the PC
228+
// automatically once it comes online.
229+
property bool wakeAndOpenPending: false
230+
property bool onlineRole: model.online
237231

238-
// Kick off pairing in the background
239-
computerModel.pairComputer(index, pin)
232+
onOnlineRoleChanged: {
233+
if (wakeAndOpenPending && onlineRole) {
234+
wakeAndOpenPending = false
235+
wakeOpenTimeout.stop()
236+
activatePc()
237+
}
238+
}
240239

241-
// Display the pairing dialog
242-
pairDialog.pin = pin
243-
pairDialog.open()
244-
}
240+
Timer {
241+
id: wakeOpenTimeout
242+
interval: 120000
243+
onTriggered: {
244+
wakeAndOpenPending = false
245+
errorDialog.text = qsTr("Timed out waiting for %1 to wake up.").arg(model.name)
246+
errorDialog.helpText = ""
247+
errorDialog.open()
248+
}
249+
}
250+
251+
function wakeAndOpen() {
252+
wakeAndOpenPending = true
253+
wakeOpenTimeout.restart()
254+
computerModel.wakeComputer(index)
255+
}
256+
257+
function activatePc() {
258+
if (!model.serverSupported) {
259+
errorDialog.text = qsTr("The version of GeForce Experience on %1 is not supported by this build of Moonlight. You must update Moonlight to stream from %1.").arg(model.name)
260+
errorDialog.helpText = ""
261+
errorDialog.open()
262+
}
263+
else if (model.paired) {
264+
// go to game view
265+
var component = Qt.createComponent("AppView.qml")
266+
var appView = component.createObject(stackView, {"computerIndex": index, "objectName": model.name})
267+
stackView.push(appView)
268+
}
269+
else {
270+
var pin = computerModel.generatePinString()
271+
272+
// Kick off pairing in the background
273+
computerModel.pairComputer(index, pin)
274+
275+
// Display the pairing dialog
276+
pairDialog.pin = pin
277+
pairDialog.open()
278+
}
279+
}
280+
281+
onClicked: {
282+
if (model.online) {
283+
activatePc()
245284
} else if (!model.online) {
246285
// Using open() here because it may be activated by keyboard
247286
pcContextMenu.open()

0 commit comments

Comments
 (0)